Save an array's values

I have created an multi dimendsional array!

What I want to do is save all the values in this array a restore them in the onload event. Is there any way to do this without writing all the values to a text file. then opening and parsing the text file in to on load event?

I am looking for a simple and fast way to do this without creating a huge text file.

this array will be very large!

dim myarray(40,50,25,5)
wadegAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
watyConnect With a Mentor Commented:
That's what I told you man... You MUST save it to a file, but those functions I gave you save the array as binary, and you don't have to parse it, do you understand that? I think you didn't understand how those functions works..

..-=ViKtOr=-..
0
 
viktornetCommented:
you can use

write #1, whatever
and
get#1, whatever

and whatever would be your array..

(not sure about the function's name, but it's something similar)

-vik-
0
 
wadegAuthor Commented:
I think I found what I am after...

savesetting
getsetting

I tested it in a loop and got it to work so I think I will do it that way.

this also enables me to just change and retrieve one record at a time.

If any one has a good reason why I should not use this method please let me know. or even tell me yes it is a good idea and why fo an easy 50 points!

I am sorry viktornet's but I was looking for a method that I do NOT have to write to a text file!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
viktornetCommented:
how do you wanna save your array if you dont wanna write to a file?!?! I don't see your point there... i'm quite interested in saving data without writing to a file... please teach me...
0
 
wadegAuthor Commented:
OK what I did still saves it but does not create a text file that I will have to open and parse to use

As I said I have a large multi dimensional array!

dim myarray(35,50,25,5)

this will hold 238,680 different values. I did not want to have to parse such a huge file each time my program loaded.

But I found the saveSetting And GetSetting commands

these are used most often to store values in a program so you can just pick up were you left off the next time you load the program.

the format is this

SaveSetting(AppName As String, Section As String, Key As String, Setting As String)

and

GetSetting(AppName As String, Section As String, Key As String, Default Value)

AppName is the name of the application or project
Section I just used the "UR" and it creates it for you
Key.. this is were I used my arrays index numbers with a | in between them

So myarray(11,22,15,1) I stored in the key "11|22|15|1" so when I use a loop to store an get my values from my array I can compare them to the old values with the getsetting statment

Here is my test code

First I wrote something simmilar that used savesetting to write the value tHE i used this to retieve it and compare it to the value that was stored there

keyp = tl(1) & "|" & tl(2)   my 1st and 2nd demensions
For x = 0 To 25
    For q = 0 To 4
       
    test = GetSetting("MY PROGRAM", "UR", keyp & "|" & x & "|" & q)
        If myarray(x, q) = test Then MsgBox (myarray(x, q))
       
    Next q
Next x

and it worked great and very fast!
0
 
wadegAuthor Commented:
OK what I did still saves it but does not create a text file that I will have to open and parse to use

As I said I have a large multi dimensional array!

dim myarray(35,50,25,5)

this will hold 238,680 different values. I did not want to have to parse such a huge file each time my program loaded.

But I found the saveSetting And GetSetting commands

these are used most often to store values in a program so you can just pick up were you left off the next time you load the program.

the format is this

SaveSetting(AppName As String, Section As String, Key As String, Setting As String)

and

GetSetting(AppName As String, Section As String, Key As String, Default Value)

AppName is the name of the application or project
Section I just used the "UR" and it creates it for you
Key.. this is were I used my arrays index numbers with a | in between them

So myarray(11,22,15,1) I stored in the key "11|22|15|1" so when I use a loop to store an get my values from my array I can compare them to the old values with the getsetting statment

Here is my test code

First I wrote something simmilar that used savesetting to write the value tHE i used this to retieve it and compare it to the value that was stored there

keyp = tl(1) & "|" & tl(2)   my 1st and 2nd demensions
For x = 0 To 25
    For q = 0 To 4
       
    test = GetSetting("MY PROGRAM", "UR", keyp & "|" & x & "|" & q)
        If myarray(x, q) = test Then MsgBox (myarray(x, q))
       
    Next q
Next x

and it worked great and very fast!
0
 
wadegAuthor Commented:
The reason I want to do this is my program measures change over time.

I need to be able to compare a new value to the value that it used to be! without creating a HUGE text file to parse!

this way I only store and get the specific set of values that I want to compare at any given time!
0
 
wadegAuthor Commented:
The reason I want to do this is my program measures change over time.

I need to be able to compare a new value to the value that it used to be! without creating a HUGE text file to parse!

this way I only store and get the specific set of values that I want to compare at any given time!
0
 
kzzm44Commented:
The SaveSetting function writes these values to the registry of your PC. GetSetting will retrieve these values. That's why there was no file created. Still I don't like using this method, because if you're changing your PC, you have to copy the registry, rather than a file.

kzzm44
0
 
SmoutCommented:
uhum, sorry for saying but the user won't like it that you store such a huge amaount of variables in the registry, it will only make his system less stable and slower...

it is east though :) (typically MS; just throw it in the registry)

do you want these variables when the program is already terminated, otherwise how about using modules; public declare your variable..
0
 
mirrorinternetzahavnetCommented:
I think the answer you rejected was exactly what you need!
It SAVES the whole array in a file with just one line of code and READS the whole file into array with one line of code. So you don't have to do any parsing and you don't have to write any loops. I didn't try it myself but I think it has to work even faster then your loops.
0
 
mirrorinternetzahavnetCommented:
Agreed. VictorNet gave the correct answer. You can load the file when needed and you can even choose to only load the parts of the array you need. The file you'd create is less than 1 Meg in size and that is not exacly huge in Windoze terms...
Filling the registry however with such amound of information can have unexpected results. Some systems protest when the registry sizes over a certain size, and an OS like NT will flatly refuse the save if you have no rights to alter the registry.

0
 
phiroCommented:
Wow! They have bugs at Experts! :)
0
 
mirrorinternetzahavnetCommented:
Errr... Why is mirrorinternetzahavnet's name above my entry?
And why my name above the one comment I did not make...

PhiRo
0
 
phiroCommented:
' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 4/05/99
' * Time             : 15:43
' **********************************************************************
' * Comments         : Save an array to a file
' *
' *
' **********************************************************************

Option Explicit
Private maArray() As String

Dim iFileNum   As Integer
Dim sOutput    As String

'Get a free file handle
iFileNum = FreeFile
Open App.Path & "\MyArray.txt" For Output As iFileNum

'Here we make use of this handy new
'method Join.
sOutput = Join(maArray, ";")

'Now we take the string returned to us
'by the Join method and write it to the file
Print #iFileNum, sOutput

Close iFileNum


' #VBIDEUtils#************************************************************
' * Programmer Name  : Waty Thierry
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : waty.thierry@usa.net
' * Date             : 4/05/99
' * Time             : 15:43
' **********************************************************************
' * Comments         : Read an array from a file
' *
' *
' **********************************************************************

Dim iFileNum As Integer
Dim sInput   As String
Dim iCounter As Integer

'Get a free file handle
iFileNum = FreeFile
Open App.Path & "\MyArray.txt" For Input As iFileNum

'We use the Line Input to read in an
'entire line into our string
Line Input #iFileNum, sInput

'This new Split function will take a string
'split it up, and return an array!
maArray = Split(sInput, ";")

Close iFileNum

'Now we loop through each item in the
'array and add it to our listbox
For iCounter = 0 To UBound(maArray)
   List1.AddItem maArray(iCounter)
Next

0
 
viktornetCommented:
what's wrong with E-E??
0
 
viktornetCommented:
Thanks that is what I am after.

A better description of what and how.

And thanks to all of you who added comments. and answering my question "Is there any reason I should not do this."

I figured it was way to easy.

I will see if I can get this method to work for me!

Thanks to viktornet for trying to answer it but for someone who has never don this before (Me) it was not very clear.

Is there any way I can give him some points anyway?
0
 
wadegAuthor Commented:
Arrg! now the answer dissapeared on me!

Oh well I have some idea what direction to go!
0
 
wadegAuthor Commented:
wadeg, as the guys have mentioend already it saves the array into the registry, and it is not a good idea to saves a couple of megs in your registry... the registry is only for settions and options, etc... (it is still saved to a file, but that's a different story...)... okay, i think my method would've worked the best... wish ya luck...

..-=ViKtOr=-..
0
 
viktornetCommented:
they have the messages all messed up!

(who sent what)


0
 
wadegAuthor Commented:
The answer was Waty's but it appeared under my name. Every message is moved up one position.
0
 
phiroCommented:
Thanks as long as I do not have to parse a HUGE text file I am happy!
0
 
wadegAuthor Commented:
hey guys, just so you know this is viktornet ;-))

If I gave the correct answer why didn't you accept my answer and did Waty's instead??

..-=ViKtOr=-..
0
 
viktornetCommented:
He described it better. (this is wadeg)

I will give you point if I can

just aswer my next question

"for viktornet"

You earned it anyway but so did waty
0
 
wadegAuthor Commented:
wadeg, where the hell is his explanation??

-vik-
0
 
viktornetCommented:
This is messed up. (this is wadeg)

He gave me reasons why not to use the regestry. as di all of you. and he explained what your solution does + gave me yet another way to do it. I gave Waty the points simply for the efort and a good explination. I will give you 50 points for the correct answer!

thanks all!
0
 
wadegAuthor Commented:
(this is viktornet)

wadeg, as you can see the binary explanation wasn't waty's, but was rather mine... it appeared to be his 'cuz of this messed up thread... and I think write and get were the easiest solutions you can get... a single line of code instead of dozens of those...

..-=ViKtOr=-..
0
 
viktornetCommented:
It still will not work! (wadeg)

I tried write and put and print nothing will just write the array!

I am getting flustered!
0
All Courses

From novice to tech pro — start learning today.