VB tutorial

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




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

VB tutorial

Post by Patrickh »

Okay, I just started learning VB, which is my first programming language. I posting some painfully basic things you can do in VB simply because the best way to learn is to teach. :wink: .

i'll be adding to it as I learn things, so I can cement them in my mind.

First I will explain a few ways of making it so that the window in your form always stays on top, and then goes back to normal.

Create a windows application.

Method #1: put a checkbox and a button in your form. Click the checkbox and in it's properties you will see text (towards the bottom of the 'properties). Change it's name to 'always on top'. In the same way, change the button to say 'set'.
Double click the button to bring up it's code. Type this:

Code: Select all

 If CheckBox1.Checked = True Then
            Me.TopMost = "True"
        Else
            Me.TopMost = "False"
        End If
Let's break that down.
'If CheckBox1.Checked = True Then'=If the box is checked then,
Me=the form that the button is in, example 'form1'.
Topmost=an option within the properties of form1
True=That option is set to be engaged
Else- or else
False=the opposite of true.
End If=the end of the statement
Now let's make popup message boxes for each of the scenarios.
Update the code to say this:

Code: Select all

If CheckBox1.Checked = True Then
            Me.TopMost = "True"
            MsgBox("Your window will now stay on top", vbExclamation, "Your preference has been changed")
        Else
            Me.TopMost = "False"
            MsgBox("Your window will no longer stay on top", vbExclamation, "Your preference has been changed")
        End If
New things:
MsgBox=Message Box
""#1 = text to be displayed
vbExclamation=type of message icon
""#2 = Title of message

Actually that's the only method I'm going to show for that, because we should be learning other things.


Now we are going to make it so there is a toolbar, and if you hit file>options it will open a new window with some options in it.

Into your form, add a 'MenuStrip'. A box will appear that says 'type here'. Click on it and type 'file' then hit enter. below the design window click something called MenuStrip1. click the box directly below file and type 'options' en hit enter. click file, then double click options.
Before you write anything, go to Project>Add Windows form and add a standard one.
Now go back to the code we were at and enter this:

Code: Select all

Form2.Visible = True
which makes form2 visible.
Time to make some options in form2 that edit form1.
create a label and four buttons.
make the label say:
'choose background color'
make the buttons say green, red, blue, and done
double click the green button and type

Code: Select all

Form1.BackColor = Color.Lime
double click red and type:

Code: Select all

Form1.BackColor = Color.Red
try doing blue your self.
double click done and enter

Code: Select all

Me.Visible = False
Hurray! test your knowledge so far and add more color options.



that's it for now, but more to come! Try it out!
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

I would start learning C#, because it's really not even harder, it's just different syntax that appears harder. I think C# is better, because it almost forces you to use object oriented programming.
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

Is it the same basic idea, just a different overall format?
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
User avatar
xbox7887




Socialist Coagulator Decryptor Advisor
Eureka Commentator Wave Scorched Earth

Posts: 2160
Joined: Mon Dec 27, 2004 6:19 pm
Location: New Lenox, Illinois
Contact:

Re: VB tutorial

Post by xbox7887 »

Code: Select all

 If CheckBox1.Checked = True Then
            Me.TopMost = "True"
        Else
            Me.TopMost = "False"
        End If
You're obviously thinking too hard about this stuff...the code above could be easily converted to the following below :?

Code: Select all

Me.TopMost = CheckBox1.Checked;
User avatar
Patrickh




Wordewatician 500

Posts: 1173
Joined: Wed Mar 14, 2007 4:53 pm

Post by Patrickh »

thanks, good to know
Image
conure says: or i could jsut incase my shoes in papar mache, followed by my dog
|||Lethargy||| Mr. Mohawk|||
|||feel free to contact me via PMs, AIM, MSNM, or Xfire if you have any questions|||
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

Patrickh wrote:Is it the same basic idea, just a different overall format?
Yeah, it all gets translated into .Net MSIL, but C# pretty much forces object oriented programming, which for most things is the better style of programming in my opinion, so it would be good to just start in that than learn something else and have to break habbits.
Post Reply