Variable based Restore with Read/Data

General FreeBASIC programming questions.
Post Reply
rpkelly
Posts: 52
Joined: Sep 03, 2016 22:36

Variable based Restore with Read/Data

Post by rpkelly »

Is it possible to use Restore with a variable containing the block name to support random block access to a series of DATA statements?

Code: Select all

Dim sRead as String
Dim sBlock as string

sBlock = "Data2"
Restore Data2             ' I'd like to use Restore with the data value in variable sBlock
Read sRead
Print sRead

Print "press q to quit"
Do
     Sleep 1, 1
Loop Until Inkey = "q"

Data1:
Data "1"
Data2:
Data "2"
Data3:
Data "3"
fxm
Moderator
Posts: 12107
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Variable based Restore with Read/Data

Post by fxm »

No.
By cons, we can test the string value and restore the next-data-to-read pointer accordingly:

Code: Select all

Dim sRead as String
Dim sBlock as string

sBlock = "Data2"

Select Case sBlock
Case "Data1"
  Restore Data1
Case "Data2"
  Restore Data2
Case "Data3"
  Restore Data3
End Select

Read sRead
Print sRead

Print "press q to quit"
Do
     Sleep 1, 1
Loop Until Inkey = "q"

Data1:
Data "1"
Data2:
Data "2"
Data3:
Data "3"
rpkelly
Posts: 52
Joined: Sep 03, 2016 22:36

Re: Variable based Restore with Read/Data

Post by rpkelly »

fxm wrote:No.
By cons, we can test the string value and restore the next-data-to-read pointer accordingly:
OK, it was a long shot. I was looking at best way for my IANA time zone parser to emit values. I can emit a series of statements that load arrays instead.
Post Reply