|
-
Aug 20th, 2008, 05:12 PM
#1
Thread Starter
PowerPoster
[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.
-
Aug 20th, 2008, 05:33 PM
#2
Re: about array object variable
Please always tell us what the error is and where it happens.
-
Aug 20th, 2008, 05:55 PM
#3
Thread Starter
PowerPoster
Re: about array object variable
 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.
-
Aug 20th, 2008, 06:02 PM
#4
Re: about array object variable
Well the first problem is that a created object like ObjectsName doesn't have a Name property.
-
Aug 20th, 2008, 06:06 PM
#5
Thread Starter
PowerPoster
Re: about array object variable
 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....
-
Aug 20th, 2008, 06:12 PM
#6
Re: about array object variable
Without talking about objects, etc can you describe what you are trying to do?
-
Aug 20th, 2008, 06:16 PM
#7
Thread Starter
PowerPoster
Re: about array object variable
 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
-
Aug 20th, 2008, 06:18 PM
#8
Re: about array object variable
What type of objects are they?
-
Aug 20th, 2008, 06:22 PM
#9
Thread Starter
PowerPoster
Re: about array object variable
 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...
-
Aug 20th, 2008, 07:03 PM
#10
Re: about array object variable
Well if the object is a control of some type then you could use a control array and store whatever "name" you want it to have in the control's Tag property.
-
Aug 20th, 2008, 07:25 PM
#11
Re: about array object variable
 Originally Posted by joaquim
 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
-
Aug 20th, 2008, 07:32 PM
#12
Re: about array object variable
Or as I suggested
Code:
ReDim ObjectsName(NumberObjects)
For i = 0 To NumberObjects
myPicture(i).Tag= lstAddCollisionObject.List(i)
Next i
-
Aug 21st, 2008, 07:05 AM
#13
Thread Starter
PowerPoster
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
-
Aug 23rd, 2008, 12:02 PM
#14
Thread Starter
PowerPoster
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
-
Aug 23rd, 2008, 12:04 PM
#15
Re: [RESOLVED] about array object variable
Please don't forget to pull down the Thread Tools menu and click the Mark Thread Resolved button..
-
Aug 23rd, 2008, 12:08 PM
#16
Thread Starter
PowerPoster
Re: [RESOLVED] about array object variable
 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?
-
Aug 23rd, 2008, 12:11 PM
#17
Re: [RESOLVED] about array object variable
-
Aug 23rd, 2008, 12:12 PM
#18
Thread Starter
PowerPoster
Re: [RESOLVED] about array object variable
 Originally Posted by MartinLiss
Yes you did, thank you.
you welcome... thank you, i must say
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
|