It is currently Sat Mar 25, 2017 12:34 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: settings/flag functions
Unread postPosted: Sun Dec 06, 2015 3:57 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
I use these functions to manage my saved program flags and numerical settings in one convenient settings.ini file
They store the settings as strings which are extremely fast in BASIC!

Examples:

CALL wset("speech", 1)
IF rset("speech")
PRINT "Speech mode on"
ELSE
PRINT "Speech mode off"
ENDIF

Not sure there is a faster way to do this, but this seems to work pretty well for me.




Code:
! slightly more tolerant val function
FN.DEF val2(s$)
let s$=TRIM$(s$):let l=len(s$)
DO
  i++
  LET bad=!IS_IN(MID$(s$,i,1),"-0123456789.")
UNTIL bad|i>=l
IF !bad then FN.RTN VAL(s$) 
FN.RTN 0
FN.END


FN.DEF rset(s$)
! PRE: s$ is setting name
! POST: RETURNs value of setting s$ or 0 if not found
LET F$="settings.ini"
FILE.EXISTS e,f$
IF !e THEN FN.RTN 0
GRABFILE b$,f$
LET i=IS_IN(s$,b$)
IF !i THEN FN.RTN 0
LET t$=MID$(b$,i+LEN(s$),20)
LET v$=TRIM$(WORD$(t$,1,CHR$(10)))
IF v$="" THEN FN.RTN 0
FN.RTN VAL2(v$)
FN.END

FN.DEF writeln(f$,msg$)
TEXT.OPEN w,h,f$
TEXT.WRITELN h,msg$
TEXT.CLOSE h
FN.END

FN.DEF wset(s$,v)
! PRE: s$ is setting name,v is value to set
! POST: setting named s$ is set to v
LET F$="settings.ini"
LET ns$=s$+"\t"+INT$(v)
IF isold(f$)
  TEXT.OPEN r,h,f$
  LET o$=ns$+CHR$(10)
  DO
   TEXT.READLN h,a$
   IF a$="EOF" THEN D_U.BREAK
   IF !found & WORD$(a$,1,"\t")=s$
    LET found=1
   ELSE
    o$+=a$+CHR$(10)
   ENDIF
  UNTIL a$="EOF"
ENDIF

TEXT.CLOSE h

CALL writeln(f$,TRIM$(o$))
FN.END




Top
 Profile  
 
 Post subject: Re: settings/flag functions
Unread postPosted: Mon Jan 25, 2016 9:24 am 
Offline

Joined: Fri Dec 25, 2015 9:45 pm
Posts: 17
I just read the post stating strings are faster in Rbasic!, and I've been interested in porting a working eval function for quite a while so if it's alright with you, I'd like to borrow/modify these functions from you.


Top
 Profile  
 
 Post subject: Re: settings/flag functions
Unread postPosted: Mon Jan 25, 2016 9:42 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5447
Location: Paris, France
What is Rbasic? Is it Xojo (aka realbasic) ?

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: settings/flag functions
Unread postPosted: Mon Jan 25, 2016 10:13 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 408
Arion--

No problem--- hope it works!

I didn't know about global bundles when I wrote this.. not sure which works faster.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred