Programming: VB Programming Tutorial #1

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Programming: VB Programming Tutorial #1

Post by Locke »

Well,alot of people are still in the dark when it comes to programing.So this is a tut to get people started.

Today,you will learn Visual Basic.Oooooooh,the excitement

First you will need vb,found here.
http://www.microsoft.com/downloads/deta ... layLang=en

Dl and install.

Now for the learning part.

Open vb and select Standard exe
Image
It should now look like this
Image
Image
That is a Form.Thats where to entire program takes place.You can expand and minimize it.
Image
This is your tool bar.This is where you can select controls.Liek command buttons,text boxes,and labels
Image
And this is the Properties box.This is where you change everything thats in the object selected.

That was the basic introduction.So you know what Im talking about

Now the fun begins

Notice that the forms label says Form1.You probably dont want that in your program so lets change it
Click on the form and go into properties.Go down to caption and it should say Form1

For now,change it to Test

You just changed the title.Hurray!

Now lets change the name.In vb there is abriviations.Heres a list of them

Form=frm
Label=lbl
Text Box=txt
Shape=shp
Picture Box=pic
Image Box=img
Timer=tmr
Option=opt
Cammand Button=cmd

Those are the basics of abriviations.So lets put them to use

Click on your form and go into properties.Go to the top where it says (Name)Form1
change it to frm1
Not much of abriviation there.But helps you in the long run.

Now gray may not be your color of choice.So to change the background color go down to BackColor in the properties window.Click on the gray color til a box comes up.That box has all the colors you can use.Select the one you want and click on the form.It should now be the color.

So lets make a very simple program

Go to your tool box,and select the command button icon.If you are unsure what one this is.Hold your cursor over each one,and it will say what it is.

Drag the commandbutton onto the screen.
It should now look similar to this
Image
Click on the button once.Then go to properties and go to name
Rename to
cmd1
Go down to caption and type
HI

Now double click on the command button.It brings up the code.It now looks like this
Image
Now in there type
msgbox"Hello World!",vbexclamation,"Message"

Now to break that down
msgbox stands for message box
The first quotations "Hello World!" is what the messgae box will say when it pops up.
The vbexclamation is the icon the message box will have.In this case,an Exclamation mark.
And the last quotes "Message",is what the title for the message box will say.

Now press F5 to run the program

Click on the command button that says Hi.It should look like this
Image
Note my title for the message box didnt come up.Thats because Im not using a regular Windows skin.Others will work though

To stop the program click on the icon
Image

Now you may be wondering.How do I see my form again?Above the properties window there is another window.In that,it should say Frm1.Double click frm1 and it will take you back.

Thats it for this part of the tut.Feedback if you want more


Part 2

Well I finaly got enough time to write another tut.Sry to leave you guys hanging with the last one.With that said,lets begin

I will assume you know the basics by following the Visual Basic Programming Tutorial #1 so I wont have to repeat myself

Today,you will be learning something a bit more comlicated.But still easy.You will be learning how to make your own web browser.

Open vb and select Standard exe.Drag out the form so it looks like this
Image
Go over into the properties menu and change the name Form1 to frmExplorer2
Then change the caption to Explorer 2

Not hold control and press the letter "T"
A menu should appear.Scroll down to Microsoft Internet Controls.Check the box and click ok.
Image

Now a picture of the world has been added to your tool box.
Image
Click on it,and drag it out onto the form.
Image
Now clcik on a text box,and drag it out onto the form.
Image
Click on the txt box and go down in the properties menu to Text
Change it from "Text1"to " "

Now drag out a command button onto the form.Change the name from "Command1" to "cmdgo"
Now change the caption to "Go!"
Image
Looks kinda familiar now.
Now for the coding wich is very simple
Double click cmdgo
Now type
WebBrowser1.Navigate Text1.Text
Image

Press F5 to run the program.Type the url into the textbox and press Go!
Image

And thats a web browser.But if you want to create a little bit more.Continue on

Create a new command button and name it cmdback.Then change the caption to "Back"
Then add another command button and name it cmdforward.Then change the cpation to "Forward"
Image
Double click on cmdback and type

On Error GoTo Error
WebBrowser1.GoBack
Error:
Exit Sub


Then double click on cmdforward.And type

On Error GoTo Error
WebBrowser1.GoForward
Error:
Exit Sub

Now when you are in the explorer,you can go back,and forward.

That ends this tut.Ill post more when I get my next break.Feedback please

Part 3


This one will be more Halo orientated.I will explain how to make a simple program like this.
http://files.halomods.com/viewtopic.php?t=18487
Just got it moved to utilities,people spammed last one.

Im going to again asume you have read the previous tuts.

To start off make a form.Name it frmmain
Change caption to Halo Dedicated Server Program

Make a textbox on the form,and name it txt1.Go down to text and delete it.Go to Multiline,and say True(makes it type on more than 1 line)
Image

Now that you have that,lets create some labels
Drag out a label and place it on screen.Change caption to
Server Name

Make a new label and change caption to Maxplayers

Make a new label and change caption to Maps

