Results 1 to 21 of 21

Thread: adding to the end of a variant derived array

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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"
        
    %>

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  4. #4

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    On what line? By the way are you using VB6 (InterDev6) ???

  6. #6

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Works for me...
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  9. #9

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  10. #10
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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,

  11. #11

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  12. #12
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    '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

  13. #13

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  16. #16

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  17. #17

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  18. #18
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  19. #19
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  20. #20

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  21. #21
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
  •  



Click Here to Expand Forum to Full Width