enumerating an collection

Post your Gambas programming questions here.
Post Reply
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

enumerating an collection

Post by grayghost4 »

this code runs fine :

Dim Dict As New Collection
Dim Element As String

Dict["Blue"] = 3
Dict["Red"] = 1
Dict["Green"] = 2

For Each Element In Dict
Print Element;
Next

but if I substutite a json.Decode .... I get the results in the attachment
Attachments
Screenshot from 2018-12-21 23-31-14.png
Screenshot from 2018-12-21 23-31-14.png (70.08 KiB) Viewed 5155 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: enumerating an collection

Post by cogier »

Hi grayghost4,

Can you tell us what it is you are trying to achieve and please upload the 'conssendo_s.srm' file so we can see what you see.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: enumerating an collection

Post by grayghost4 »

thanks for the response.

I want to load the file from the disk, make modifications to it and then write it back to the disk. I can accomplish that without enumerating the file but when I write it back with Json.encode, the file is compressed without tabs and linefeeds. If I enumerate it to a string, or string[] then I can add tabs and line feeds where I want them, and write the string back to a file.

Also, I am learning the language and want to understand the commands and understand why that one does not work. It seems like that is a useful command to know.

I believe I found the problem ... the file I am working with has two collections within it.
So the first element is a collection and the second element is a string. So it will generate a type mismatch no matter what you try to assign it to. :(
Attachments
ConscendoS.zip
(4.66 KiB) Downloaded 388 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: enumerating an collection

Post by cogier »

I think that you can do what you want with a simpler edit structure.
I have taken your file opened it and split it by line, then created a new array without all the indentation. You can edit the data then replace the old data with the new. This leaves the indentation as it was.

I hope it helps.
Plane_data.tar.gz
(36.29 KiB) Downloaded 407 times
Post Reply