DATA statements - possible in Gambas ?
Posted
#1
(In Topic #616)
Regular

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
Something like that. Does Gambas have something similar? I can't find it.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
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.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

Posted
Regular

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.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Regular

Doctor Watson said
…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;
Posted
Guru

Doctor Watson said
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
Posted
Regular

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 :
looks very close to the ‘old’ BASIC way.fData[0] = [3.08, 5.19, 3.12, 3.98, 4.24]
fData[1] = [5.08, 5.55, 4.00, 3.16, 3.37]
I’ll have a go at it.
Cheers and all of you have a nice weekend
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

<COLOR color="#FF0000">WARNING: - This slows the IDE down a lot when accessing the Module</COLOR>
<IMG src="https://www.cogier.com/gambas/InternalData.png">
</IMG>
Posted
Guru

Doctor Watson said
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 :
looks very close to the ‘old’ BASIC way.fData[0] = [3.08, 5.19, 3.12, 3.98, 4.24]
fData[1] = [5.08, 5.55, 4.00, 3.16, 3.37]
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
Posted
Regular

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
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Guru

Doctor Watson said
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
1 guest and 0 members have just viewed this.


