Sign in to follow this  
Followers 0
Gene

Loading a file into a 2 dimensional Array

5 posts in this topic

Hi,

I need to load a file into a 2 dimensional Array. Is there an elegant way of doing this? It is now about [250] X [32], I can't see it ever being more than [5100] X [32].

The first dimension would be the record numbers and the second is for the field contents.

I've seen and used the UDF _FileReadToArray() and StringSplit(), but they both appear to be one dimensional. Is there a way to use StringSplit to populate the second dimension of an array?

OR

Is the best way to read the file into a variable and run 2 nested loops to populate the 2 dimensions of the array? I'd really like to use StringSplit() in the inside loop, but I don't quite see how to do it.

OR

Is there yet a better way?


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites



appear to be one dimensional.  Is there a way to use StringSplit to populate the second dimension of an array?

while 1 

  ; META Code
  ; $line FileReadLine()
  ; $temp = StringSplit($line, ":")
  ; $n = $n+1
  ; for $i = 1 to 32 
  ;  $array[$n][$i] = $temp[$i]
  ; next
wend

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

while 1 

  ; META Code
  ; $line FileReadLine()
  ; $temp = StringSplit($line, ":")
  ; $n = $n+1
  ; for $i = 1 to 32 
  ;     $array[$n][$i] = $temp[$i]
  ; next
wend

Cheers

Kurt

<{POST_SNAPBACK}>

Thanks, that is the 2 nested loops I mentioned except maybe a little slower due to file handling.

In the meantime, I've been reading about someone else's array problems. On thinking about it, maybe I should put the data in 32 one dimension arrays. They would all have the same index, could be named for the field they held. With one or more loops and using StringInStr() be able to search on one or more fields without having to sort them. For some reports I would have to sort, but there I could just sort the data set to be printed.

Does anyone have thoughts on that?


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Does anyone have thoughts on that?

<{POST_SNAPBACK}>

It all depends (don't you just hate it when people say that?).

If your data isn't formatted yet, you could try IniWrite and IniReadSection. They're nice and clean. As far as performance is concerned I don't know however. There is also another drawback (which doesn't apply to you); there can't be more than one copy of each key (i.e.: Key=Value).

Here's a sample .INI in case there's some confusion:

[sectionName]

1stParam = Hello

2ndParam = Goodbye

3rdParam = Bonjour

4thParam = AuRevoir

..

..

..

After reading with IniReadSection($A,"SectionName"), you get (example)

$A[0][0] = Size of array

$A[1][0] = 1stParam

$A[1][1] = Hello

$A[2][0] = 2ndParam

$A[2][1] = Goodbye

$A[3][0] = 3rdParam

$A[3][1] = Bonjour

$A[4][0] = 4thParam

$A[4][1] = AuRevoir

..

..

..

You might get a speed boost writing the INI file if you use FileWriteLine (and you're willing to insert section names yourself instead of having the program do it for you :))

Anyways this technique has been a winner for me; I was writing a multi-language program and wanted an easy way to insert into an array all translatable text.

Hope this helps!!!


I am endeavoring, ma'am, to construct a mnemonic circuit using stone knives and bearskins.SpockMy UDFs:Deleted - they were old and I'm lazy ... :)My utilities:Comment stripperPolicy lister 1.07AutoIT Speed Tester (new!)

Share this post


Link to post
Share on other sites

It all depends (don't you just hate it when people say that?).

If your data isn't formatted yet, you could try IniWrite and IniReadSection. They're nice and clean. As far as performance is concerned I don't know however. There is also another drawback (which doesn't apply to you); there can't be more than one copy of each key (i.e.: Key=Value).

You might get a speed boost writing the INI file if you use FileWriteLine (and you're willing to insert section names yourself instead of having the program do it for you :))

Anyways this technique has been a winner for me; I was writing a multi-language program and wanted an easy way to insert into an array all translatable text.

Hope this helps!!!

<{POST_SNAPBACK}>

Thanks for the response. I've used INI files a lot, I wouldn't want to use INI files for anything larger than trivial. I maintain the contact and directory information for a High School graduated class. Several of the fields are in effect MEMO fields. I'm currently doing it with MS Access. This year is our 40 year reunion. At some point I'm going to need to turn the data over to someone else. The odds of them having Word, Excel, Access or anything similar plus knowing how to use it is small. I need to come up with a small simple application that they can for forward with whether I'm here or not. I'd like it to be in VB, but I've always found it unfriendly, as well as the several VB books I've tried too. I've been using AutoIt for some time (off & on), console apps. I'm just starting to develop this, so far I only have notes, field definitions, code snippets and some thought on what the editing and reporting tabs should look like.

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0