|
-
Nov 5th, 2000, 06:34 PM
#1
Say I split a string(strTemp) into 5 parts as myStuff(a variant. So now I have myStuff(0 to 4), right? Is there a way to add on a myStuff(5) to the end?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 06:53 PM
#2
Sure thing. Here's a little example:
Code:
<%
Dim strTemp
Dim arrTemp
strTemp = "s'f'd'g'f"
arrTemp = Split(strTemp, "'")
'Add new element to the array
ReDim Preserve arrTemp(UBound(arrTemp) + 1)
arrTemp(UBound(arrTemp)) = "My New String"
%>
-
Nov 5th, 2000, 06:54 PM
#3
fantastic
knew there had to be a way, thanx!
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 06:59 PM
#4
whoa, whoa, whoa!
An error says "Method or Data Member not found", what's up with that?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 07:11 PM
#5
On what line? By the way are you using VB6 (InterDev6) ???
-
Nov 5th, 2000, 07:21 PM
#6
VB hightlights "ReDim Preserve myStuff" then the (UBound...
is left alone. I'm using VB6.0 Enterprise Edition.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 07:22 PM
#7
_______
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 5th, 2000, 07:29 PM
#8
transcendental analytic
You get that error when you try to redim a listbox right? (this is just a guess) Serge's code works only for arrays.
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.
-
Nov 5th, 2000, 08:07 PM
#9
no, I used it to redim an array. Here's the thing:
Code:
Private Sub Combo1_LostFocus()
For x = 0 to Combo1.ListCount - 1
If(Combo1.Text = Combo1.List(x)) Then
matchFound = True
End If
Next x
if(matchFound = True) Then
Redim Preserve myStuff(UBound(myStuff) + 1)
myStuff(UBound(mystuff)) = "Whatever"
End If
End Sub
when the combobox loses focus, the error comes up
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 08:29 PM
#10
I think I know what the problem is. I think the array is not populated at all. So, of course, the line on Ubound will fail. Try checking if the array is dimmensioned before:
Code:
If(matchFound = True) Then
On Error Resume Next
'This line will be true if array is populated
If IsNumeric(UBound(myStuff)) Then
Redim Preserve myStuff(UBound(myStuff) + 1)
Else 'Otherwise redim your array with the first element
Redim Preserve myStuff(0)
End If
myStuff(UBound(mystuff)) = "Whatever"
End If
Regards,
-
Nov 5th, 2000, 08:35 PM
#11
alright, wait, let's take two steps back.
Does the redim approach have to be used on something dimmed as an array, because I'm doing it on a variant that becomes an array.
BTW - The array is populated to start.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 08:36 PM
#12
_______
<?>
'try it this way
[code]
Option Explicit
Option Compare Text
Public mystuff
Private Sub Combo1_LostFocus()
Dim x As Integer, matchFound As Boolean
For x = 0 To Combo1.ListCount - 1
If (Combo1.Text = Combo1.List(x)) Then
matchFound = True
End If
Next x
If (matchFound = True) Then
ReDim Preserve mystuff(UBound(mystuff) + 1)
mystuff(UBound(mystuff)) = "Whatever"
MsgBox mystuff(5)
End If
End Sub
Private Sub Form_Load()
Dim strTemp
Dim i As Integer
strTemp = "s'f'd'g'f"
mystuff = Split(strTemp, "'")
For i = LBound(mystuff) To UBound(mystuff)
Combo1.AddItem mystuff(i)
Next i
Combo1.ListIndex = 1
End Sub
[code]
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 5th, 2000, 08:50 PM
#13
That one worked HeSaidJoe, now let me ask, can the variant be public on another form, or does it need to be dimmed on the form that its used?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 08:52 PM
#14
transcendental analytic
ubound failure causes subscript out of range, serge, theres no way to avoid or check it but error handling
I think there's another possiblity, crptcblade, you have a class or standard module called mystuff, that would make the call ambigous, and it prefers the classname instead
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.
-
Nov 5th, 2000, 08:54 PM
#15
transcendental analytic
Yes the variant can be public on another form, but you have to call it by Formname.Mystuff
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.
-
Nov 5th, 2000, 08:54 PM
#16
sorry, kedaman, that's not an issue
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 08:56 PM
#17
the above post wasn't for your last post, kedaman, and I did use the format : formName.MyStuff
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 09:08 PM
#18
transcendental analytic
Hmm, is it really public?
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.
-
Nov 5th, 2000, 09:14 PM
#19
transcendental analytic
eh sorry, now i get the problem!
What vb does is creates a property of the public variant, that means you can't use functions and statements like redim as it would be a variable, it's not, it's a propety.
What you need to do is store the variable in a temporray variant, redim that, and pass it back to the form
hope it works now
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.
-
Nov 5th, 2000, 09:19 PM
#20
cool, I'll give it a shot
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 5th, 2000, 09:38 PM
#21
_______
<?>
Sorry, was off watching my Leafs clobber the Bruings.
If you make it public in a bas module it works.
ie.
if you have Public myStuff in a bas module
and then do your stuff on form1 and then open form2
and msgbox mystuff(5) you will get whatever.
Later.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|