TOPIC: Formatted numbers
#1939
Formatted numbers 2 Months, 2 Weeks ago
I have question about implementing formatted numbering. I need numbers to identify objects (documents, letters, etc). I want to give them unique number in a certain formatting. However formatting of numbers is limited, and I not sure if should format numbers as being string type.

Example: 2010.00052 -> can not format as number. Should be string? Pattern? What is better way to handle?

Thanks...
 
 
#1940
Re:Formatted numbers 2 Months, 2 Weeks ago
I'm not sure what you mean by "format". Why can't you format 2010.00052?

2010.00052.Format("####.#####") => "2010.00052"

Do you mean on a report? Or in a field on the screen? Or do you mean validation?
 
 
andrew
 
#1941
Re:Formatted numbers 2 Months, 2 Weeks ago
Actually i have a identifier as a Number defined, if i want 2010.12345 it wants to convert it to something like 201,012,345 on screen. The problem is not validation only way it is display in a Field as part of a RecordControl.

I solved by make new type of control:

Code:


FieldControl
{
Name:FormattedNumber
New(pattern)
{
super()
.pattern = pattern
}
KillFocus()
{
if (false isnt t = .Convert2(String(.Get())))
{
dirty? = .Dirty?()
SetWindowText(.Hwnd, t)
.Dirty?(dirty?)
}
}
Get()
{
return .Convert1(super.Get())
}
Set(value)
{
super.Set(.Convert2(String(value)))
}
Convert1(value)
{
Number(value.Replace('D+', ''))
}
Convert2(value)
{
t = ""
si = 0
for (pi = 0; (pc = .pattern[pi]) isnt ""; ++pi)
{
sc = value[si++]
if (pc is 'a' or pc is '<')
t $= sc.Lower()
else if (pc is 'A' or pc is '>')
t $= sc.Upper()
else if (pc is '#' or (pc is sc and pc isnt '^'))
t $= sc
else if (pc is '^' and sc is .pattern[pi + 1])
t $= .pattern[++pi]
else // fill in literal char
{
if pc is '^'
pc = .pattern[++pi]
t $= pc
--si // undo increment
}
}
return t
}
}



I try first with patternControl but it saves string to database, not number...
 
 
#1942
Re:Formatted numbers 2 Months, 2 Weeks ago
Ok, I think I understand. The stored number is actually 201012345 but you want to display it as 2010.12345

Your approach seems reasonable.

Tip: To get the indenting to show up in code examples, you have to convert tabs to spaces. BookEdit does this, so you can open a book, paste in the code, refresh, then copy the code. I keep an empty book just for this.
 
 
andrew