Code: Select all
declare sub ValidateLeadingSign(Digit as string,PlusExists as Byte, _
MinusExists as Byte)
Dim shared as string TxtLine,TxtChar
Dim shared as short TxtPos
'Validate unairy + or - sign for number
sub ValidateLeadingSign( _
Byref Digit as string, _
Byref PlusExists as byte, _
Byref MinusExists as byte)
'Make sure PlusExists is defined with "Byref" so this value can be passed back.
'Make sure MinusExists is defined with "Byref" so this value can be passed back.
Dim TxtVal as Ubyte
do
TxtChar= MID(TxtLine,TxtPos,1)
TxtPos = TxtPos + 1
TxtVal = asc(TxtChar)
If TxtVal = 43 then
'check for "+"
PlusExists = not PlusExists
if PlusExists = 0 then
Print "Error cannot have more than 1 leading + sign in a number"
exit do
end if
if MinusExists then
print "error bad signed number"
exit do
end if
elseif TxtVal = 45 then
'check for "-"
MinusExists = not MinusExists
if MinusExists = 0 then
Print "Error cannot have more than 1 leading - sign in a number"
exit do
end if
if PlusExists then
print "error bad signed number"
exit do
end if
else
exit do
end if
Digit = Digit + TxtChar
loop
end sub
Dim Digit as string
Dim MinusExists as Byte
Dim PlusExists as Byte
TxtPos = 1
MinusExists = 0
PlusExists = 0
input "enter floating-point number ";TxtLine
TxtLine = TxtLine +";"+chr$(13)
Digit = ""
ValidateLeadingSign(Digit,PlusExists,MinusExists)
If (PlusExists + MinusExists) <> 0 then
Print "error a floating point hex number MUST be unsigned."
else
print "no error" ;Digit
end if
end
Code: Select all
exptest.bas<12> error 57: type mismatch, at parameter 2 <PlusExists> of ValidateLeadingSign<> in 'byref MinusExists as byte>