General area when it fits no where else

Moderator: Mmiscool

User avatar
By tabbiati
#85954 Hello,
i am new to basic but i am interesting to this interpreter;
i made some test and i write a program but i have a error "return without gosub but i don't find it.
A little help for someone?

SSID = ""
Password = ""
Stringa = ""
Key = ""
IP = ""
SogliaTemperatura = ""
SogliaUmidita = ""
PosizioneServo = ""


Key = read(KeyStore)

if (Key = "127") then
SSID = read(locSSID)
Password = read(locPassword)
wifi.connect(SSID,Password)
else
wprint "<h1>Settings network</h1><hr/><br/>"
wprint "Access point SSID name: "
textbox SSID
wprint "<br/><br/>"
wprint "Access point SSID password: "
passwordbox Password
wprint "<br/><br/>"
button "Confirm", [connect_to_ap]
wprint "<br/><br/><hr/>"
endif

wprint "<h1>Home</h1><hr/><br/>"
wprint "Temperature now: "
wprint "<br/><br/>"
wprint "Humidity now: "
wprint "<br/><br/>"
wprint "Heater: "
wprint "<br/><br/>"
wprint "Humidifier: "
wprint "<br/><br/>"
wprint "Temperature threshold: "
wprint "<br/><br/>"
wprint "Humidity threshold: "
wprint "<br/><br/>"
wprint "Servo position: "
wprint "<br/><br/>
wprint "<br/><br/><hr/>"

wprint "<h1>Settings value</h1><hr/><br/>"
wprint "Temperature threshold: "
textbox SogliaTemperatura
wprint "<br/><br/>"
wprint "Humidity threshold: "
textbox SogliaUmidita
wprint "<br/><br/>"
wprint "Servo position: "
textbox PosizioneServo
wprint "<br/><br/>"
button "Send", [inviovalori]
wprint "<br/><br/><hr/>"


IP = ip()
serialbranch [serialin]
wait
end

[inviovalori]
serialprintln "Ciao"
return


[connect_to_ap]
write(KeyStore,"127")
write(locSSID,SSID)
write(locPassword,Password)
wprint "You must reboot...</h1><hr/><br/>"
do
loop until 0
return

[serialin]

serialinput Stringa

if (Stringa == "Reset") then
SSID = ""
Password = ""
write(KeyStore,"")
write(locSSID,"")
write(locPassword,"")
wifi.connect(SSID,Password)
endif

if (Stringa == "GetIP") then
serialprintln IP
endif

if (Stringa == "GetTemp") then
serialprintln "GetTemp"
endif

if (Stringa == "GetHumi") then
serialprintln "GetHumi"
endif

if (Stringa == "GetServo") then
serialprintln "GetServo"
endif

if (Stringa == "SetTemp") then
serialprintln "SetTemp"
endif

if (Stringa == "SetHumi") then
serialprintln "SetHumi"
endif

if (Stringa == "SetServo") then
serialprintln "SetServo"
endif


return
User avatar
By Electron250
#85976 Hi,
I dont have much knowledge of BASIC but looking at your listing I can see a "return" statement right at the very end of the list.

The "return" statement must have a corrosponding "gosub" statement somewhere in the listing in order to work. Your listing does not appear to have a "gosub" statement anywhere which is why you are receiving the error message.

If you do not need a "gosub / return" (subroutine) in your listing then you could simply try deletting the "return" statement and replace it with an "end" statement.

Here is an example explaining the correct use of the "gosub" and "return" statements....

[urlurl]https://www.purebasic.com/documentation/reference/gosub_return.html[/]

Hope this helps?

Regards,

Electron250
User avatar
By tabbiati
#85985 Hi Electron250,
also i am not expert but return at the close subroutine [serialin] and other return close [xxxx].... if i think correct!