Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #5503

Re: how to use a sysvar in Basic

From "John Williams (News)" <UCEbin@tiscali.co.uk>
Subject Re: how to use a sysvar in Basic
Newsgroups comp.sys.acorn.programmer
Date 2018-09-04 18:16 +0100
Message-ID <57325ba594UCEbin@tiscali.co.uk> (permalink)
References <d1fd503257.jim@6.abbeypress.net>
Organization League of Underpaid, Overworked, Undervalued, and Overwhelmed

Show all headers | View raw


In article <d1fd503257.jim@6.abbeypress.net>,
   Jim Nagel <jimnewsm13c@abbeypress.co.uk> wrote:

> Leads me to think there's something fundamental I need to understand 
> about the use of sysvars within Basic.

I have saved this useful snippet for further use:

<quote>
On Tue, 06 Oct 2009 17:17:52 +0100, Alan Adams <alan@adamshome.org.uk>
wrote:

>[...]
>
>DEF PROCsetsysvar(varname$,varval$)
>LOCAL vallen%
>LOCAL name% , val%
>DIM name% LEN(varname$)+1, val% LEN(varname$)+1
>$name%=varname$+CHR$(0)
>$val%=varval$+CHR$(0)
>vallen%=LEN(varval$)
>SYS "OS_SetVarVal",name%,val%,vallen%,0,0
>ENDPROC

There's no need whatsoever for the explicit DIMming and
0-termination. On SYS calls, BASIC already takes care
of that for you (if there's a string parameter, its
0-terminated value is copied to the BASIC stack, and
discarded after the SYS call).

I.e. simply replace the whole PROC with :

SYS "OS_SetVarVal", varname$, varval$, LEN(varval$), 0, 0

>DEF FNgetsysvar(varname$)
>LOCAL name% ,val% ,vallen%
>DIM name% LEN(varname$)+1,val% 200
>$name%=varname$+CHR$(0)
>SYS "XOS_ReadVarVal",name%,,-1 TO ,,vallen%
>IF vallen%<0 THEN
>SYS "OS_ReadVarVal",name%,val%,200,0,3 TO ,,vallen%
>val%?vallen%=13
>ELSE
>?val%=13
>ENDIF
>=$val%

Same thing, also for the return value.

I.e. :

varval$ = ""

SYS "OS_ReadVarVal", varname$, STRING$(255, CHR$0), 255, 0,
3 TO , varval$

(varval$ will be "" if the variable is undefined, the STRING$
reserves a temporary buffer for the return value on the BASIC
stack, which is discarded after the SYS call)


John Kortink

[sig separator removed] 

Email    : kortink@inter.nl.net
Homepage : http://www.inter.nl.net/users/J.Kortink

There's something to be said, for getting out of bed

</quote>

There's also something to be said for saving useful snippets!

Best wishes, 
 
John

-- 
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 16:20 +0100
  Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-04 18:00 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 18:54 +0100
      Re: how to use a sysvar in Basic Julian Fry <julianfry@orpheusmail.co.uk> - 2018-09-08 21:03 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-05 17:13 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 20:19 +0100
        Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-06 11:19 +0100
          Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-08 10:32 +0100
            Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-08 14:56 +0100
              Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-08 19:39 +0100
              Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-10 07:27 +0100
                Re: /  not  (OT) Jim Nagel <jnews18c@abbeypress.co.uk> - 2018-09-10 11:37 +0100
                Re: /  not  (OT) News <chrisjohnson@spamcop.net> - 2018-09-10 14:34 +0100
    Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-08 11:20 +0100
      Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-08 14:40 +0100
  Re: how to use a sysvar in Basic "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-09-04 18:16 +0100
    Re: how to use a sysvar in Basic Alan Adams <alan@adamshome.org.uk> - 2018-09-04 22:04 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 08:03 +0100
        Re: how to use a sysvar in Basic Martin Wuerthner <spamtrap@mw-software.com> - 2018-09-05 14:39 +0200
          Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 19:45 +0100
            Re: how to use a sysvar in Basic Steve Drain <steve@kappa.me.uk> - 2018-09-06 11:24 +0100
    Re: how to use a sysvar in Basic "John Williams (News)" <UCEbin@tiscali.co.uk> - 2018-09-05 20:56 +0100
      Re: how to use a sysvar in Basic svrsig <chris@svrsig.org> - 2018-09-05 20:13 -0700
        Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-06 07:21 +0100
  Re: how to use a sysvar in Basic A. N. Other <ANOther@argonet.co.uk> - 2018-09-04 18:11 +0100
    Re: how to use a sysvar in Basic Jim Nagel <jimnewsm13c@abbeypress.co.uk> - 2018-09-04 18:42 +0100
      Re: how to use a sysvar in Basic Matthew Phillips <spam2011m@yahoo.co.uk> - 2018-09-05 08:08 +0100
  Re: how to use a sysvar in Basic jgh@mdfs.net - 2018-09-06 17:12 -0700

csiph-web