[Gambas-user] Check on entered number having more than 6 digits not working
nando
nando_f at ...951...
Mon Aug 13 13:53:42 CEST 2012
I'd say, if a number has been inputted
and it's in the range -90 ... + 90 then it is a valid long.
No more testing required.
Period!!!
If you multiply it by 6 zero's then it could be
-90,000,000 ... +90,000,000
and you're defeating the whole thing.
What you're doing is pointless.
for this snippet...
1> f = latitude * 1000000
2> g = CFloat(CInt(f))
3> Print "f=" & f
4> Print "g=" & g
5> If f <> g Then
6> Message.Info("More than 6 decimal digits - try again")
7> Last.SetFocus()
8> Stop Event
9> End If
if you want f to be with no digits to the right of the decimal point
then use INTEGER, not FLOAT
so, f should be an INTEGER
You're trying so hard to do things an INTEGER does well
line 2,4,5,6,7,8 are not needed
but is line 1 purpose only for testing, then you don't even need line 1
Overall, if lat is -90 ... +90 then it's in range.
No more tests required.
if someone types in: 89.12361263571235671235645345345
and you don't want all those extra digits to the right of the 6th decimal digit
DO NOTHING.
TEST NOTHING.
because it doesn't matter.
It really doesn't!!
-Fernando
---------- Original Message -----------
From: John Rose <john.aaron.rose at ...626...>
To: GambasUsers MailingList <gambas-user at lists.sourceforge.net>
Sent: Sun, 12 Aug 2012 08:09:06 +0100
Subject: [Gambas-user] Check on entered number having more than 6 digits not working
> Jussi,
>
> I've put the code below into the Fmain class in that Test project and it
> works OK! The Test project needs a lot more code in order to obtain the
> Latitude from the database. I'll check it out again with the full
> project.
>
> Public Sub ValueBoxLongitude_KeyRelease()
> If Key.Code = Key.Return Or Key.Code = Key.Enter Or Key.Code = Key.Tab
> Then
> ButtonExit.SetFocus()
> Endif
> End
>
> Public Sub ValueBoxLatitude_LostFocus()
> Dim latitude As Float
> Dim f As Float
> Dim g As Float
> If IsNull(Last.Value) Then Return
> latitude = Last.Value
> If latitude < -90 Or latitude > 90 Then
> Message.Info("Must be between -90 and +90 - try again")
> Last.SetFocus()
> Stop Event
> End If
> f = latitude * 1000000
> g = CFloat(CInt(f))
> Print "f=" & f
> Print "g=" & g
> If f <> g Then
> Message.Info("More than 6 decimal digits - try again")
> Last.SetFocus()
> Stop Event
> End If
> ButtonExit.SetFocus
> End Sub
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------
More information about the User
mailing list