Programming: VB Programming Tutorial #4
Programming: VB Programming Tutorial #4
Whoa! Its been a long time since I wrtoe another tut. Expect more to come shortly after this.
In this tut, you will learn to make objects move around the screen using Command buttons.
Start off by making a new project. Standard Exe
Now that you have the form made. Change the name to
Frm1
Your welcome to change it to anyname you want. Also, feel free to change the caption
Now, go over to shapes in your toolbox. And drag out a shape onto the form. You cannot select the shape first. So it automaticly gives you a square
Now that you have that done. Rename the shape to
Shp1
' Shape = Shp
And go down to Shape under Properties. Change the shape to Circle
Now its time to make the command buttons. Arrange them to line up like the arrows of your keyboard.(See pic)
Now its time to name them
The command button for up's name should be
cmdup
And the command button for down's is
cmddown
And so on.......
Now that the UI is set up. Its time for some code. The code is pretty straightfoward
Open up the code for cmdup. Type
shp1.top=shp1.top-100
Now to break it down. Shp1.top means. Shp 1's top properties.
Shp1.top=Shp1.top-100 means find shp1.top's current position, and minus that by 100 pixels. Normaly + means to go up, and - to go down. But VB is different. 0,0 on the form is at the top left corner. Not the bottom left corner like a graph.
Now open the code for cmddown. Use
shp1.top=shp1.top+100
Properties in vb are only Top, and left. There is no right, or down
Now open the code for cmdleft. Use
shp1.left=shp1.left-100
Again, same as the top
Again, open cmdright's code. And type
shp1.left=shp1.left+100
Now open the code for cmdexit. Use
Unload Me
Thats to shut the program down
Wthe program runs. Click on the command buttons to move the shaps. You have to click them multiple times to get it to move far. But you could always increase to number from 100 +
Well, sry for the delay. I get busy sometimes. Expect more tuts very soon. For now
Enjoy!
In this tut, you will learn to make objects move around the screen using Command buttons.
Start off by making a new project. Standard Exe
Now that you have the form made. Change the name to
Frm1
Your welcome to change it to anyname you want. Also, feel free to change the caption
Now, go over to shapes in your toolbox. And drag out a shape onto the form. You cannot select the shape first. So it automaticly gives you a square
Now that you have that done. Rename the shape to
Shp1
' Shape = Shp
And go down to Shape under Properties. Change the shape to Circle
Now its time to make the command buttons. Arrange them to line up like the arrows of your keyboard.(See pic)
Now its time to name them
The command button for up's name should be
cmdup
And the command button for down's is
cmddown
And so on.......
Now that the UI is set up. Its time for some code. The code is pretty straightfoward
Open up the code for cmdup. Type
shp1.top=shp1.top-100
Now to break it down. Shp1.top means. Shp 1's top properties.
Shp1.top=Shp1.top-100 means find shp1.top's current position, and minus that by 100 pixels. Normaly + means to go up, and - to go down. But VB is different. 0,0 on the form is at the top left corner. Not the bottom left corner like a graph.
Now open the code for cmddown. Use
shp1.top=shp1.top+100
Properties in vb are only Top, and left. There is no right, or down
Now open the code for cmdleft. Use
shp1.left=shp1.left-100
Again, same as the top
Again, open cmdright's code. And type
shp1.left=shp1.left+100
Now open the code for cmdexit. Use
Unload Me
Thats to shut the program down
Wthe program runs. Click on the command buttons to move the shaps. You have to click them multiple times to get it to move far. But you could always increase to number from 100 +
Well, sry for the delay. I get busy sometimes. Expect more tuts very soon. For now
Enjoy!
Feel free to send me an instant message if you need anything.
-
- Posts: 19
- Joined: Mon Oct 25, 2004 5:39 pm
its cool, this would help those people who want to make a game, instead of using command buttons you could use the keypress method that is built into each form and have it move around via the arrow keys, then you could make a simple game, like snake or something. Just an idea for people who want to put what they learned to the test. Good tutorial
Signature exceeded 75KB.
-
- Posts: 732
- Joined: Wed Nov 26, 2003 11:59 pm
- Location: Raleigh, NC, USA
-
- Posts: 94
- Joined: Mon Nov 15, 2004 7:01 pm
- Location: over there
if any1 wants to no how to do that with the keys i can help them. i learned it a while ago, i think yomama taught me.TheKeihatsu wrote:its cool, this would help those people who want to make a game, instead of using command buttons you could use the keypress method that is built into each form and have it move around via the arrow keys, then you could make a simple game, like snake or something. Just an idea for people who want to put what they learned to the test. Good tutorial
btw great tutorial! that will help out alotta ppl. make another 1 on making a character shoot and making it kill people. or sumthing
then a buncha ppl will be making games and maybe there will be sum good 1s made.
Signature exceeded 3 lines of text.
-
- Posts: 19
- Joined: Mon Oct 25, 2004 5:39 pm
-
- Posts: 100
- Joined: Thu Dec 02, 2004 8:35 am
- Location: MS,USA
- Contact:
-
- Posts: 115
- Joined: Fri Jan 14, 2005 9:26 am
- Location: Why The Fuck Would I Tell You? Indiana...
- Contact:
-
- Posts: 773
- Joined: Tue May 04, 2004 7:14 am
- Location: Uranus