Results 1 to 18 of 18

Thread: [RESOLVED] about array object variable

Hybrid View

  1. #1
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: about array object variable

    Quote Originally Posted by joaquim
    Quote Originally Posted by MartinLiss
    What type of objects are they?
    in these case doesn't metter, because that function only use the position and size of objects... that every objects use the same properties...
    Yes, it does matter.

    Your Collision() function required an object argument, that can be any type of object but it must be an actual object (such as PictureBox, etc), it cannot be a dummy un-set object.

    Your code below does not work by many reasons:
    Code:
    Public ObjectsName() As Object
    Public NumberObjects As Long
    
    ... ...
    
        NumberObjects = lstAddCollisionObject.ListCount
        ReDim ObjectsName(NumberObjects)
        For i = 0 To NumberObjects
            Set ObjectsName(i).Name = lstAddCollisionObject.List(i)
        Next i
    In statement: Set something1 = something2
    both something1 and something2 must be some kind of objects, not strings.

    With 2 strings, you cannot use
    Set string1 = string2
    but just simply
    string1 = string2

    Before you can use Object1.Name, Object1 need to be Set to some actual object,
    otherwise you get error message "Object Variable or With block variable not set".

    So, you need to have something like this:
    Code:
        ReDim ObjectsName(NumberObjects)
        For i = 0 To NumberObjects
            Set ObjectsName(i) = myPicture(i) '-- make sure myPicture(i) already existed
            ObjectsName(i).Name = lstAddCollisionObject.List(i)
            '-- noted that after the above line, myPicture(i).Name will be 
            '-- also changed to the same as ObjectsName(i).Name
        Next i
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  2. #2

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about array object variable

    ok i resolve my problem(at least i think), but i have a little problem....
    heres the code:
    Code:
    Public ObjectsName() As String
    Public NumberObjects As Long
    
    Private Sub UserControl_Show()
        blnShow = True
        ReDim ObjectsName(Extender.Parent.Controls.Count)
        NumberObjects = Extender.Parent.Controls.Count - 1
        For i = 0 To Extender.Parent.Controls.Count - 1
            ObjectsName(i) = Extender.Parent.Controls(i).Name
            MsgBox ObjectsName(i)
        Next i
    end sub
    
    Private Sub PropertyPage_ApplyChanges()
        NumberObjects = 0
        For i = 0 To lstAddCollisionObject.ListCount - 1
            If lstAddCollisionObject.Selected(i) = True Then NumberObjects = NumberObjects + 1
        Next i
        ReDim ObjectsName(NumberObjects)
        For i = 0 To lstAddCollisionObject.ListCount - 1
            If lstAddCollisionObject.Selected(i) = True Then ObjectsName(i) = lstAddCollisionObject.List(i)
        Next i
        For i = 0 To NumberObjects
            MsgBox ObjectsName(i)
        Next i
    end sub
    my list box is with check style activated(is why i use selected property, for see if was checked or not)
    but here i have a little problem...
    i recive an message box empty... can you explain to me why?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: about array object variable

    ok... resolved, thanks
    Code:
    Dim RealName As String
    
    RealName = Extender.Name
                For i = 0 To Extender.Container.Controls.Count - 1
                    If Extender.Container.Controls(i).Name <> RealName Then
                        If Collision(Extender, Extender.Container.Controls(i)) = True Then
                            RaiseEvent Collision(Extender.Container.Controls(i).Name & IFF(Extender.Container.Controls(i).TabIndex <> 0, Extender.Container.Controls(i).TabIndex, ""))
                        End If
                    End If
                Next i
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [RESOLVED] about array object variable

    Quote Originally Posted by MartinLiss
    Please don't forget to pull down the Thread Tools menu and click the Mark Thread Resolved button..
    yes i did... thanks for everything thanks...
    thanks anhn... thanks for help me too...
    PS: did i rate you, MartinLiss?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7

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