Your Pages‎ > ‎

User Subroutines

Add your User Subroutines or Functions contributions below...


Random RGB Colour - Electroguard 2/4/18

CODE: Random RGB Colour

sub randomcol(ret$)

local R, G, B

R = rnd(256)+1: G = rnd(256)+1: B = rnd(256)+1:

ret$ = "#" + right$("00000" + hex$((R << 16) + (G << 8) + B), 6)

end sub


Two User Subs for creating 3-byte numbers (hhmmss, yymmdd) from time and date strings ("hh:mm:ss", "dd/mm/yy") - Electroguard 2/4/18
Used for making straight-forward numeric comparisons of times or dates, ie: which of 2 dates is the latest.

CODE:

sub time(t$,ret)

local h,m,sy,

h = val(word$(t$,1,":"))

m = val(word$(t$,2,":"))

s = val(word$(t$,3,":"))

ret = (h << 16) + (m << 8) + s

end sub


sub date(d$,ret)

local d,m,y,ret

d = val(word$(d$,1,"/"))

m = val(word$(d$,2,"/"))

y = val(word$(d$,3,"/"))

ret = (y << 16) + (m << 8) + d

end sub



Save and Re-load parameters from a configuration file - Electroguard 2/4/18

CODE:

save:

' Saves settings to file

a$ = ""

if FILE.EXISTS(filename$) > 0 then a$ = FILE.READ$(filename$)

if a$ <> "" then b$ = a$

gosub setpars

FILE.SAVE filename$, a$

gosub paint

return


load:

' Loads settings from file

a$ = ""

gosub setpars

b$ = a$

a$ = ""

if FILE.EXISTS(filename$) > 0 then a$ = FILE.READ$(filename$)

gosub getpars

refresh

gosub paint

return


getpars:

if WORD.GETPARAM$(a$,"font$") <> ""  then font$ = WORD.GETPARAM$(a$,"font$")

if WORD.GETPARAM$(a$,"fontcol$") <> ""  then fontcol$ = WORD.GETPARAM$(a$,"fontcol$")

if WORD.GETPARAM$(a$,"fontstyle$") <> ""  then fontstyle$ = WORD.GETPARAM$(a$,"fontstyle$")

if WORD.GETPARAM$(a$,"fontweight$") <> ""  then fontweight$ = WORD.GETPARAM$(a$,"fontweight$")

if WORD.GETPARAM$(a$,"fontbak$") <> ""  then fontbak$ = WORD.GETPARAM$(a$,"fontbak$")

if WORD.GETPARAM$(a$,"fontgrad$") <> ""  then fontgrad$ = WORD.GETPARAM$(a$,"fontgrad$")

if WORD.GETPARAM$(a$,"fontgradflag$") <> ""  then fontgradflag = val(WORD.GETPARAM$(a$,"fontgradflag$"))

if WORD.GETPARAM$(a$,"fontpad$") <> ""  then fontpad$ = WORD.GETPARAM$(a$,"fontpad$")

if WORD.GETPARAM$(a$,"fontsize$") <> ""  then fontsize$ = WORD.GETPARAM$(a$,"fontsize$")

if WORD.GETPARAM$(a$,"bordsize$") <> ""  then bordsize$ = WORD.GETPARAM$(a$,"bordsize$")

if WORD.GETPARAM$(a$,"bordrad$") <> ""  then bordrad$ = WORD.GETPARAM$(a$,"bordrad$")

if WORD.GETPARAM$(a$,"bordcol$") <> ""  then bordcol$ = WORD.GETPARAM$(a$,"bordcol$")

if WORD.GETPARAM$(a$,"bakcol$") <> ""  then bakcol$ = WORD.GETPARAM$(a$,"bakcol$")

return


setpars:

WORD.SETPARAM  a$, "font$", font$

WORD.SETPARAM  a$, "fontstyle$", fontstyle$

WORD.SETPARAM  a$, "fontweight$", fontweight$

WORD.SETPARAM  a$, "fontcol$", fontcol$

WORD.SETPARAM  a$, "fontbak$", fontbak$

WORD.SETPARAM  a$, "fontgrad$", fontgrad$

WORD.SETPARAM  a$, "fontgradflag$", str$(fontgradflag )

WORD.SETPARAM  a$, "fontpad$", fontpad$

WORD.SETPARAM  a$, "fontsize$", fontsize$

WORD.SETPARAM  a$, "bordsize$", bordsize$

WORD.SETPARAM  a$, "bordrad$", bordrad$

WORD.SETPARAM  a$, "bordcol$", bordcol$

WORD.SETPARAM  a$, "bakcol$", bakcol$

return





HTM BUFFERED BROWSER MOUTHFULS - Electroguard 10/5/19

A User Sub to control buffered output to the browser in manageable mouthfuls to avoid memory indigestion.
It allows my script to run for continued development, whereas it had previously been stopping with 'out of memory' errors when sending output to the browser, so that's all I'm interested in.
Instead of using an accumulating variable (eg: a$=a$+"more") each line is sent directly to the HTM user sub as shown in the example snippet.
The HTM user sub will accumulate each new incoming$ string into buffer$ until it reaches the assigned buffersize, which will then cause that buffered mouthful to be sent to the browser, and pause long enough for it to be digested before sending any more.
Sending an empty string, ie: HTM  "", will flush the existing partial buffer$ contents out to the browser, so use this after sending all the data.. 

buffersize=2000        
incoming$=""
buffer$=""

HTM  "first bit" + "<br>"
HTM  "second bit" + "<br>"
HTM  ""            'calling subroutine with empty string causes existing buffer contents to be flushed out to the browser
wait

sub HTM(incoming$)
if (len(incoming$)+len(buffer$) > buffersize) or (incoming$="") then
 html buffer$
 buffer$=incoming$
 incoming$=""
 pause 200        'allows time for the browser to digest the current mouthful before being sent another (play with the delay to suit yourself)
else
 buffer$=buffer$+incoming$
 incoming$=""
endif
end sub


'--------------------------------------
  
Comentarios