Page 1 of 2
DataStructure
Posted: Wed Feb 03, 2010 11:24 am
by Michael Vogel
According to some ideas like StringSection I'd like to ask if the DataSection command could get some improvements...
...I have a list of more than 20.000 cities, their country and latitude/longitude values. I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible.
So the country will be translated to a single byte and the coordinates to floats, the cityname will be kept as a string:
Code: Select all
Andorra la Vella 1 42,51 1,51
Les Escaldes 1 42,50 1,53
Abû Zabi 2 24,48 54,37
al-ŽAyn 2 24,23 55,74
Khawr Fakkân 2 25,34 56,36
:
When I transfer this to PB, I have two possiblities, one is to write three lines for each city...
Code: Select all
Data.s Andorra la Vella
Data.b 1
Data.f 42.51 1.51
...or to split the data into three (or four) different areas:
Code: Select all
Data.s "Andorra la Vella","Les Escaldes",...
Data.b 1,1,2,...
Data.f Data42.51,1.51,42.50,...
Would anyone see an improvement in having the possibility to get different data types in one Data row? I'm not sure, if such things are needed often (for me, this is the first time, I think about such things

) -- however, a data section could look like this:
Code: Select all
DataStructure .x Uses "sbff"
Data.x "Andorra la Vella",1,42.51,1.51
Data.x "Les Escaldes,1,42.50,1.53
Re: DataStructure
Posted: Wed Feb 03, 2010 11:40 am
by KJ67
Something like
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
DataSection
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
Re: DataStructure
Posted: Wed Feb 03, 2010 4:25 pm
by blueznl
Oh, KJ67, that's a nice idea! And it matches the generic syntax of PureBasic nicely!
Re: DataStructure
Posted: Wed Feb 03, 2010 4:34 pm
by mback2k
blueznl wrote:Oh, KJ67, that's a nice idea! And it matches the generic syntax of PureBasic nicely!
Yeah, this idea is a lot more PureBasic-style than the StringSection thing.
Re: DataStructure
Posted: Wed Feb 03, 2010 4:37 pm
by Seymour Clufley
mback2k wrote:Yeah, this idea is a lot more PureBasic-style than the StringSection thing.
It's a completely different thing. This doesn't address multilines, Chr(34)s within the string etc., which is what my StringSection request is about.
Re: DataStructure
Posted: Wed Feb 03, 2010 5:02 pm
by flaith
KJ67 wrote:Something like
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
DataSection
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
And how do you read the datas ?
Re: DataStructure
Posted: Wed Feb 03, 2010 5:23 pm
by KJ67
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
Define.XYZ MyVar
Restore MyData
Read.XYZ MyVar
DataSection
MyData:
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
Why not follow the rules that already exists, just allow reading structures too?
Personally I do not need any brand new function, just a update of the already existing rules and function.
Re: DataStructure
Posted: Wed Feb 03, 2010 6:40 pm
by flaith

hey, really neat that way
Re: DataStructure
Posted: Wed Feb 03, 2010 7:20 pm
by Demivec
Wouldn't this problem be the same as the one in the file library. If a structure was read from a file you would still need to use ReadInteger(), ReadString(), and ReadFloat().
If a solution like that mentioned above is implemented for the DataSection then it can be done for the file library by using a ReadStructure(fileID, *pointer, structure). At least it would seem reasonable. Likewise a WriteStructure(fileID, *pointer, structure) could be possible.
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
Define fileID = 0
If OpenFile(fileID,"C:\outputFile")
Define.XYZ MyVar
Restore MyData
Read.XYZ MyVar
WriteStructure(fileID,@MyVar,XYZ)
CloseFile(fileID)
EndIf
DataSection
MyData:
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
It certainly would fill in a few holes. I'm not sure how many it would create though.

