? Reading any type of DATA (SB3) ● SmileBASIC Source

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Reading any type of DATA (SB3)

Normally you need to know what type the data is (string vs int vs float) before using READ, but if the variable you use is untyped, its type will change to the type of the data. There are basically 2 ways to get untyped vars: DEF TEST OUT X 'OUT variables start as untyped READ X ENDor IF 0 THEN DIM A[0] 'arrays are untyped until the DIM is executed, and if it's skipped, the var stays untyped READ A So you can easily make a function that reads any type of data: DEF READ_ANY OUT IS_STRING,NUM,STR IF 0 THEN DIM A[0] READ A IF (A||0)==3 THEN 'Bug: || returns 3 when first arg is a string (a safer way to check might be (A*0 && A*0==A*0) or something STR=A:NUM=0:IS_STRING=#TRUE ELSE NUM=A:STR="":IS_STRING=#FALSE ENDIF END
Author
12Me21
Updated
Rating
1 vote
Categories
Keywords
2 Comment(s) rando rando Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Second Year My account is over 2 years old Website Forum Leader Hidden Achievements interesting CyberYoshi64 CyberYoshi64 Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Great Page Hidden Achievements Oh, that boolean returning 3? ""==var==3... cool