--- title: "The VAL$ Function" type: "article" slug: "the-val-function" url: "http://localhost/article/the-val-function/" markdown_url: "http://localhost/article/the-val-function.md" published_at: "2022-09-14T02:41:21+00:00" modified_at: "2026-08-04T13:27:52+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "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…" category: - name: "CATS Newsletter" slug: "cats-newsletter" taxonomy: "category" url: "http://localhost/category/periodicals/cats-newsletter/" post_tag: - name: "Best of Timex/Sinclair 2068 Articles and Documents" slug: "ts2068best" taxonomy: "post_tag" url: "http://localhost/tag/ts2068best/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" - name: "Tutorial" slug: "tutorial" taxonomy: "post_tag" url: "http://localhost/tag/tutorial/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Roald Schrack" slug: "roald-schrack" taxonomy: "indiv" url: "http://localhost/indiv/roald-schrack/" publication_r: id: 35941 title: "CATS Newsletter" type: "periodical" url: "http://localhost/periodical/cats-newsletter/" authors: "Roald Schrack" authors_r: - name: "Roald Schrack" slug: "roald-schrack" taxonomy: "indiv" url: "http://localhost/indiv/roald-schrack/" volume: "3" issue: "7b" issues_articles: - id: 39611 title: "CATS v3 n7b" type: "issue" url: "http://localhost/issue/cats-v3-n7b/" pages: "5" pubdate: "November 1985" archive_link: false --- # The VAL$ Function 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 ```