| View previous topic :: View next topic |
| Author |
Message |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Wed Oct 16, 2002 2:26 pm Post subject: numeric and decimal poiunt check |
|
|
I need to check that an edit box only contains numbers with either a "." or a "," to allow for the decimal point as used by different countries.
I am needing to check some 75 such edit boxes and was wondering if someone had a quick way of being able to do that.
I tried @numeric() but it only works with numbers and not with the decimal point.
I could do it the hard way checking that each edit box only contains numeric characters together with the decimal point but i was wondering if someone had a better way of doing it.
Thanks in advance,
Serge _________________
|
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Wed Oct 16, 2002 2:39 pm Post subject: |
|
|
Well, I think an easy was would be to name your edit boxes with
numbers like Edit_1 - Edit_10. Then you can use repeat until
to check each edit box. You can use the @pos() to look for the
"." or "," in the number... Something like this
| Code: |
rem pretend that there is a dialog...
%x = 1
repeat
if @numeric(@dlgtext(Edit_%x))
%d = @pos(".",@dlgtext(Edit_%x))
%c = @pos(",",@dlgtext(Edit_%x))
rem do something here
else
rem do something here
end
until @equal(%x,11)
|
Hope that helps. _________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed Oct 16, 2002 2:39 pm Post subject: |
|
|
Here is a example that looks for the ASCII code, and if it is a number it will put it in a variable...
| Code: |
DIALOG CREATE,New Dialog,-1,0,104,60
DIALOG ADD,EDIT,EDIT1,5,10,85,20,1234.1234
DIALOG ADD,BUTTON,BUTTON1,30,10,85,25,Go
DIALOG SHOW
:evloop
wait event
goto @event()
:Button1button
%%text = @dlgtext(edit1)
repeat
if @both(@greater(@asc(@substr(%%text,1,1)),47),@greater(58,@asc(@substr(%%text,1,1))))
%%number = %%number@substr(%%text,1,1)
else
%%number = %%number","
end
rem You can also use the following code, if you don't know if there
rem are any other characters in the EDIT...
rem if @equal(@asc(@substr(%%text,1,1)),@asc("."))
rem %%number = %%number","
rem end
%%text = @strdel(%%text,1,1)
until @equal(@len(%%text),0)
info %%number
goto evloop
:Close
exit |
|
|
| Back to top |
|
 |
arcray Valued Contributor


Joined: 13 Jul 2001 Posts: 242 Location: Aude, France
|
Posted: Wed Oct 16, 2002 2:41 pm Post subject: |
|
|
Internally I only work with numeric data. For presentation purposes sometimes I include commas for ease of legibility. I insert and remove with the following sub-routines:-
:CommasIn
gosub Stripcommas
IF @NOT(@EQUAL(%X,NA))
gosub Insertcommas
END
EXIT
:CommasOut
:Stripcommas
REPEAT
%X = @strdel(%X,@POS(",",%X))
UNTIL @ZERO(@POS(",",%X))
EXIT
:Insertcommas
IF @NOT(@NUMERIC(%X))
info Problem with a field that should contain a number.@CR()It currently contains:- %X@CR()@CR()Please inform Andy Gray on 020 798 798 14
END
%X = @FORMAT(%X,7.2)
%L = @len(%X)
IF @EQUAL(%L,7)
%X = @strins(%X,2,",")
END
IF @EQUAL(%L,8)
%X = @strins(%X,3,",")
END
IF @EQUAL(%L,9)
%X = @strins(%X,4,",")
END
IF @EQUAL(%L,10)
%X = @strins(%X,2,",")
%X = @strins(%X,6,",")
END
EXIT _________________ Andrew GRAY
If you don't know I am looking for work, I won't get the job.
andrewrcgray.com |
|
| Back to top |
|
 |
Skit3000 Admin Team

Joined: 11 May 2002 Posts: 2166 Location: The Netherlands
|
Posted: Wed Oct 16, 2002 2:44 pm Post subject: |
|
|
Oops.... We've all posted at the same moment....  |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Wed Oct 16, 2002 8:06 pm Post subject: |
|
|
One more idea.... This subroutine can be modified for
any char check (alpha, numeric, etc.) by changing the
valid chars in the var "%v". The loops stops checking
if an invalid char is found. It also shows invalid if the
string "%s" is empty.
Call the following subroutine for each edit box (or string)
with these two lines:
%s = @dlgtext(EditBoxName)
GOSUB IsValid
| Code: |
rem -- The subroutine (%v can be assigned once at program start) --
:IsValid
%v = "0123456789.,"
%x = 1
REPEAT
if @equal(@pos(@substr(%s, %x), %v), 0)
WARN Invalid Entry...@tab()
%x = @len(%s)
end
%x = @succ(%x)
UNTIL @greater(%x, @len(%s))
exit
|
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Serge Professional Member


Joined: 04 Mar 2002 Posts: 1480 Location: Australia
|
Posted: Thu Oct 17, 2002 12:10 pm Post subject: |
|
|
Thanks for all your answers
I did try the @numeric() but it reports an error if the edit box contains a "." or a ",". It would have been nice if @numeric() was set to test for numbers with decimal points rather than integers only
I will have a close look at all your suggestions.
Thanks a bunch,
Serge _________________
|
|
| Back to top |
|
 |
arcray Valued Contributor


Joined: 13 Jul 2001 Posts: 242 Location: Aude, France
|
Posted: Thu Oct 17, 2002 12:27 pm Post subject: |
|
|
It does work! But it'll only work with numbers that your windows system thinks are numbers. And that depends on what has been put in to the Numbers dialog in Regional settings... _________________ Andrew GRAY
If you don't know I am looking for work, I won't get the job.
andrewrcgray.com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|