Results 1 to 18 of 18

Thread: [RESOLVED] about array object variable

  1. #1

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

    Resolved [RESOLVED] about array object variable

    i'm trying build 1 variable array, that must be object type for saving the objects names...
    heres how i declare the variable:
    Code:
    Public ObjectsName() As Object
    Public NumberObjects As Long
    now i put some objects names in listbos(string, of course)...
    then i must put them in variable array(ObjectsName()) using the listcount property i redim the variable....
    heres the code:
    Code:
    NumberObjects = lstAddCollisionObject.ListCount
        ReDim ObjectsName(NumberObjects)
        For i = 0 To NumberObjects
            Set ObjectsName(i).Name = lstAddCollisionObject.List(i)
        Next i
    and heres how i will use it:
    Code:
    For i = 0 To NumberObjects
                    If Collision(extender.name, ObjectsName(i), ObjectsName(i)) = True Then
                        RaiseEvent Collision(ObjectsName(i))
                    End If
                Next i
    the collision() function only acept objects name(the arguments are objects)...
    note: these objects name are the objects that is puted in form, but the names are manualy declared...
    i recive errors... can anyone tell me what isn't right?
    thanks
    Last edited by joaquim; Aug 20th, 2008 at 05:23 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

  3. #3

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

    Re: about array object variable

    Quote Originally Posted by MartinLiss
    Please always tell us what the error is and where it happens.
    i'm so sorry... you have right...
    when i try save the values from a list to variable...
    heres some code:
    for declare the variable:
    Code:
    Public ObjectsName() As Object
    Public NumberObjects As Long
    here for put the values:
    Code:
    NumberObjects = lstAddCollisionObject.ListCount
        ReDim ObjectsName(NumberObjects)
        For i = 0 To NumberObjects
            Set ObjectsName(i).Name = lstAddCollisionObject.List(i)
        Next i
    and theres my error message:
    "Run-Time error '91':
    Object Variable or With block variable not set"
    i have a question:
    i can without a problem save the object names in array string variable... but can
    use them in argument Object(because here he must considered an object)?
    these is the function that i need to use with objects name:

    Collision(object1 as object, Object2 as object,optional strNameColision as string="") as boolean

    thanks
    Last edited by joaquim; Aug 20th, 2008 at 06:01 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

  5. #5

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

    Re: about array object variable

    Quote Originally Posted by MartinLiss
    Well the first problem is that a created object like ObjectsName doesn't have a Name property.
    yes that's true....
    i'm sorry, if i can't express very well....
    what i'm trying to do is saving the objects names in array, i can do these by using a string array... but the problem is how can i convert them to object name....
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6

  7. #7

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

    Re: about array object variable

    Quote Originally Posted by MartinLiss
    Without talking about objects, etc can you describe what you are trying to do?
    i'm trying build a object name list that is in form, by using an array variable...
    then i use that array to see if there is a collision betwen them(1 of them and other one(these one is always the same) by using the collision() function...
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8

  9. #9

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

    Re: about array object variable

    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...
    VB6 2D Sprite control

    To live is difficult, but we do it.

  10. #10

  11. #11
    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

  12. #12

  13. #13

    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.

  14. #14

    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.

  15. #15

  16. #16

    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.

  17. #17

  18. #18

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

    Re: [RESOLVED] about array object variable

    Quote Originally Posted by MartinLiss
    Yes you did, thank you.
    you welcome... thank you, i must say
    VB6 2D Sprite control

    To live is difficult, but we do it.

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