byref compiler error

New to FreeBASIC? Post your questions here.
Post Reply
StillLearning
Posts: 54
Joined: Aug 27, 2019 22:22

byref compiler error

Post by StillLearning »

I have created a small code example of a error I keep on getting when attempting to use byref to return 2 different parameters.
Here is the code:

Code: Select all

declare sub ValidateLeadingSign(_
  Digit as string,_
  PlusExists as byte,_
  MinusExists as byte)
declare sub GetOperand()

Dim shared TxtLine as ZString*513 'max size of line of text
Dim shared TxtChar as zstring*2
dim shared TxtPos as ubyte


'Validate unairy + or - sign for number
sub ValidateLeadingSign(_
  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 AscChar as Ubyte

do
  TxtChar[0] = TxtLine[TxtPos]
  TxtPos = TxtPos + 1
  AscChar = asc(TxtChar)
  If AscChar = 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 AscChar = 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

Sub GetOperand()
dim CurrentOpCaseNumber as ubyte
dim PriorPrecedence as ushort
dim PlusSignExists as byte
dim MinusSignExists as byte
dim Digit as string

TxtPos = 0 
PlusSignExists = 0
MinusSignExists = 0
ValidateLeadingSign(Digit,PlusSignExists,MinusSignExists)
if MinusSignExists then
  'is Negation
  PriorPrecedence = 100
  CurrentOpCaseNumber = 9
  exit sub
end if
end sub

input "enter instruction: ";TxtLine
TxtPos = 0
GetOperand()
 end
When I attempt to compile it I get this error:
Error 57: Type mismatch, at parameter 2 (PlusExists) of ValiadteLeadingSign() in 'ByRef MinusExists as Byte)

I do not see any type mismatch.
Can anybody tell me what I am doing wrong with the way I am passing parameters?
I am attempting to learn how to pass parameters.

Thank you for any help.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: byref compiler error

Post by dodicat »

You must use byref in your declaration also.
StillLearning
Posts: 54
Joined: Aug 27, 2019 22:22

Re: byref compiler error

Post by StillLearning »

Thank you dodicat.
I did not know that was necessary.
Post Reply