I'm writing a program (my first in PB) in which the user will enter numbers, which may legitimately include zeroes, into a text box. Using examples given in PB documentation, the program checks that something has been entered using the len function, and uses the remove$ function to delete extraneous material, as below.
CASE %IDOK
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX1 TO Sentry
IF LEN(TRIM$(Sentry)) = 0 THEN
MSGBOX "You need to enter something", _
%MB_OK OR %MB_TASKMODAL, "EnterNumber"
CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1
ELSE
y = VAL(REMOVE$(Sentry, "$, "))
Sentry = STR$(y)
MSGBOX "You entered" + Sentry, _
%MB_OK OR %MB_TASKMODAL, "EnterNumber"
CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1
DIALOG END CBHNDL, %IDOK
END IF
END IF
My question concerns the checking of whether the entry is a valid number. If the user has entered a letter (say), the val function returns a zero. However, zero is also legitimate value. So, my problem is how to distinguish the two.
As I'm sure that many of you will have faced this question and solved it, I thought I'd ask, rather than continue to labour.
Thanks for any help you can give me.
Alan
CASE %IDOK
IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
CONTROL GET TEXT CBHNDL, %IDC_TEXTBOX1 TO Sentry
IF LEN(TRIM$(Sentry)) = 0 THEN
MSGBOX "You need to enter something", _
%MB_OK OR %MB_TASKMODAL, "EnterNumber"
CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1
ELSE
y = VAL(REMOVE$(Sentry, "$, "))
Sentry = STR$(y)
MSGBOX "You entered" + Sentry, _
%MB_OK OR %MB_TASKMODAL, "EnterNumber"
CONTROL SET FOCUS CBHNDL, %IDC_TEXTBOX1
DIALOG END CBHNDL, %IDOK
END IF
END IF
My question concerns the checking of whether the entry is a valid number. If the user has entered a letter (say), the val function returns a zero. However, zero is also legitimate value. So, my problem is how to distinguish the two.
As I'm sure that many of you will have faced this question and solved it, I thought I'd ask, rather than continue to labour.
Thanks for any help you can give me.
Alan
Comment