hi i attached a file should run for u,there is no exe in there.
my problem is this program will animate 3 ants no problem.
add another and it stops animating .
if i should throw this away and start over doing it another way please
tell me.
thanks
Printable View
hi i attached a file should run for u,there is no exe in there.
my problem is this program will animate 3 ants no problem.
add another and it stops animating .
if i should throw this away and start over doing it another way please
tell me.
thanks
The code you have got seems to be quite good, but it is hard to be sure (or find the problem) because you have made it very hard to read.
One reason for that is lots of blank lines - you should try to keep it down to just 1 or 2 in a row at most (and usually none).
Another reason is that your indenting is extremely random. For an explanation/example of how it should be, see the article What is indenting, and why should I do it? from our Classic VB FAQs (in the FAQ forum)
Something else that makes it harder to read (and maintain) is the duplication that you have got - Animateant1 and Animateant2 etc have almost identical code, so you should really only have one of them, and pass parameters as apt. For info and examples, see the FAQ article How can I pass a control (textbox/listbox/..) to a sub or function?
If you make those changes the code will be much shorter and easier to read, which will make it much simpler for us to find the problem(s).
You should also take a look at the article Why is using the 'End' statement (or VB's "stop" button) a bad idea?
In this case you should replace End with this:
Code:antanimation.Enabled = False
Unload Me
Exit Sub
fly,
First of all, as far as your question about tossing it all and starting over...
Not necessarily, but I would suggest using arrarys instead of having each ant be an "individual."
When I uncommented "ant4," it worked ok for me. What problem are you having? The only problem I saw was with your "bounce" logic. For example, if an ant was traveling downward and to the left, and went off the bottom of the screen, you have "left" as a valid new direction for it. In other words, it won't come back on the screen at that point. I assume it has to travel left until it goes past the x=0 part of the screen, and maybe then it shows up again? Not sure that would even happen all the time, since I'm guessing "down" would be valid to switch to at that point.
Give me some more details about the issues your having and we'll go from there.
Bryce
thanks si i usually clean up last take out lines and such .
ive been trying to find a way to do that Animateant1 and 2 into one.
@Bryce im still trynig to learn arrarys and such
thanks all
It's much better to clean up as you go along, because it reduces the chances of several kinds of mistakes while you are writing the code (because they become much more obvious), as well as making situations like this far easier too.
Give it a go based on the article, and if you get stuck let us know what the issue is, and what code you've come up with.Quote:
ive been trying to find a way to do that Animateant1 and 2 into one.
Using Control Arrays as vbfbryce suggested is a good alternative, and could well be better in your situation. If you want to give that a go, there is an article in the "Controls" section of the FAQs which explains them.
fly,
some code to get you started with arrays, if that's the way you want to go:
This code will populate an array with random ("direction") numbers, 1 thru 8.Code:Option Explicit
Private Directions(1 To 4) As Integer 'need one element for each ant
Private LowerBound As Integer 'will be 1
Private UpperBound As Integer 'I'm thinking 8? represents number of "directions"
Private Sub Form_Load()
Dim i As Integer
LowerBound = 1
UpperBound = 8
Randomize
'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
For i = 1 To 4
Directions(i) = Int((UpperBound - LowerBound + 1) * Rnd + LowerBound)
'sets a starting direction for each ant, assuming 4 ants
Next i
End Sub
Let's start with this. Let me know if it makes sense to you, and we can go from there.
Bryce
thanks that seams to be easy will probly be faster
Couple more points:
1) Move the Randomize statement to Form_Load. It should only be
called once for any program run.
2) Use the code below to get the program to properly unload:
Code:If GetAsyncKeyState(vbKeySpace) Then
antAnimation.Enabled = False
Unload Me
Exit Sub
End If
...
thanks to all
i think im going to have to learn bltbit .
another question when using multiple forms at once as the ants does that use more memory,and is there a way to use collision detection for forms?
becuse the animationing works fine that way,werd i think
That wouldn't give a noticeable improvement... but you would get a very significant improvement by simply pre-loading the images (possibly in extra image controls), rather than re-loading them every frame for every ant.
Yes, and more CPU time etc.Quote:
another question when using multiple forms at once as the ants does that use more memory,
Yes, the same as you would for controls... but with a few extra calculations.Quote:
and is there a way to use collision detection for forms?
I wouldn't recommend using multiple forms, as I can't think of any benefit.
Once you have tidied up the code, it will be much easier to work out what the issues are.Quote:
becuse the animationing works fine that way,werd i think
image controls is that in propertys?
I think this is what si_the_geek is telling you:
...:wave:Code:Option Explicit
Private Sub Command1_Click() '~~~ When button is pressed
Picture2.Picture = Picture1.Picture '~~~ Copying the preloaded image to a new picturebox, in which we will display it to the user
End Sub
Private Sub Form_Load()
Picture1.Visible = False '~~~ We are hiding this picturebox from the user.
'~~~ Preloading the image to a Picturebox
Picture1.Picture = LoadPicture("c:\test.jpg")
End Sub
That is exactly what I meant :)
(while I said Image controls, PictureBox controls are perfectly valid too)
hey i got 11 out of 12 to work