Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays into Reg

Status
Not open for further replies.

AdamWhitehouse

Programmer
Aug 7, 2000
34
0
0
GB
Looking for assistance in storing an array into the registry, eg:

Dim myarray(25) as Variant

for i = 1 to 20
myarray(i)=i*3
next

****savesetting*** hkey,path,myarray

this isnt actual code only an example of what i am trying to achieve, without having to save each element of the array seperately.

help appreciated .
 
Dim myarray(25) as Variant

for i = 1 to 20
myarray(i)=i*3
next

'/// loop through array's values...
for i = 1 to UBound(myarray)
****savesetting*** hkey,path,myarray(i)
next i



****savesetting*** hkey,path,myarray

------------------------
Hit any User to continue
 
ooops.. ignore the last ****savesetting*** hkey,path,myarray

------------------------
Hit any User to continue
 
Thanks for the reply but the problem I have is with the

****savesetting*** hkey,path,myarray

I can't find a Reg save for variants, ony strings, bytes etc,
and I cant convert my defined array into a string.
 
I may be missing the point here but..

'lets declare a string variable:
dim strArrayValue as String

'/// loop through array's values...
for i = 1 to UBound(myarray)

'pop the the array's variant value into a string..
strArrayValue = myarray(i)

'dump into registry..
****savesetting*** hkey,path,strArrayValue
next i

You can't populate the registry in one lump from the array, instead you have to take each element of the array and add it..

------------------------
Hit any User to continue
 
you can't save a variant to the registry and it stay a variant - by the looks of it - it will need to be a string
(I don't understand why you want a variant)

%, 2004
 
I don't understand it either.

Maybe this code could help you out. It doesn't save the array as an array (because I don't think you can (maybe someone like strongm or johnwm can comment on that)) but here is some code that will simplify the process of storing the array into a string format and reading it back out.

Code:
    Dim arrArray(25) As Variant
    Dim InputArray As Variant
    Dim LCV As Long
    
    'Init your array with values
    For LCV = LBound(arrArray) To UBound(arrArray)
        arrArray(LCV) = LCV * 3
    Next
    
    SaveSetting "ProjectName", "TestSection", "TestKey", Join(arrArray, "~")
    
    InputArray = Split(GetSetting("ProjectName", "TestSection", "TestKey"), "~")
    
    For LCV = LBound(InputArray) To UBound(InputArray)
        Debug.Print InputArray(LCV)
    Next

You'll first need to check to see if InputArray is an actual array or not. See Thread222-836312 for ideas on how to check that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top