sirbounty
asked on
variable array
How do I declare (and use) a variable array in vb.net?
It seems I have problems with code that worked in vb6:
Dim myStringArray() as string
ReDim myStringArray(whateverObje ct.Count)
Or, in a more 'real-world' case...
Dim strAccounts as string
[...]
ReDim strAccounts(myAdoRS.Record Count)
It seems I have problems with code that worked in vb6:
Dim myStringArray() as string
ReDim myStringArray(whateverObje
Or, in a more 'real-world' case...
Dim strAccounts as string
[...]
ReDim strAccounts(myAdoRS.Record
ASKER
Well, like I'm using this in a module: (this is 'upgraded' via the wizard code from vb6):
Public Function FindWindowLike(ByRef hWndArray() As Integer, ByVal hWndStart As Integer, ByRef WindowText As String, ByRef Classname As String) As Integer
and in my form...
Dim hWnds() As Integer
Dim cnt As Integer
cnt = FindWindowLike(hWnds, 0, "1.3*", "*")
and I get a green squiggley under hWnds:
Variable hWnds is passed by reference before it has been assigned a value. A null reference exception could result at run time.
Do I care? I'm just trying to find my window... :^)
Public Function FindWindowLike(ByRef hWndArray() As Integer, ByVal hWndStart As Integer, ByRef WindowText As String, ByRef Classname As String) As Integer
and in my form...
Dim hWnds() As Integer
Dim cnt As Integer
cnt = FindWindowLike(hWnds, 0, "1.3*", "*")
and I get a green squiggley under hWnds:
Variable hWnds is passed by reference before it has been assigned a value. A null reference exception could result at run time.
Do I care? I'm just trying to find my window... :^)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ReDim requires an array which the following statement is not
Dim strAccounts As String
so then this statement will fail
ReDim strAccounts(myAdoRS.Record
On the other hand this is fine as long as you do not need the data that was already in the array if any.
Dim myStringArray() as string
ReDim myStringArray(whateverObje
If you don't want to lose the data then use this form:
Dim myStringArray() as string
ReDim Preserve myStringArray(whateverObje
Also this should return an integer.
Fernando