Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pete's Dumb Idea of the Day!
#1
Wouldn't it be nice to have this feature for Data Restore?

On x Restore data1, data2, data3

instead of needing to code...

Select Case x
Case 1: Restore data1
Case 2: Restore data2
Case 3: Restore data3
End Select

data1:
data eof
data2:
data eof
data3:
data eof

Be sure to post your hate comments in a respectful, non-micro-aggressive and culturally appropriate manner. Oh who am I kidding? Comment however the hell you want!

Pete
Reply
#2
(10-21-2024, 07:53 PM)Pete Wrote: Wouldn't it be nice to have this feature for Data Restore?

On x Restore data1, data2, data3

instead of needing to code...

Select Case x
Case 1: Restore data1
Case 2: Restore data2
Case 3: Restore data3
End Select

data1:
data eof
data2:
data eof
data3:
data eof

Be sure to post your hate comments in a respectful, non-micro-aggressive and culturally appropriate manner. Oh who am I kidding? Comment however the hell you want!

Pete
Hi Pete
what do you think about this alternative solution?

Code: (Select All)

Rem  demo Restore : On x Restore idea

For x = 1 To 4
    On x GOSUB data1, data2, data3, data4
    Read number, nam$, Order$
    Print number, nam$, Order$
Next

End

data1:
Restore data1
Return
Data 1,one,the first

data2:
Restore data2
Return
Data 2,two,the second


data3:
Restore data3
Return
Data 3,three,the third

data4:
Restore data4
Return
Data 4,four,the forth

the trick is to heading the label of data selected with a restore to itself and a return to come back to the main loop of reading data.
Yes it use GOSUB and not GOTO. But if you like you can put a label at the start of reading instructions and  coming back GOTO to that label from data area.
Reply
#3
(10-21-2024, 07:53 PM)Pete Wrote: Wouldn't it be nice to have this feature for Data Restore?

On x Restore data1, data2, data3

instead of needing to code...

Select Case x
Case 1: Restore data1
Case 2: Restore data2
Case 3: Restore data3
End Select

data1:
data eof
data2:
data eof
data3:
data eof

Be sure to post your hate comments in a respectful, non-micro-aggressive and culturally appropriate manner. Oh who am I kidding? Comment however the hell you want!

Pete

Yup, that is very BASIC to me: https://basicanywheremachine.neocities.o...STORE#Home
Reply
#4
Sure!  That would be awesome.  You know what would be better???  If we could get _Resize working properly !!!  WooHoo...that would be incredible.
Reply
#5
Yeah, _Resize can be a pain. That's why I use _Viagra. Now if you work with smaller apps, like Steve, it's not so necessary. Big Grin

Oh, and see, Charlie beat you guys to it! +1

And for my friend from my families homeland... I think you managed to go in the opposite direction, and find a more complicated way than Select Case, but it did showcase just how cool creativity is when it comes to coding! +1.

Pete
Shoot first and shoot people who ask questions, later.
Reply
#6
Who the hell reads data so much, just get an array and be done with it. But it's not the dumbest idea I ever saw.

Who the hell can't make up their mind what size they need, pick one bigger than you will ever need, the space will fill, it's a law of nature. Size does matter, a little...

Since we are wishing here, I want a keyboard that types the words I mean not the ones that come out at the ends of my fingers, wait that can't be at the top of my list,... for QB64?

Ah, arrays! Functions that can return them and Types that can accommedate them (spell checker in forum editors) and while at it, Functions that return UDT's.
Lets focus on that people!
b = b + ...
Reply
#7
Other languages have "Array initialization" features, but QB64 does not. I'm not too fond of DATA, but that's a personal choice.

I'd rather see true array initialization capability in QB64.

https://github.com/QB64-Phoenix-Edition/.../issues/47

Other interesting stuff:
https://github.com/QB64-Phoenix-Edition/.../issues/30
https://github.com/QB64-Phoenix-Edition/...issues/135
https://github.com/QB64-Phoenix-Edition/...issues/212
Reply
#8
I'm uncomfortable with it. Data is good for a hard-coded part of the program where nothing will change. But - during development, who never changed anything? I like the solution with an array and a function that returns it all as a result much better, even if it takes more time to write the function. Something like this:

Code: (Select All)

Type Record
    As Integer number
    As String text1, text2
End Type
ReDim Shared Rec(0) As Record
Dim Values(1 To 4) As Integer

Values(1) = InitRecord(1, "one", "the first")
Values(2) = InitRecord(2, "two", "the second")
Values(3) = InitRecord(3, "three", "the third")
Values(4) = InitRecord(4, "four", "the forth")

For Show = 1 To 4
    PrintRecord Show
Next
Erase Rec
Erase Values
End

Function InitRecord (number As Integer, t1 As String, t2 As String)
    U = UBound(Rec) + 1
    ReDim _Preserve Rec(U) As Record
    Rec(U).number = number
    Rec(U).text1 = t1
    Rec(U).text2 = t2
    InitRecord = U
End Function

Sub PrintRecord (Id As Integer)
    Print Rec(Id).number, Rec(Id).text1, Rec(Id).text2
End Sub


Reply
#9
@a740g 
 I have used sometimes DATA and READ and RESTORE for fun, but their logic is far away from chunking down a task in so many littler tasks.

@Petr
Yes your is a more modular code

@Pete
I have proposed a tricky way to build an ON x RESTORE label1,label2,label3....,labelN-1, labelN
it works because if you declare a label in the right part of the line of code ( just after RESTORE) you must also type the label in the code.
Using SELECT CASE a unpredictable value causes troubles...
run this code
Code: (Select All)
 
Rem  demo Restore : On x Restore idea    vs Select Case

For x = 0 To 4
    On x GOSUB data1, data2, data3, data4
    Read number, nam$, Order$
    Print number, nam$, Order$
Next
Print "----------------------------------------------"
For x = 0 To 4
    Select Case x
        Case 1
            Restore data1
        Case 2
            Restore data2
        Case 3
            Restore data3
        Case 4
            Restore data4
    End Select

    Read number, nam$, Order$
    Print number, nam$, Order$
Next

End

data1:
Restore data1
Return
Data 1,one,the first

data2:
Restore data2
Return
Data 2,two,the second


data3:
Restore data3
Return
Data 3,three,the third

data4:
Restore data4
Return
Data 4,four,the forth

but I haven't found any function dedicated to RESTORE in internal code of QB64.
There is only a managing of pointer into section of QB64IDE.
So I dunno how RESTORE is coded into c++ and how it can be expanded.
Reply
#10
Well with Select Case you would use...

Code: (Select All)
 
Rem  demo Restore : On x Restore idea    vs Select Case
For x = 1 To 4
     Select Case x
        Case 1
            Restore data1
        Case 2
            Restore data2
        Case 3
            Restore data3
        Case 4
            Restore data4
    End Select
    Print "----------------------------------------------"
    Read number, nam$, Order$
    Print number, nam$, Order$
Next
End
data1:
Data 1,one,the first
data2:
Data 2,two,the second
data3:
Data 3,three,the third
data4:
Data 4,four,the forth

Pete
Shoot first and shoot people who ask questions, later.
Reply




Users browsing this thread: 1 Guest(s)