CODE: errors.bas
CODE: google_sheet4.bas
print "inizio"
onerror goto pippo
print "prima"
gosub lello
'onerror skip 1
a$ = space$(60000)
print "dopo"
wait
lello:
'onerror skip 1
print 33/0
print "detro lello"
return
pippo:
print "dentro error ", bas.errmsg$, bas.errnum, bas.errline
onerror goto off
return
' write in a google sheet
' the sheet is https://docs.google.com/spreadsheets/d/1r63eRys9gllwTSywWJUNEeuGWVIlEayZpx8g2fzAjyc/edit#gid=0
' it calls a script with the following ID
' writes with tag=TAGNAME&value=VALUE
' reads with read=A2 ( cells)
script_id$ = "AKfycbwcx_wuEL2REoueaAWZK1X9TOqLXhNKgqjQn7RsBHaIUe9cop5F"
ret$ = ""
for z = 0 to 180
msg$ = "tag=" + str$(z)+ "&value=" + str$(sin( 2*PI / 180 * z))
exec_macro script_id$, msg$, ret$
wlog ret$
next z
msg$ = "read=d2"
exec_macro script_id$, msg$, ret$
wlog ret$
sub exec_macro(key$, payload$, ret$)
local query$, q2$, r$
query$ = "script.google.com/macros/s/" + key$ + "/exec?" + payload$
r$ = wget$(query$, 443, 0) ' last optional parameter, if =1, includes the header in the answer
'exit sub ' this is useful to speedup the write as the 2nd wget is not required
r$ = word.extract$(r$, "https://", |"| )
r$ = replace$(r$, "&", "&") ' replace & with &
ret$ = wget$(r$, 443)
end sub
CODE: textarea.bas
cls
t$ = "first" + chr$(13) + "second" + chr$(13) + "third"
a$ = ""
a$ = a$ + textarea$(t$, "tarea") + "<br>"
a$ = a$ + button$("Update", update)
a$ = a$ + cssid$("tarea", "width:400px; height:400px")
html a$
wait
update:
wlog t$
return
CODE: googlesheet_demo3.bas
' write in a google sheet
' the sheet is https://docs.google.com/spreadsheets/d/13ep8XJXyyEbblaasyMRmx-DvXvSG1n_OFPgjN-TSsfk/edit#gid=0
' it calls a script with the following ID AKfycbz5tR58jr7rJktapMNbinEGASUeeV2EthRv1uaPOrYEoyiDTMA
' writes 30 lines of data and then read back them
' to write the message is sensor1=value&sensor2=value&sensor3=value&sensor4=value
' to clear the message is clear=1
' to read the message is read=line
' this is the url of the script
'https://script.google.com/macros/s/AKfycbz5tR58jr7rJktapMNbinEGASUeeV2EthRv1uaPOrYEoyiDTMA/exec
script_id$ = "AKfycbz5tR58jr7rJktapMNbinEGASUeeV2EthRv1uaPOrYEoyiDTMA"
ret$ = ""
' clear the content of the sheet
exec_macro script_id$, "clear=1", ret$
' write 4 sensors values
for z = 0 to 1000
s1 = sin(2*PI * z/30)
s2 = sin(2*PI * z/30 + PI/6) '30°
s3 = sin(2*PI * z/30 + PI/3) '60°
s4 = sin(2*PI * z/30 + PI/2) '90°
msg$ = ""
msg$ = msg$ + "sensor1=" + str$(s1) + "&"
msg$ = msg$ + "sensor2=" + str$(s2) + "&"
msg$ = msg$ + "sensor3=" + str$(s3) + "&"
msg$ = msg$ + "sensor4=" + str$(s4)
exec_macro script_id$, msg$, ret$
print ret$
print ramfree
next z
'read back the lines
for z = 1 to 31
msg$ = "read=" + str$(z)
exec_macro script_id$, msg$, ret$
print ret$
next z
sub exec_macro(key$, payload$, ret$)
local query$, q2$, r$
query$ = "script.google.com/macros/s/" + key$ + "/exec?" + payload$
queryp$ = "script.google.com/macros/s/" + key$ + "/exec"
r$ = wget$(query$, 443, 0) ' last optional parameter, if =1, includes the header in the answer
'r$ = wpost$(queryp$, payload$, 443) ' last optional parameter, if =1, includes the header in the answer
print r$
exit sub ' this is useful to speedup the write as the 2nd wget is not required
'pause 500
r$ = word.extract$(r$, "https://", |"| )
r$ = replace$(r$, "&", "&") ' replace & with &
ret$ = wget$(r$, 443)
end sub