PDA

View Full Version : [SOLVED:] storing processed data



NIMANIMA50
09-13-2022, 10:45 PM
Hi

assuming that we have below sub that generate a 2d array.



sub test()
dim arr(1 to10, 1 to 10)

for i =1 to 10
arr(i,1)=i: arr(i,2)=2*i
next i

end sub


is it possible to store the arr() in the memory (something like data dump) and use it in other subs without calculating it again?

thanks

arnelgp
09-14-2022, 03:07 AM
make your array variable Public

public arr(1 to 10, 1 to 10) as Long

sub test()
...
...

snb
09-14-2022, 03:46 AM
Avoid public variables; use


Dim arr(9,9)

or


Private arr(9,9)

NIMANIMA50
09-14-2022, 08:31 PM
make your array variable Public

public arr(1 to 10, 1 to 10) as Long

sub test()
...
...


Thank you it works.Here is what i did :



Public arr(1 To 10, 1 To 10) As LongSub test()
For i = 1 To 10
arr(i, 1) = i: arr(i, 2) = 2 * i
Next i
End Sub





I was able to read the values of Arr from other subs.

NIMANIMA50
09-14-2022, 08:34 PM
Avoid public variables; use


Dim arr(9,9)

or


Private arr(9,9)

i tried this :


Private arr(1 To 10, 1 To 10) As Long
Sub test()
For i = 1 To 10
arr(i, 1) = i: arr(i, 2) = 2 * i
Next i
End Sub




but did not work, I can not read the values of Arr from other subs.
may I know why you recommended to avoid using Public variables?

snb
09-15-2022, 12:15 AM
You can't use the same variable name in another Macromodule.


Dim sn(9, 0)

Sub M_snb()
For j = 0 To 9
sn(j, 0) = j
Next

M_snb_002
End Sub

Sub M_snb_002()
MsgBox sn(4, 0)
End Sub

NIMANIMA50
09-15-2022, 01:12 AM
You can't use the same variable name in another Macromodule.


Dim sn(9, 0)

Sub M_snb()
For j = 0 To 9
sn(j, 0) = j
Next

M_snb_002
End Sub

Sub M_snb_002()
MsgBox sn(4, 0)
End Sub

in your method i can only use the array while the main module is running (in your example "sub M_snb()".
i prefer @arnelgp (http://www.vbaexpress.com/forum/member.php?74556-arnelgp) method as it will give me the possibility of using the array even if the main module is done running.

NIMANIMA50
09-15-2022, 04:07 AM
You don't understand the structure of a VBA project.
Please master VBA fundamentals first.

i agree that i dont know many things about VBA.That is the reason Im posting my questions here so people with good understanding about VBA enlighten me.
but your suggestions to my question ,as a person that understand structure of a VBA project, does not solve my problem.
if you think i am not applying your method properly, please let me know how it should be done. Thanks

georgiboy
09-15-2022, 04:46 AM
You don't understand the structure of a VBA project.
Please master VBA fundamentals first.

Your attitude towards people trying to learn VBA stinks

Not sure if anything is lost in translation but it needs to be remembered that people come here to learn (as I did), your messages quite often come across as someone who is on a high horse.

You could also argue that your explanations are sub standard.

Moderators can delete my account if this is a problem, I have had enough of the clique here that support such people.

snb
09-15-2022, 05:10 AM
in your method i can only use the array while the main module is running (in your example "sub M_snb()".

This is not a question, but a statement.
That statement can only based on .....
The best advice to give I gave you.