|
-
Jul 26th, 2000, 01:18 PM
#1
Thread Starter
Addicted Member
What would be the best way to populate an array through a function or sub, without having to declare it as a global variable ?
Especially, I have run into trouble when I already have some data in the array and don't want to touch that part of it...
Any ideas ?
Thanks
-
Jul 26th, 2000, 01:23 PM
#2
transcendental analytic
Not sure what you meant, you can pass an array to a sub of any datatype, or you could pass it as a variant, but you can't pass arrays of UDT's as variant
Also use redim to change the size or your array, preserve will keep your old data..
Code:
SUb Yoursub (Array())
REdim preserve array(X)
End sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jul 26th, 2000, 01:36 PM
#3
Thread Starter
Addicted Member
Thanks... It's a little more complex than that... The array I am talking about holds Vriables of a User defined type. For example:
Code:
Type UserType1
Var1 As String
Var2 As Long
End Type
And my array holds variables of that type. Some of which already have data in 'Var1' and the sub will populate Var2...
The only solution to this might be global declarations, but I don't like using them...
-
Jul 26th, 2000, 01:47 PM
#4
Frenzied Member
Your signioture says you are using VB6
Arrays are no problem with VB 6
this works:
is this the sort of thing you want to do?
Code:
Option Explicit
Private Type UserType1
Var1 As String
Var2 As Long
End Type
Private Sub Command1_Click()
Dim MyVarArray(10) As UserType1
Dim i As Integer
FillVar2 MyVarArray()
FillVar1 MyVarArray()
For i = 0 To 10
Debug.Print MyVarArray(i).Var2
Debug.Print MyVarArray(i).Var1
Next i
End Sub
Private Sub FillVar2(varArray() As UserType1)
Dim i As Integer
For i = 0 To 10
varArray(i).Var2 = i
Next i
End Sub
Private Sub FillVar1(varArray() As UserType1)
Dim i As Integer
For i = 0 To 10
varArray(i).Var1 = "var1, element " & i
Next i
End Sub
-
Jul 26th, 2000, 02:07 PM
#5
transcendental analytic
That will also work with Vb5, it's just that you can't pass an array of UDT's as a variant, but i guess if FrancisC is happy with that, it's ok
Fox said that it should work with VB6, if you pass public variables in classes to public functions in a standard module, not sure though
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jul 26th, 2000, 02:09 PM
#6
Thread Starter
Addicted Member
That works fine... thanks !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|