Make a new label and change caption to gametypes

And creat a command button called submit
cmdsubmit
Caption=Submit
Image
Now create a txtbox,name it txtname,and delte the text from it.Place it next to the label that says Server Name

Create another textbox and name it txtmaxplayers,and delete all text,And place by label Maxplayers

Create another textbox and name it txtmap,and delete all text,And place by label Map

Create another textbox and name it txtgametype,and delete all text,And place by label Gametype
Image
Now for some coding
type
txt1.text="sv_name "+""""+txtname+""""
'That says,type sv_name then add a space,and put "" around the name the user typed in.
So txt1 will say
sv_name "Test"

go down a line anf type
txt1.text=txt1.text+vbcrlf+"sv_maxplayers "+txtmaxplayers
You dont need the "" around it cause its a number
txt1.text=txt1.text,that means add this to the current txt1(otherwise,it would delete what you said,and qrtie new text)
vbcrlf just makes it go to next line

now go to next line and type
txt1.text=txt1.text+vbcrlf+"sv_mapcycle_add "+txtmap+" "+txtgametype
Longer code there,cause it combines txtmap,and gametype together
Image
Now run and type Name,maxplayers,map,and gametype.
Image

And thats the basics of my program.Youll have to mess around a bit to put in more stuff.

All the dl's for vb trial have disapered and I cant find them.Search google for
Visual Basic 5.0 Control Edition

if you find a link please post it here
Any suggestions for another tut?

Part 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
Image
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
Image
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
Image

Now its time to make the command buttons. Arrange them to line up like the arrows of your keyboard.(See pic)
Image
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
Image

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 +
Image

Well, sry for the delay. I get busy sometimes. Expect more tuts very soon. For now
Enjoy!
Last edited by Locke on Tue Oct 26, 2004 3:08 pm, edited 1 time in total.
Image
Feel free to send me an instant message if you need anything.
User avatar
rabiv88





Posts: 734
Joined: Thu Feb 05, 2004 5:20 pm
Location: Halo 2 is in my grasp, wont be back for a while... PEACE
Contact:

Post by rabiv88 »

sweet, im takin progammin in java at school and its not that bad, maybe someday i can help you out... Ohh and great tut :wink:
Image
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Has anyone tried this yet?
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

i dont have the program so no :?

is there a demo? or something?
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

I posted a link of the demo at the top ^^^^^
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

i knew that....was just...testing you
**EDIT** Page Cannot Be Displayed **EDIT**
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Interesting.Thats a direct link to dl.Try copy and pasting.
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

......

I knew that



thanks
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Tiny font you got there,but yourwelcome lol
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

Idid it, and it works (yay) lol

Good Job
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Thank you.I just felt that people might wanna know how to do some programming.Should I make more?
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

This needs a sticky (and yes, you should make more) -- complex --
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Is it just me,or are there no stickeys in this section?
Image
Feel free to send me an instant message if you need anything.
Pie





Posts: 2690
Joined: Wed Mar 10, 2004 8:46 am
Location: Bedford \ Nashua, New Hampshire
Contact:

Post by Pie »

It's just ...your right, you should be the first!..or make me a moderator for 5 seconds so i can sticky it Mr. Admin
Image
Thank You, SHOUTrvb, For This Fantastic Signature :mrgreen:
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

Ya,but modderators dont like me.And no one ever posts in this forum with actual programming
Image
Feel free to send me an instant message if you need anything.
kaptainkommie




Wordewatician 500

Posts: 732
Joined: Wed Nov 26, 2003 11:59 pm
Location: Raleigh, NC, USA

Post by kaptainkommie »

Decent tutorial I suppose. I didn't do it, since I despise VB and already know how to program, but good job. Stickied.
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

kaptainkommie wrote:Decent tutorial I suppose. I didn't do it, since I despise VB and already know how to program, but good job. Stickied.
Wow,thanx.
Image
Feel free to send me an instant message if you need anything.
User avatar
rabiv88





Posts: 734
Joined: Thu Feb 05, 2004 5:20 pm
Location: Halo 2 is in my grasp, wont be back for a while... PEACE
Contact:

Post by rabiv88 »

kool beans, i tried it and it worked, WOOT
Image
EvilPickels




Articulatist 100

Posts: 225
Joined: Thu Sep 16, 2004 2:21 pm

Post by EvilPickels »

Yeah... um, the DL link is like... BROKEN. You mind fxing it?


EDIT: Yeah I recognize that sentence : hello world!. I know where you learned all that from, arg I am to lazy to search for i but try typing C++ tutorial into yahoo search and you get a few really nice tuts. Like from www.cplusplus.com
User avatar
Locke




Socialist Advisor Translator

Posts: 2225
Joined: Fri Aug 06, 2004 1:42 am
Location: Woot.com
Contact:

Post by Locke »

The Hello World thing is a basic tut.So I thought people would understand it easier.For the third tut,im thinking about it having to do with games more.But I have to go slow with people because alot of people dont understand these things
Image
Feel free to send me an instant message if you need anything.
Post Reply