|
-
Aug 28th, 2001, 10:14 AM
#1
Thread Starter
Addicted Member
Array Problem
I have an array that has NOTHING in it.
When I msgbox for the lbound and the ubound it gives a subscript out of range error.
I am trying to store information in it without useing the Array function because it would delete the other information that is already in the array. I tryed:
ReDim Preserve rvar(LBound(Owned) To (UBound(Owned) + 1))
but it gave me a subscript out of range error. how could I do this?
Using:
Visual Studio .Net Enterprise
Visual Basic 6.0 Enterprise
-
Aug 28th, 2001, 10:18 AM
#2
Frenzied Member
I dont know what the value of the Nothing constant really is, but it may be -1 or something, so the array can't accept it as an element number. Do this:
VB Code:
Dim x() As Long
ReDim x(0)
and then do redim preserve or whatever you want.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 10:22 AM
#3
Frenzied Member
BTW theres no point of doing:
VB Code:
ReDim Preserve x(LBound(x) To UBound(x) + 1)
Just do:[/Highlight]
ReDim Preserve x(0 To UBound(x) + 1)
[/Highlight]
Cause you cant change the LBound anyways.
You just proved that sig advertisements work.
-
Aug 28th, 2001, 10:53 AM
#4
Hyperactive Member
Code:
Dim I as long
On error resume next
I = UBound(emptryarray)
if Err.Number <> 0 then I = -1
On error goto 0
if i < 0 then ' No items
An alternativ is what I use. I do not use element 0 therefore I always define my dynamic arrays as
Code:
Dim aryDynamic() as string
Redim aryDynamic(0) ' Define empty
Dim lngCurrI as long ' current "Filled" element
'.........
' put into array
lngCurrI = lngCurrI + 1 ' advance to next element
If lngCurr > ubound(aryDynamic) then ' check fo xpand needed
Redim preserve aryDynamic (lngcurrI * 1.1 + 1) ' I prefer * 2
' becaus it only costs 4 bytes per empty element
End if
aryDynamic(lngCurrI) = somedata
'........
' Resize when finished filling
Redim Preserve aryDynamic(lngCurrI)
Now I can send th array anywhere even with "no" items because UBOUND(aryDynamic will always work and shoot right thru
For I = 1 to Ubound(aryDynamic)
'.....
Next
-
Aug 28th, 2001, 11:24 AM
#5
Addicted Member
You can only Redim Preserve the the upper bound of the last dimension in the array. Additionally when you use:
VB Code:
Private Sub Form_Load()
ReDim s(0) As String
s(0) = "a"
End Sub
You are actually creating an array with 1 bucket in it.
Use:
VB Code:
Private Sub Form_Load()
Dim s() As String
Erase s
End Sub
This will create a true empty array...
poooof
Wizard Since 1997    
SQL Server 7.0:2K, Oracle, VB 6.0 EE, VBScript, C/C++, COBOL, RPG ILE, HTML, XML, Perl
-
Aug 28th, 2001, 12:48 PM
#6
Frenzied Member
*Must excersice patience with people who dont read thread*
Try this instead:
VB Code:
Dim x() As Variant
ReDim x(0)
ReDim Preserve x(0 To UBound(x) + 1)
You just proved that sig advertisements work.
-
Aug 28th, 2001, 12:49 PM
#7
Frenzied Member
Originally posted by Frankie902
Dim x As Variant
ReDim Preserve x(0 To UBound(Owned) + 1)
When I use that I get type mismatch
If this is the exact code your using, then whya re u doing UBound(Owned) instead of UBound(x)??
You just proved that sig advertisements work.
-
Aug 28th, 2001, 12:54 PM
#8
Thread Starter
Addicted Member
THe original array is Owned
but I am putting it in X and then putting x into Owned
Using:
Visual Studio .Net Enterprise
Visual Basic 6.0 Enterprise
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
|