[Gambas-user] ValueBox value validation
John Rose
john.aaron.rose at ...1601...
Thu Jan 19 16:41:36 CET 2012
I have a problem with validating a user-entered value in a ValueBox. I've
tried LostFocus & Leave and neither seems to do the validation i.e. no
message box appears for incorrect values. So I thought that I would try
Change, even though the documentation says that it is raised on each
character typed in (rather than at the end of typing in the changes to the
value) which would not be any good. However, I'm not able to use the Change
event (i.e. not in popup menu for event and has no effect at runtime) for a
Valuebox: looks like a bug. I've tried using KeyRelease, but that applies
to each character change, so that it rejects the value as each character is
entered. Code fragment is:
Public Sub ValueBoxLatitude_Change()
Dim latitude As Float
Dim i As Integer
Print "Latitude Validation"
latitude = Last.Value
If latitude < -90 Or latitude > 90 Then
Message.Info("Must be between -90 and +90 - try again")
Last.SetFocus
Stop Event
Endif
i = CInt(latitude * 1000000)
Print "CInt(latitude * 1000000)=", i
If (latitude * 1000000) - CFloat(i) <> 0.0 Then
Message.Info("More than 6 decimal digits - try again")
Last.SetFocus
Stop Event
Endif
End
PS what event should this validation be under?
More information about the User
mailing list