Page 1 of 1

DATA statements - possible in Gambas ?

Posted: Friday 12th March 2021 10:06am
by Doctor Watson
Good morning / evening (whatever)

Getting underway with CSV files made me think of DATA statements.
In my project, I will be using some specific data that stay always the same.
In some BASIC languages you can store those in the executable itself, as you probably know.
If not, here’s an example in GW_BASIC
80 FOR I=1 TO 10
90 READ A(I)
100 NEXT I

110 DATA 3.08,5.19,3.12,3.98,4.24
120 DATA 5.08,5.55,4.00,3.16,3.37
Something like that. Does Gambas have something similar? I can't find it.
Of course I can just store such data in a CSV file and import them when de programme starts, but when they can ‘reside’ in the compiled programme itself, some adventurous user cannot tamper with them – unless he/she knows how to use a binary editor.

Re: DATA statements - possible in Gambas ?

Posted: Friday 12th March 2021 2:51pm
by cogier
That code took me back to the ZX Spectrum.

You can store the data in the code like this: -
Public Sub Form_Open()

  Dim fData As Float[] = [3.08, 5.19, 3.12, 3.98, 4.24, 5.08, 5.55, 4.00, 3.16, 3.37]
  Dim iLoop As Integer

  For iLoop = 0 To fData.Max
    Print fData[iLoop]
  Next

End

Re: DATA statements - possible in Gambas ?

Posted: Saturday 13th March 2021 7:06am
by Doctor Watson
Hi Cougier
That’s perfect for a small number of data, but I would need to store between 100 and 200 data. Wouldn’t be very practical, would it?
As I gather, a DATA statement is not possible in Gambas. Other BASIC develloppers have dropped this as well or haven’t been including it considering it old fashioned perhaps.
That’s regrettable – my opinion that is – because it offers some very neat possibilities, such as shielding essential data from being manipulated.
Well, I rest my case.

Re: DATA statements - possible in Gambas ?

Posted: Saturday 13th March 2021 9:03am
by stevedee
Doctor Watson wrote: Saturday 13th March 2021 7:06am ...That’s perfect for a small number of data, but I would need to store between 100 and 200 data. Wouldn’t be very practical, would it?...
I don't know why you think that it wouldn't be practical. To keep the code neat, just put it in its own module;
'this is a data module
Public Function LoadBigData() As Float[]
 
  Dim fData As Float[] = [3.08, 5.19, 3.12, 3.98, 4.24, 5.08, 5.55, 4.00, 3.16, 3.37]

  Return fData
 
End

Re: DATA statements - possible in Gambas ?

Posted: Saturday 13th March 2021 10:57am
by BruceSteers
Doctor Watson wrote: Saturday 13th March 2021 7:06am Hi Cougier
That’s perfect for a small number of data, but I would need to store between 100 and 200 data. Wouldn’t be very practical, would it?
As I gather, a DATA statement is not possible in Gambas. Other BASIC develloppers have dropped this as well or haven’t been including it considering it old fashioned perhaps.
That’s regrettable – my opinion that is – because it offers some very neat possibilities, such as shielding essential data from being manipulated.
Well, I rest my case.
NO that ancient old useless method was dropped for better ways ;)

Dim fData As New Float[]
fData[0] = [3.08, 5.19, 3.12, 3.98, 4.24]
fData[1] = [5.08, 5.55, 4.00, 3.16, 3.37]
Or however you want your array of numbers.

seems less confusing than
110 DATA 3.08,5.19,3.12,3.98,4.24
120 DATA 5.08,5.55,4.00,3.16,3.37

(how would you even retrieve that data?)

And how would a statement like either of them in your code be unshielded unless you built it that way?

What you say does not really make sense

Re: DATA statements - possible in Gambas ?

