Jump to content

Format rule or function?


Sdawson

Recommended Posts

I have a database with a number and a format field. The format field will always be 12 characters but the number field will vary from 8 to 10 characters.

 

Does anyone know a rule or function that will help me format the number field?

 

 

X = Space

V = Variable Number

 

Number Format Result

1234567890 XVVVVVVVVVV 1234567890

12345678 XVVVVXVVVXV 1234 567 8

Link to comment
Share on other sites

var sequence=Field("Number").split("");
var pattern=Field("Format").split("");
var formatNumber="";
for (var i=0; i<pattern.length; i++) {
  if (pattern[i] == "X") formatNumber += " ";
  else formatNumber += sequence.shift();
}
return formatNumber;

Link to comment
Share on other sites

Thank you, after I posted this I took a crack at writing some code. Your's looks way better :)

 

var AccountNumber = ""  
var Counter = 0 

for (var i = 0; i<Len(Field("Account_Format")); i++)
{
var x = Field("Account_Format").substring(i,i+1);

if (x == "V")
{
AccountNumber += Field("Account_Numbers").substring(Counter,Counter+1); 
Counter+=1;
}
else if (x == "X")
{
AccountNumber += " ";
}
}
return AccountNumber

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...