I've just started learning BASIC AND using Stackoverflow. This is my code in FBIDE. The error messages are :
42 variable not declared : var1 in 'input "Enter Function Number" ;var1 / - 32 expected 'END IF' found 'end' in 'end sub'/ - 32 expected 'END IF' in 'end sub' -
Code:
declare sub premain
declare sub main
dim var1 as integer
premain
sub premain
print "EMC ALPHA v1.0"
main
end sub
sub main
print "Functions:"
print "1.Add"
print "2.Subtract"
print "3.Multiply"
print "4.Divide"
input "Enter Function Number" ;var1
if var1=1 then
print "HElo"
end sub
In your program the variable
var1is declared in the main program scope. This variable will not be accessible in sub programs (procedures: SUB or FUNCTION), unless you use the SHARED keyword. Then the variable would become globally available in your program.The better way is to use local variables:
Global variables (created by SHARED) should only rarely be used, for example for program-wide configuration / settings, e.g. the user's selected language in a multilingual application.
Moreover, your program was missing an
END IF(fixed in the code snippet above in my posting).