Code archives/Algorithms/Val function

This code has not been declared by its author to be Public Domain code, and therefore should not be assumed to be so.

Download source code

Val function by Unknown
(Posted 25 years ago)
As of 14/10/01 Blitz doesnt have an in-built function to perform this operation. So here is one I just knocked up. Enjoy!

The Prof.
; Val Function v0.1 By The Prof - For Blitzers Everywhere!
;
T$="109876":V=Val(T$):Print V     ; example 1

V=Val("12345"):Print V            ; example 2

Print Val("02468")                ; example 3

Print Val("Blitz Basic")          ; example 4

Print Val("Blitz 123 Basic")      ; example 5

WaitKey
End

; **************************************************************
;
Function val(txt$)
  ; Val v0.1 By The Prof - Last Compiled 14-10-01 - 22:00
  ; String to Integer function (Decimal).
  ; 
  t$=Upper$(txt$):l=Len(t$):Power=1
  For Pos=L To 1 Step-1
      V=Asc(Mid$(t$,Pos,1))-48
      If (V>-1) And (V<10)        ; Ensure a Zero for letters
         Value=Value+(V*Power)
         Power=Power*10
      End If
  Next
  Return Value
End Function
;
; **************************************************************

Comments

None.

Code Archives Forum