here is what I did with your code... what do you think?
Out of interest, I'd be interested in seeing a piece of code that used this function. As I've just typed elsewhere, I almost never use functions, and would appreciate seeing an example using a bit of code I know and understand.
(If you're wondering why, it's chiefly that early BASICs made functions difficult (to me, anyway), and by the time QB45 came along, I'd got out of the habit. Plus, the QB45 IDE doesn't exactly make the experience all that user-friendly, either.)
Malcolm
You use FUNCTIONs all the time in your code. Your original code is chock full of them...
FOR i = 1 TO LEN(text$)
IF ASC(MID$(text$, i, 1)) < 45 OR ASC(MID$(text$, i, 1)) >= 58 GOTO notanumber
Of the above, we have 2 lines of code and 3 functions: LEN(), ASC(), MID$()
At its base, all a FUNCTION is, is a routine which gives you a return value. A SUB on the other hand, doesn’t.
CLS — this is a SUB.
PRINT — this is a SUB.
ASC() — This returns a value, so is a FUNCTION.
CHR$() — Function.
SIN(), COS(), TAN() — all FUNCTIONs.
If it’s a routine which gives you a return value, which you can use from the right side of an equal sign, it’s a FUNCTION:
X =
whatever(), and whatever() is a FUNCTION.
IF your command is a stand-alone procedure which
can’t go to the right side of an equal sign, it’s a SUB:
X = PRINT “Hello World” — for example.
You’ve used functions all the time in your code. You just haven’t been creating any CUSTOM functions of your own, from the way your post sounds. When you do, you just end up using them like you have been, with all usual rules and syntax applying.