Re: DataStructure
Posted: Wed Feb 03, 2010 7:33 pm
by jamirokwai
KJ67 wrote:Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
Define.XYZ MyVar
Restore MyData
Read.XYZ MyVar
DataSection
MyData:
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
Why not follow the rules that already exists, just allow reading structures too?
Personally I do not need any brand new function, just a update of the already existing rules and function.
Great Idea!
Re: DataStructure
Posted: Wed Feb 03, 2010 7:44 pm
by ts-soft
Demivec wrote:Wouldn't this problem be the same as the one in the file library. If a structure was read from a file you would still need to use ReadInteger(), ReadString(), and ReadFloat().
If a solution like that mentioned above is implemented for the DataSection then it can be done for the file library by using a ReadStructure(fileID, *pointer, structure). At least it would seem reasonable. Likewise a WriteStructure(fileID, *pointer, structure) could be possible.
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
Define fileID = 0
If OpenFile(fileID,"C:\outputFile")
Define.XYZ MyVar
Restore MyData
Read.XYZ MyVar
;WriteStructure(fileID,@MyVar,XYZ)
WriteData(fileID, @MyVar, SizeOf(XYZ))
CloseFile(fileID)
EndIf
DataSection
MyData:
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
The only problem is a non fixed String, but with WriteStructure should the same problem
Re: DataStructure
Posted: Wed Feb 03, 2010 7:51 pm
by Demivec
ts-soft wrote:The only problem is a non fixed String, but with WriteStructure should the same problem
Well, since these are only wishes it means that is what would be taken care of by the developers.
Since my suggestion for files, and the other's for datasections would be compile-time functions that would transform into an appropriate series of actions based on the structure, it shouldn't be hard to deal with a 'normal' string. There would be other problems, but not that one.
These are just ideas, all can be accomplished with what currently exists.
Re: DataStructure
Posted: Sat Apr 20, 2013 2:24 am
by Tenaja
KJ67 wrote:Something like
Code: Select all
Structure XYZ
a.i
b.s
c.f
d.f
EndStructure
DataSection
Data.XYZ 10, "Some text...", 3.14, 2.9111
EndDataSection
would be very useful
+1
Re: DataStructure
Posted: Sat Apr 20, 2013 7:20 am
by davido
+1
I'd like it for my 25,000 Uk places
Re: DataStructure
Posted: Sat Apr 20, 2013 4:09 pm
by heartbone
Michael Vogel wrote:According to some ideas like StringSection I'd like to ask if the DataSection command could get some improvements...
...I have a list of more than 20.000 cities, their country and latitude/longitude values. I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible.
So the country will be translated to a single byte and the coordinates to floats, the cityname will be kept as a string:
Code: Select all
Andorra la Vella 1 42,51 1,51
Les Escaldes 1 42,50 1,53
Abû Zabi 2 24,48 54,37
al-ŽAyn 2 24,23 55,74
Khawr Fakkân 2 25,34 56,36
:
When I transfer this to PB, I have two possiblities, one is to write three lines for each city...
Code: Select all
Data.s Andorra la Vella
Data.b 1
Data.f 42.51 1.51
...or to split the data into three (or four) different areas:
Code: Select all
Data.s "Andorra la Vella","Les Escaldes",...
Data.b 1,1,2,...
Data.f Data42.51,1.51,42.50,...
Would anyone see an improvement in having the possibility to get different data types in one Data row? I'm not sure, if such things are needed often (for me, this is the first time, I think about such things

) -- however, a data section could look like this:
Code: Select all
DataStructure .x Uses "sbff"
Data.x "Andorra la Vella",1,42.51,1.51
Data.x "Les Escaldes,1,42.50,1.53
Since you guys are continuing to extend this three plus year old thread, I'll throw in my 2¢.
The original poster's premise is that he has two possibilities.
I see many other ways to get the job done, that is to achieve
"I'd like to include the list into a PB source to have the data "onboard" -- and as compact as possible."
Using a float to store the coordinates, when they only run to two decimal places is a waste but could be supported.
How about using an integer and dividing it by 100 to get the float value?
How about storing said integer (as well as the country byte) in a fixed field string and then converting the substring into your float after reading the data?
Code: Select all
; LLLLLLLLLLLLLLLLLLLLLCCCYYYYYXXXXX
Data.s "Andorra la Vella1 0010425100151"
That approach would certainly get that job requirement done quickly by properly using the language as it exists, would it not?