Page 1 of 1
Posted: Fri Jan 25, 2002 1:38 pm
by BackupUser
Restored from previous forum. Originally posted by Manolo.
Hello,
Because PB not have (For the moment), I write this function:
Code: Select all
;Function for check only numeric characters into 1 field or in one string variable
;is valid for check differents charactes, only change the compare variable
OpenConsole()
Procedure.f Num(value.s)
result=0
compare.s="1234567890.-"
For i=1 To Len(value)
res=FindString(compare,(Mid(value,i,1)),1)
If res=0
result=result+1
EndIf
Next
ProcedureReturn result
EndProcedure
in:
a$=Input()
If Num(a$)=0
PrintN("CORRECT NUMBER"+valor$)
Else
PrintN("INCORRECTO. NOT NUMERICAL CHARACTERS"+valor$)
EndIf
Goto in:
Delay(10000)
Regards to all
Manolo
[url]mailto:
vpardo@infonegocio.com[/url]
Posted: Fri Jan 25, 2002 7:06 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
Hi Manolo,
Added the Num function to the MathExtras library, available at Paul's site (in 24 hours):
http://www.reelmediaproductions.com/pb
Added "," as a numerical character because, as you know, we use it in Spain to delimit decimals instead of ".".
Hope you find it useful. Bye,
El_Choni
PS: I'm idiot! Your function returns a float, and mine a string! Back to work, sorry...
Edited by - El_Choni on 25 January 2002 19:07:48
Posted: Fri Jan 25, 2002 7:18 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
I think PureBasic's ValF() should match your needings. It has all been a stupid loss of time. If only I read the entire postings...
Bye,
El_Choni
Posted: Sat Jan 26, 2002 10:40 am
by BackupUser
Restored from previous forum. Originally posted by Manolo.
I think PureBasic's ValF() should match your needings. It has all been a stupid loss of time. If only I read the entire postings...
Bye,
El_Choni
Not, not... ValF() from Paul is diferent. Is very nice for. Best that Val() from
native PureBasic, but... Don't check the correct numeric characters, similar to
problem from Val() native.
In this moment I work with Num() and ValF()combination. For example:
a$="123f4.01"
If Num(a$)=0
r$=ValF((a$),2)
MessageRequester("OK","Check and result OK.",0)
Else
MessageRequester("Error","Only numeric characters",0)
Endif
ValF() form Paul and Val() form PureBasic dont checking the numerics only.
Regards.
Manolo from Ourense. HeHe (Galleguiño)
Bye.
Posted: Sat Jan 26, 2002 6:12 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.
Hi Manolo,
Coded this inline asm example of your Num() procedure just for fun:
Code: Select all
Global string.s, result.l
Procedure.l Num(string.s)
! xor edx, edx
! mov eax, [esp+24] ; don't know why @string is here, but it is.
! dec eax
! .siguiente:
! inc eax
! cmp byte [eax], 0
! je .fin
! cmp byte [eax], ","
! jb .siguiente
! cmp byte [eax], "."
! jbe .copiar
! cmp byte [eax], "0"
! jb .siguiente
! cmp byte [eax], "9"
! ja .siguiente
! .copiar
! inc edx
! jmp .siguiente
! .fin:
! mov [v_result], edx
ProcedureReturn result
EndProcedure
MessageRequester("Num function result:", Str(Num("0123456789.,-")), 0)
Bye,
El_Choni from Coruña, je, je
Edited by - El_Choni on 26 January 2002 18:13:44