Reputation: 87
hi ppl im new at Scilab, im doing a script which i send the user through menus and i'm making a function for every sub-menu. I read that functions can have 0 input parameters but it must have at least 1 output parameter. According to this i wrote this
//execution file landing menu
option='1'
while (option~=0)
clc
mprintf('1 - First Sub-menu')
mprintf('2 - Second Sub-menu')
option=input('Select the option: ', 's')
select option
case '1' then
result=sub_one(),
case '2' then
result=sub_two(),
else
disp('Invalid Option!!!')
end
end
//Function sub_one
function result=sub_one()
option='1'
while (option~=0)
clc
mprintf('1 - Do stuff')
mprintf('2 - Do other stuff')
option=input('Select the option: ', 's')
select option
case '1' then
result=do_stuff(),
case '2' then
result=do_other_stuff(),
else
disp('Invalid Option!!!')
end
end
result=0
endfunction
and i always get the error
result=sub_one(),
!--error 4
Undefined variable: sub_one
at line xx of exec file called by :
exec('dir\dir\dir\file.sce', -1)
this is freaking annoying me
some experter then me?
Upvotes: 0
Views: 9782
Reputation: 2955
Scilab parses the file top to bottom, so when it is in your main part at the top of the file, sub_one
does not exist yet. If you switch the order around it will work.
If you would like to retain the order in your file you can also do the following:
// Define some main function
function main()
disp('hello from main')
sub_one()
endfunction
// Define some sub function
function sub_one()
disp('hello from sub_one')
endfunction
// call function main to execute
main()
Upvotes: 2