QB64 Phoenix Edition
Is there an IsAlpha function in QB64PE? - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10)
+---- Thread: Is there an IsAlpha function in QB64PE? (/showthread.php?tid=1594)



Is there an IsAlpha function in QB64PE? - PhilOfPerth - 03-31-2023

Is there an IsAlpha or IsNum (or equivalent) function in PE, to examine an input's type? If not, should there be? 
I couldn't see one in Help or the Wiki.
I know we can use Select Case etc., but it would be much more convenient if these functions were available.


RE: Is there an IsAlpha function in QB64PE? - bplus - 04-01-2023

Quote:to examine an input's type


An input's type is determined by the variable that contains the value:

Code: (Select All)
Input "Enter a number"; aNum ' << single type
Print "A number"; aNum
Input "Enter a string"; aString$ ' << determines Type
Print "A string "; aString$



RE: Is there an IsAlpha function in QB64PE? - TerryRitchie - 04-01-2023

(03-31-2023, 11:56 PM)PhilOfPerth Wrote: Is there an IsAlpha or IsNum (or equivalent) function in PE, to examine an input's type? If not, should there be? 
I couldn't see one in Help or the Wiki.
I know we can use Select Case etc., but it would be much more convenient if these functions were available.

Functions like those are really handy (and necessary) for languages that don't rely on, or are very flexible with, variable types. Since QB64 requires a variable to have a type (integer, single, string, etc..) there would be no reason to have an IsAlpha or IsNum function. All variables created in QB64 without specifying a type default to SINGLE, therefore they are always "IsNum" so to speak.

If you want to test a string for a numeric value use VAL().


RE: Is there an IsAlpha function in QB64PE? - PhilOfPerth - 04-01-2023

Ah, of course it is! Sorry.


RE: Is there an IsAlpha function in QB64PE? - PhilOfPerth - 04-01-2023

(04-01-2023, 12:13 AM)TerryRitchie Wrote:
(03-31-2023, 11:56 PM)PhilOfPerth Wrote: Is there an IsAlpha or IsNum (or equivalent) function in PE, to examine an input's type? If not, should there be? 
I couldn't see one in Help or the Wiki.
I know we can use Select Case etc., but it would be much more convenient if these functions were available.

Functions like those are really handy (and necessary) for languages that don't rely on, or are very flexible with, variable types. Since QB64 requires a variable to have a type (integer, single, string, etc..) there would be no reason to have an IsAlpha or IsNum function. All variables created in QB64 without specifying a type default to SINGLE, therefore they are always "IsNum" so to speak.

If you want to test a string for a numeric value use VAL().
Yep, got it. Thanks Terry.


RE: Is there an IsAlpha function in QB64PE? - mnrvovrfc - 04-01-2023

https://qb64phoenix.com/qb64wiki/index.php/C_Libraries#C_Functions_and_Subs

It would be pretty easy to invent BASIC functions out of the C library ones in "ctype.h" header file.

Otherwise:

Code: (Select All)
DIM character AS INTEGER, somestring AS STRING, someposition AS LONG
character = ASC(somestring, someposition)
SELECT CASE character
CASE 44 TO 46, 48 TO 57
'(is a number)
'would have to check if plus or minus is the first character
'would have to check if there is only one of plus, minus or period
CASE 65 TO 90, 97 TO 122
'(is a letter)
CASE ELSE
'(is neither number nor letter)
END SELECT

(Declares AS INTEGER instead of AS _BYTE or AS _UNSIGNED _BYTE because those pesky negative numbers would have to be clamped away and other such calculations.)

EDIT: Added "CASE ELSE" so it could be put inside a function which should have extensive checks for number's sake, since that is more demanding than doing it to an ordinary English word apart from @#%& or other such gibberish. Smile


RE: Is there an IsAlpha function in QB64PE? - SMcNeill - 04-01-2023

https://staging.qb64phoenix.com/showthread.php?tid=1207&highlight=Isnum


RE: Is there an IsAlpha function in QB64PE? - RhoSigma - 04-01-2023

The ctype.h header is allready included in QB64pe and its functions can easily accessed via a declare library block.
Code: (Select All)
DECLARE LIBRARY
    'ctype.h
    FUNCTION isalnum% (BYVAL c AS INTEGER) 'is an alphabet letter(isalpha(c) or isdigit(c))
    FUNCTION isalpha% (BYVAL c AS INTEGER) 'is letter (isupper(c) or islower(c))
    FUNCTION isdigit% (BYVAL c AS INTEGER) 'is a decimal digit
    FUNCTION isgraph% (BYVAL c AS INTEGER) 'is a printing character other than space
    FUNCTION islower% (BYVAL c AS INTEGER) 'is a lower-case letter
    FUNCTION isprint% (BYVAL c AS INTEGER) 'is printing character. ASCII: &H20 (" ") to &H7E (~)
    FUNCTION ispunct% (BYVAL c AS INTEGER) 'is printing character other than space, letter, digit
    FUNCTION isspace% (BYVAL c AS INTEGER) 'is space, formfeed, newline, return, tab, vertical tab
    FUNCTION isupper% (BYVAL c AS INTEGER) 'is upper-case letter
    FUNCTION isxdigit% (BYVAL c AS INTEGER) 'is a hexdecimal digit character(0 thru 9 or A thru F)
END DECLARE

LINE INPUT "Gimme a char: "; c$

IF isalpha%(ASC(c$)) THEN
    PRINT "Is alpha."
ELSE
    PRINT "Is NOT alpha."
END IF

END
For more informations/other functions see https://qb64phoenix.com/qb64wiki/index.php/C_Libraries