Help with pointing to variable

homer2002

Registered User.
Local time
Today, 20:57
Joined
Aug 27, 2002
Messages
152
i am trying to write a little procedure that redims a variable.
I need this procedure to take a variable name and then use that to redim the variable to somthing usefull



e.g.

______________________________________________

sub RedimTheVariable(VariabletoBeRidimmed as ?????)
redim preserve variableToBeRedimmed(1 to 50)
end sub


sub cmdAButton_Click
Dim AVariable() as string
RedimtheVariable(AVariable)
end sub

______________________________________________

the function does a couple of other things too, but I need to be able to point to the variable so I can use my procedure across difference projects.


thanks

____\o/_______ HELP ~~~ME ~~~~
 
I think you may have got lost somewhere as to why you would ReDim and Preserve a variable.

Can you give more information about what you are trying to do, maybe suggesting a possible example?
 
ok heres an insight

i'm writing a little sub that will allow me to make a multi select list box, click on some values and then pass these out to an array.


because I want to keep my code nice and neat i want to redim an array to the right size (amount of values selected),

e.g if I select 3 things the array is (1 TO 3)


i have a function that steps through the selected items and enters them into an array so I can use them elsewhere.


This function works fine, but it would work better if I could pass a variable (array) name into it & the name of the list box


then I could use it as a nice little module for any list box like this


Dim AnyOldArray()
RipOutSelected(NameOfListBox,Variable to return values to)


I guess i could use a function, but I don't know how to pass back an array, if thats simple, then it's probably better although I would still like to be able to pass in the name of the list box.

then I could use



Dim AnyOldArray() as string '
AnyOldArray() = GetSelectedItems(NameOfListBox)
.....
and get back somthing like
AnyOldArray(1) = "Somthing that was selected"
AnyOldArray(2) - 'Something else that was selected"

maybe my code will help explain
_______________________________________________
Private Sub RipSelected() 'Would like to pass in NameOfListBox & NameOfVariable
Dim varitem As Variant
Dim SizeOfArray As Integer
Dim ctl As Control
Set NameOfForm = Me
Set ctl = Me!LSTtEST
SizeOfArray = 0
For Each varitem In ctl.ItemsSelected
SizeOfArray = SizeOfArray + 1
ReDim Preserve TempArray(1 To SizeOfArray)
TempArray(SizeOfArray) = ctl.ItemData(varitem)
Next varitem
'Would like to return TempArray
End Sub


Private Sub cmdTest_Click()
Dim SelectedItems() As String
SelectedItems = RipSelected ' Would like to pass in NameOfListBox & NameOfVariable
End Sub


________________________________

Hope you can help :-) cheers
 
Last edited:

Users who are viewing this thread

Back
Top Bottom