Authors
Publication
Pub Details
Date
Pages
BASIC Terms
If you are like me, you have never used the VAL$ function. There is no good explanation in any of the manuals. The “Quick reference guide” states that the function evaluates a numeric expression without its bounding quotes as a string expression. This is only a partial truth. The function can be used on any string expression — numerical or alphabetical. It will remove one level of " " marks from any string expression. As an example let A$=”cats” and then let B$=”A$”. The string “cats” is two levels down so to speak. Equivalently we could have written """cats""". The following exercises demonstrate the application of VAL$.
There must be some tricky applications for VAL$ but I haven’t thought of them yet — can you?
Listing
10 LET a$="""""""1+2"""""""
20 PRINT a$
30 PRINT VAL$ a$
40 PRINT VAL$ VAL$ a$
50 LET b$="""1+2"""
60 PRINT b$
70 PRINT VAL$ b$
80 LET c$="b$"
90 PRINT c$
100 PRINT VAL$ c$
110 PRINT VAL$ VAL$ c$
120 PRINT VAL VAL$ VAL$ c$
Results:
"""1+2"""
"1+2"
1+2
"1+2"
1+2
b$
"1+2"
1+2
3
Note the relative number of parentheses in statements 10 and 50.
More examples for the advanced student
10 LET a$="1+2"
11 LET g=4
12 LET h$="g"
13 LET j$="h$"
15 LET b$="""1+2"""
16 LET c$="a$"
17 LET d$="c$"
18 LET e$="cats"
19 LET f$="small,""dogs"" are nice"
20 PRINT VAL a$
30 PRINT VAL$ b$
40 PRINT VAL$ c$
50 PRINT VAL VAL$ c$
60 PRINT VAL$ d$
70 PRINT VAL$ VAL$ d$
80 PRINT VAL$ "e$"
90 PRINT e$
100 PRINT f$
110 PRINT f$(7 TO 12)
120 PRINT f$(8 TO 11)
130 PRINT VAL$ f$(7 TO 12)
140 PRINT g
150 PRINT VAL h$
160 PRINT VAL (VAL$ j$)
170 PRINT VAL$ j$+b$
180 PRINT VAL VAL$ j$+VAL VAL$ b$
The above program generates the following results:
3
1+2
1+2
3
a$
1+2
cats
cats
small,"dogs" are nice
"dogs"
dogs
dogs
4
4
4
g"1+2"
7
Products
Media
Image Gallery
Source Code
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.