You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Function NonNegativeWholeNumber(ByVal a As String) As Long ' Boolean
Local i As Long
'exclude strings such as 0000004
Local b As String '
b = LTrim$(a,"0") '
If a <> "0" And a <> b Then '
Function = 0 '
Exit Function '
End If '
For i = 1 To Len(a)
If Asc(a, i) < 48 Or Asc(a, i) > 57 Then Exit For
Next
Function = (i > Len(a))
End Function
RETAIN$ would be a lot simpler and shorter. Just RETAIN$ what you want then check the length of the original string vs. processed string. If they are the same, then it's a number. If not....
FUNCTION isNumeric(Answer AS STRING) AS LONG
Answer = TRIM$(Answer) 'may be required if right-justified text
IF (LEN(Answer) = 0) OR _
(VERIFY (Answer , ".-0123456789")) OR _
(RIGHT$(Answer,1) = ".") OR _
(INSTR(-1,Answer,"-") > 1) OR _
(TALLY(Answer,".") > 1) THEN
EXIT FUNCTION 'exit, return 0 not-numeric
END IF
FUNCTION = -1 'numeric
END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: