Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save an array's values

Posted on 1999-07-04
28
Medium Priority
?
154 Views
Last Modified: 2010-05-02
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)
0
Comment
Question by:wadeg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 8
  • 3
  • +4
28 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1521861
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
 

Author Comment

by:wadeg
ID: 1521862
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1521863
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:wadeg
ID: 1521864
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
 

Author Comment

by:wadeg
ID: 1521865
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
 

Author Comment

by:wadeg
ID: 1521866
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
 

Author Comment

by:wadeg
ID: 1521867
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
 

Expert Comment

by:kzzm44
ID: 1521868
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
 

Expert Comment

by:Smout
ID: 1521869
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
 

Expert Comment

by:mirrorinternetzahavnet
ID: 1521870
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
 

Expert Comment

by:mirrorinternetzahavnet
ID: 1521871
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
 
LVL 1

Expert Comment

by:phiro
ID: 1521872
Wow! They have bugs at Experts! :)
0
 

Expert Comment

by:mirrorinternetzahavnet
ID: 1521873
Errr... Why is mirrorinternetzahavnet's name above my entry?
And why my name above the one comment I did not make...

PhiRo
0
 
LVL 1

Expert Comment

by:phiro
ID: 1521874
' #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
 
LVL 14

Accepted Solution

by:
waty earned 150 total points
ID: 1521875
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1521876
what's wrong with E-E??
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1521877
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
 

Author Comment

by:wadeg
ID: 1521878
Arrg! now the answer dissapeared on me!

Oh well I have some idea what direction to go!
0
 

Author Comment

by:wadeg
ID: 1521879
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1521880
they have the messages all messed up!

(who sent what)


0
 

Author Comment

by:wadeg
ID: 1521881
The answer was Waty's but it appeared under my name. Every message is moved up one position.
0
 
LVL 1

Expert Comment

by:phiro
ID: 1521882
Thanks as long as I do not have to parse a HUGE text file I am happy!
0
 

Author Comment

by:wadeg
ID: 1521883
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1521884
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
 

Author Comment

by:wadeg
ID: 1521885
wadeg, where the hell is his explanation??

-vik-
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1521886
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
 

Author Comment

by:wadeg
ID: 1521887
(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
 
LVL 10

Expert Comment

by:viktornet
ID: 1521888
It still will not work! (wadeg)

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

I am getting flustered!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question