The goal of this little routine is to be able to enter a decimal number by only accepting the digits from 0 to 9 and possibly only one decimal point.
If an invalid character is entered, I delete it and update the display in "StringGadget".
The problem is that the cursor returns to the start of the input area whereas I would like it to be placed at the end of the input area.
Can you help me?
Thanks to you
Code: Select all
OpenWindow(0,100,100, 300,200, "TEST")
StringGadget(1, 10, 10, 100, 20, "123.45")
to_leave = #False
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
to_leave=#True
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Select EventType()
Case #PB_EventType_Change
Amount.s = GetGadgetText(1)
chain_length = Len(Amount)
decimal_point = 0
For i = 1 To chain_length
character.s = Mid(Amount ,i, 1)
If Not FindString("0123456789.", character)
Amount = Left(Amount, chain_length - 1)
SetGadgetText(1, Amount)
EndIf
If FindString(".", character)
decimal_point + 1
If decimal_point > 1
Amount = Left(Amount, chain_length - 1)
SetGadgetText(1, Amount)
EndIf
EndIf
Next i
EndSelect
EndSelect
EndSelect
Until to_leave
