-
Sep 5th, 2007, 09:57 AM
#1
Thread Starter
Fanatic Member
array object limit?
is there a limit to how many objects can be in an array? i'm thinking that variable arrays will be able to hold more than object arrays, does anyone know the limits for object arrays and variable arrays?
-
Sep 5th, 2007, 10:10 AM
#2
Re: array object limit?
It might be limited by the available memory.
-
Sep 5th, 2007, 10:12 AM
#3
Thread Starter
Fanatic Member
Re: array object limit?
yes, but is there a definite limit, particularly for objects on the form?
-
Sep 5th, 2007, 10:18 AM
#4
Re: array object limit?
I think the limit is 32768 (2^15), since the index is of Integer data type...
-
Sep 5th, 2007, 10:23 AM
#5
Re: array object limit?
No, ordinary array can hold much more than that:
Code:
Private Sub Command1_Click()
Dim arTest() As Integer
ReDim arTest(400000)
Debug.Print UBound(arTest)
End Sub
However, to answer the "limitation" question - if kilo is asking about the max number of control on a single form then it's limited to 256 unique names (note: not controls).
That means that can you have 256 unique control arrays holding each 256 members.
If you however don't use control array then it can only be 256 controls because each of them will have unique name.
Limitation is there but it's rather difficult to overcome.
MSDN for some reason says 254 unique names. So one of us is wrong.
Last edited by RhinoBull; Sep 5th, 2007 at 10:30 AM.
-
Sep 5th, 2007, 10:32 AM
#6
Re: array object limit?
Originally Posted by RhinoBull
No, ordinary array can hold much more than that:
Not for "objects on the form"....
Originally Posted by killo
yes, but is there a definite limit, particularly for objects on the form?
-
Sep 5th, 2007, 10:48 AM
#7
Re: array object limit?
Well, "Array of Something" is different from "Control Array" so if we are talking about ordinary arrays regardless of its type then it's limited by the available memory.
if control arrays then read my previous post.
-
Sep 5th, 2007, 11:12 AM
#8
Thread Starter
Fanatic Member
Re: array object limit?
that makes sense, my project goes funny around the time it would have loaded 256 shapes, because i'm using a shape array, a new shape gets loaded onto the form every now and then
ok so i'm making a way to get around this, basically it's:
s1 = s1 + 1
if s1 > 100 then s1 = 0
Load Shape1(s1)
'toy around with the properties of shape1
but when it loops back round to s1 = 0 then the compiler starts whining something about trying to load a shape thats already loaded.
is there a way to detect if the shape is already loaded so that if it is i can unload it?
Last edited by killo; Sep 5th, 2007 at 11:17 AM.
-
Sep 5th, 2007, 11:24 AM
#9
Re: array object limit?
You may create a few control arrays of shapes in design (as many as you think should make sense)
and during runtime add members to one array at the time until it reaches certain number (like 200 or so) and then continue with another array...
But what do you do that needs that many shapes?
-
Sep 5th, 2007, 11:29 AM
#10
Re: array object limit?
If I were you, I would just draw all the shapes through code on a Picture Box.
I don't like shapes anyways becuse it causes too much flickering when moving the shapes, and if you have that many shapes, I can only imagine the mess...
-
Sep 5th, 2007, 11:39 AM
#11
Re: array object limit?
Drawing can cause even more flickering then creating control.
But you need to try it out either approach to see which one works better [for you].
-
Sep 5th, 2007, 11:49 AM
#12
Thread Starter
Fanatic Member
Re: array object limit?
basically it's like a thing where shapes come up when you press the keys to the beat of the song and the shapes come across the screen, like those dance mat things where you have to press the arrows in time with the music, its quite similar to guitar hero and it uses loads of shapes especially when playing the 9+ minute long songs by dragonforce with really fast solos.
cvmichael: the shapes don't flicker much at all and it would take loads of recoding to change it to the picture box method you mentioned. there isn't any mess either because the shapes go upwards and eventually dissapear off the top of the form, at which time i stop them from moving to conserve resources.
by the time i have used 100 shapes the first one will have certainly dissapeared off the top of the form so i would like to go back to the first one and start from that one again using the method i mentioned earlier
rhinobull: i wouldn't know how many arrays to make because i don't know how many shapes its going to use and i cant be bothered to go through the process of switching to the next array when one is done.
isn't there a simple line of code to check if a shape is already loaded or not?
Last edited by killo; Sep 5th, 2007 at 11:58 AM.
-
Sep 5th, 2007, 11:56 AM
#13
Re: array object limit?
In that case as Michael suggested draw your shapes directly.
-
Sep 5th, 2007, 12:06 PM
#14
Thread Starter
Fanatic Member
Re: array object limit?
i want to do it this way because this would only involve changing a bit of mmy code whereas doing it the way michael said would mean i would have to completely recode my project
i'm loading new shapes:
Load Shape1(s1)
then adding 1 to s1 so that it loads the next one next time, and once s1 gets to 100 i want to go back and load shape1(0) but the compiler complains because i'm trying to load it when its already loaded,
i just need a simple piece of code thats the equivalent of this:
if shape1(s1) is already loaded then unload shape1(s1)
just one piece of code that checks if the shape is already loaded, does this exist!?
-
Sep 5th, 2007, 12:07 PM
#15
Re: array object limit?
Try this very quick sample - start pressing any key when you run it:
Code:
Option Explicit
Private Sub Form_Load()
Me.AutoRedraw = True
Randomize
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim R%, G%, B%, myColor
Dim X As Integer, Y As Integer
R = Int((254 * Rnd) + 1)
G = Int((254 * Rnd) + 1)
B = Int((254 * Rnd) + 1)
myColor = RGB(R, G, B)
X = Int((Me.ScaleWidth * Rnd) + 1)
Y = Int((Me.ScaleHeight * Rnd) + 1)
Me.ForeColor = myColor
Me.DrawStyle = 0 'solid
Me.FillColor = myColor
Me.FillStyle = 0 'solid
Me.Circle (X, Y), 300, myColor
End Sub
You may also make so actual shape is random: circle (as shown) or square, etc...
-
Sep 5th, 2007, 12:11 PM
#16
Thread Starter
Fanatic Member
Re: array object limit?
i appreciate you typing that out for me but it would take a very long time to implement that into my project.
all i want to know is; is there a piece of code that checks if a shape is already loaded!?
-
Sep 5th, 2007, 12:17 PM
#17
-
Sep 5th, 2007, 12:52 PM
#18
Thread Starter
Fanatic Member
-
Sep 5th, 2007, 01:26 PM
#19
Re: array object limit?
Did that link help you? I don't see how it avoids a runtime error.
I'd just suppress the runtime error when you load:
Code:
On Error Resume Next
Load Shape1(s1)
On Error Goto 0
Nothing else needs to change.
-
Sep 5th, 2007, 01:41 PM
#20
Re: array object limit?
@Ellis: it's often necessary to delete some member of control array which isn't necessary the last one.
So, using check for existance (could also be done in the loop) using TypeName function may let you "fill the blanks".
It is also much better way to handle control array than "Resume Next" or "GoTo 0".
-
Sep 5th, 2007, 01:42 PM
#21
Re: array object limit?
Originally Posted by RhinoBull
@Ellis: it's often necessary to delete some member of control array which isn't necessary the last one.
So, using check for existance (could also be done in the loop) using TypeName function may let you "fill the blanks".
It is also much better way to handle control array than "On Error ...".
I honestly don't see how. Could you give an example?
EDIT: I created a textbox control array with three textboxes: 0, 1, 3. My debug results:
?TypeName(Text1)
Object
?TypeName(Text1(0))
TextBox
?TypeName(Text1(1))
TextBox
?TypeName(Text1(2))
TextBox
?TypeName(Text1(3))
TextBox
?TypeName(Text1(4))
TextBox
It's telling me textbox regardless of whether that index references a member of the control array or not.
I'm confused.
Last edited by Ellis Dee; Sep 5th, 2007 at 01:45 PM.
-
Sep 5th, 2007, 01:43 PM
#22
Re: array object limit?
If in your opinion "Resume Next" or "GoTo 0" is a good way to handle things then we have nothing further to discuss.
-
Sep 5th, 2007, 01:46 PM
#23
Re: array object limit?
We do have something further to discuss because I don't understand how the linked method works and would like you to explain.
-
Sep 5th, 2007, 02:40 PM
#24
Re: array object limit?
Alright...
Randy's sample demonstrates how to determine whether or not control with say name Text1 is part of control array.
To determine whether or not particular control is a member of that array sample needs to be expanded a bit:
Code:
'--------------------------------------------------------------------------------------------
'To run this sample do the following first:
' - add a textbox to your form
' - copy the new textbox and paste it onto the same form
' - when asked if "you want to create control array?" click YES
' - repeat this a few times so you create 4-5 instances of a textbox
' - delete at least one instance with index = 2 (basically any textbox but NOT first or last)
' - when ready copy/paste this code (and the function above) into the form, and run it
'--------------------------------------------------------------------------------------------
Option Explicit
Public Function ControlExists(Name As String, Index As Integer) As Boolean
Dim ctl As Control
Dim blnExist As Boolean
blnExist = False
For Each ctl In Me.Controls
'determine if it's a control array
If ctl.Name = Name And TypeName(Me.Controls(Name)) = "Object" Then
'it is so try to find match on index
If ctl.Index = Index Then
'match found - exit
blnExist = True
Exit For
End If
End If
Next ctl
ControlExists = blnExist
End Function
'sample usage:
Private Sub Command1_Click()
Dim i As Integer
'find and create missing members (it should be 1 and 3 in this example)
For i = Text1.LBound To Text1.UBound
If Not ControlExists("Text1", i) Then
Debug.Print "Text(" & i & ") does not exist."
Load Text1(i)
Text1(i).Move Text1(i - 1).Left, Text1(i - 1).Top + Text1(i - 1).Height + 120
Text1(i).Text = "Text1(" & i & ")"
Text1(i).Visible = True
End If
Next i
End Sub
All you had to do was improvise a little.
Last edited by RhinoBull; Sep 9th, 2007 at 07:28 PM.
-
Sep 5th, 2007, 07:17 PM
#25
Re: array object limit?
Very clever. I can't test that right now, but it looks like it should work nicely. Thanks much.
-
Sep 5th, 2007, 07:20 PM
#26
-
Sep 10th, 2007, 10:53 AM
#27
Thread Starter
Fanatic Member
Re: array object limit?
i was having trouble the way i was doing it which was moving the shapes up the form
so i changed the program to the way which rhinobull suggested (yes i know, you were right, i'm sorry) which was to move the shapes in a picturebox, but now while they're moving up, if i drag the form then it totally messes up.
the program records what time you press the keys at when it's "recording" then when it's "playing" it simulates someone pressing teh keys by running the same code as the keydown event at the times recorded
it only messes up when playing when i drag it but i have copied EXACTLY the same code from the keydown and key up events into the player except for the recording parts so i don't knowwhy it's doing this to me
heres my code:
Code:
in the keydown event of the player:
ReDim Preserve square1(0 To (UBound(square1) + 1)) As Shape
Set square1(UBound(square1)) = Me.Controls.Add("VB.Shape", "square1" & (UBound(square1)))
Set square1(UBound(square1)).Container = Picture1
With square1(UBound(square1))
.Top = 2520
.Height = 15
.Left = 3270
.Width = 435
.Tag = 1
.Visible = True
.BackColor = &HFFFF00
.BackStyle = 1
End With
in the key up event of the player:
square1(UBound(square1)).Tag = 0
in a timer:
For i = 0 To UBound(square1)
If square1(i).Top > -100 - square1(i).Height Then square1(i).Top = square1(i).Top - 100
If square1(i).Tag = "1" Then If 2520 - square1(i).Top > 0 Then square1(i).Height = 2520 - square1(i).Top
Next i
the shapes still move upwards after i have dragged it so i don't think it's the timer
but no new shapes are made after that so hmm...
EDIT:
ok now it's getting very sensitive, when my screensaver comes on, it messes it up. also someone just signed in on msn and that little box thing popped up saying blahblah has just signed in and THAT MESSED IT UP! i mean OMG what the hell!!!!!????
Last edited by killo; Sep 10th, 2007 at 11:05 AM.
-
Sep 11th, 2007, 01:48 AM
#28
Thread Starter
Fanatic Member
Re: array object limit?
i figured it out now, when people sign in to msn etc it uses the cpu and the shapes get out of sync, also when theres lots of shapes on there it goes really jumpy and uses like 99% of cpu or something, theres only around 20 shapes on the screen and my computer is quite fast. i don't know how my computer can display counter strike as fast as it does when it can't move a few stupid shapes across the screen!
is there any faster way to do this?
-
Sep 11th, 2007, 07:44 AM
#29
Re: array object limit?
That's because when you use shapes, the computer re-draws the screen every time you move/draw each shape instead once at the end.
What I mean is: lets say you moved 3 shapes, the order of things go like this:
draw/move shape 1
re-draw the form
draw/move shape 2
re-draw the form
draw/move shape 3
re-draw the form
A program like counter strike uses an internal buffer for drawing, and thigs go like this:
draw/move shape 1
draw/move shape 2
draw/move shape 3
re-draw the form from buffer
You could do the same, if and only if you draw on a picture box directly on the screen, or you simulate the buffer by drawing in a picture box that has the AutoRedraw property set to True, and you hide the picture, and show it (or copy the contents to another picture) only when everything is moved/drawn...
There is also another way... something like this:
http://www.vbforums.com/showthread.php?t=451051
or this
http://www.vbforums.com/showthread.php?t=451033
Where it uses a byte array buffer to draw, and when done, just copy the data in a picture box
Using shapes is the slowest thing you can do of ALL options...
PS: I warned you about this in post #10...
Last edited by CVMichael; Sep 11th, 2007 at 07:50 AM.
-
Sep 11th, 2007, 03:09 PM
#30
Thread Starter
Fanatic Member
-
Sep 11th, 2007, 03:57 PM
#31
Re: array object limit?
Maybe you should post your entire project, and let us take a look. I'm sure we can speed it up...
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
|