Posted: Sunday 14th March 2021 6:09am
by Doctor Watson
Where I said ‘shielded’ : I do mean that if data are stored within the programme file itself – or application, app, executable or whatever it’s called – tampering with them becomes a lot more unlikely. When they are kept in an external file, that file can intententionally or not be edited, overwritten, deleted ….
As to the DATA statements I included initially, They are just some lines of code I found in GW-BASIC (yes, it’s very ancient). I should have formulated things better.
But this :
fData[0] = [3.08, 5.19, 3.12, 3.98, 4.24]
fData[1] = [5.08, 5.55, 4.00, 3.16, 3.37]
looks very close to the ‘old’ BASIC way.
I’ll have a go at it.
Cheers and all of you have a nice weekend

Re: DATA statements - possible in Gambas ?

Posted: Sunday 14th March 2021 4:51pm
by cogier
I had a look at this and I find that you can do this. The attached program has a dictionary of 25105 words all stored in a string in a Module.

WARNING: - This slows the IDE down a lot when accessing the Module

Image
InternalData-0.0.1.tar.gz
(91.41 KiB) Downloaded 293 times

Re: DATA statements - possible in Gambas ?

Posted: Sunday 14th March 2021 7:18pm
by BruceSteers
Doctor Watson wrote: Sunday 14th March 2021 6:09am Where I said ‘shielded’ : I do mean that if data are stored within the programme file itself – or application, app, executable or whatever it’s called – tampering with them becomes a lot more unlikely. When they are kept in an external file, that file can intententionally or not be edited, overwritten, deleted ….
As to the DATA statements I included initially, They are just some lines of code I found in GW-BASIC (yes, it’s very ancient). I should have formulated things better.
But this :
fData[0] = [3.08, 5.19, 3.12, 3.98, 4.24]
fData[1] = [5.08, 5.55, 4.00, 3.16, 3.37]
looks very close to the ‘old’ BASIC way.
I’ll have a go at it.
Cheers and all of you have a nice weekend

Okay I see, so do you know this...

When you hit "Make Executable" in the gambas IDE the resulting ProjectName.gambas file that is created is an archive containing all the binaries and any other files inside the Project directory (except the source code files)

So your data files can just exist in your source directory and your app exe can ALWAYS access them with the absolute path "./"
Your Appname.gambas executable does not then need the source directory (it's all inside the exe)
So they are fairly shielded that way, you'd have to know how to reverse compile a gambas app to get to the data files.

Or you can add them to a .module or .class file in the projects .src/ directory.
that way the module/class is compiled to the .gambas directory as a binary and the binary is added to the executable but not the source file.

Does that make sense?

And an additional note.
This is gambas basic. you are going to have to adjust from the old ways of other basic environments.

"Gambas Almost Means Basic" ;)
Bruce

Re: DATA statements - possible in Gambas ?

Posted: Monday 15th March 2021 9:23am
by Doctor Watson
Hi Bruce & Cogier

Indeed Cogier, but I won’t ever have to handle so many dates.
But Bruce’s sollution looks more what I’m looking for.
Up till now I only spotted that there’s something like a ‘.module’ or an extra ‘.class’ (besides the Main.class), never used one of those.
One more thing to learn.

Remember the elephant. It will take some time to digest. Only problem : whenever I take a bite, the elephant just seems to grow bigger …

Cheers

Re: DATA statements - possible in Gambas ?

Posted: Monday 15th March 2021 10:45am
by BruceSteers
Doctor Watson wrote: Monday 15th March 2021 9:23am Hi Bruce & Cogier

Indeed Cogier, but I won’t ever have to handle so many dates.
But Bruce’s sollution looks more what I’m looking for.
Up till now I only spotted that there’s something like a ‘.module’ or an extra ‘.class’ (besides the Main.class), never used one of those.
One more thing to learn.

Remember the elephant. It will take some time to digest. Only problem : whenever I take a bite, the elephant just seems to grow bigger …

Cheers
I'd just like to say using Long[] vars was Cogiers idea and using modules was Steve idea :)

My only idea was to try to explain those 2 ideas a bit better ;)

Bruce