Welcome, Guest. Please login or register.

Author Topic: [VB] {#2} First Visual Basic Program!  (Read 716 times)

0 Members and 1 Guest are viewing this topic.

Offline Inject OH 4

[VB] {#2} First Visual Basic Program!
« on: September 15, 2012, 10:49:12 PM »
Making your first application

Instead of doing what most tutorials do and make you make a "Hello World" Application. We are going to skip ahead a bit because you guys seem smart and I know you  can handle it. So lets go ahead and open up Visual Studio/Visual Basic. Once you have it open hit New Project and select windows form application. We will call this application Tutp1.

Now you will have a form (Application window within the program) in the top right corner it should say Form1. Click within the centre of this form. To the right of this form you should see the forms Properties window. As show to the right. Along with other options and properties you could change, but for now lets just work with changing the text property of this form. We are going to select the text Form1 and change it to "Click Me Game!" without quotations (area in which you need to change the text is notated with a number 1 in the picture).

Now to the left hand side of Visual Studio you should see a toolbox. If you do not hit "Ctrl + Alt + X" to bring the toolbox side panel up (you can then pin it to stay their with the pin button). Scroll down to common controls in the toolbox window and under it find "Button", now click and drag this onto your form window (IMG right). Do this again for 3 more buttons (IMG down 1). After this we are going to change the area the buttons are located on the form. So move them closer together near the top left a bit. Now click on an empty space in the form window so we have it selected and look in the form windows properties again, this time change Size to "276, 274". Now select the first button and find its Size property as well and change it to "87, 82". Now orientate your buttons the same as the second picture shown at the bottom. If that's good change the Text Property of all the buttons to "Click Me!". After you've done this change every button except "Button1" (so Button2, Button3, and Button4), to have its Visible property to false. Now it's time for some code. Double click the first button (top left most one if you orientated them from 1 to 2 on the top and 3 to 4 on the button if you didn't this could cause problems so do this now), this should bring up the code window you should see some code, continued below.

This window has many other functions we will be looking at on later tutorials.


The code you see should look like this:
Code: [Select]
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

End Class
Now right now it's not to important that you understand everything in this because that's for another tutorial, and that will be our next one. Right now we are just going to focus on the parts between "Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click" and "End Sub". That blank space between their is where we will place our code.

Now since code should always be neat and properly formatted we should give names to all our buttons as the proper format would be (depending on the language and programmer)  we would likely call button1 "btn_One" and normally instead of bnt_One it would be more like btn_Submit or btn_okDialog depending on the buttons function we would match its name to sound appropriate and be easy for us to understand later, however for now we will leave it with default names.

So for the code for button one we should have it looking like this:

Code: [Select]
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Button1.Visible = True Then
            Button1.Visible = False
            Button2.Visible = True
            Button3.Visible = True
            Button4.Visible = True
        End If

    End Sub
End Class

Now at the top you should see tabs one should say Form1.vb [Design] Click that to go back to the form window and see the buttons and now do the same to buttons 2, 3, and 4 changing it so that it would be If Button(button you are working on number) (IE Button2) .Visible = True Then
Button1 = t
true true  and then the button you are working on set to false.
 

If this confused you then the code at the end should look like this:

Code: [Select]
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Button1.Visible = True Then
            Button1.Visible = False
            Button2.Visible = True
            Button3.Visible = True
            Button4.Visible = True
        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If Button2.Visible = True Then
            Button1.Visible = True
            Button2.Visible = False
            Button3.Visible = True
            Button4.Visible = True
        End If

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        If Button3.Visible = True Then
            Button1.Visible = True
            Button2.Visible = True
            Button3.Visible = False
            Button4.Visible = True
        End If

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        If Button4.Visible = True Then
            Button1.Visible = True
            Button2.Visible = True
            Button3.Visible = True
            Button4.Visible = False
        End If

    End Sub
End Class

Now, since I assume you are using Visual Basic Studio Express Edition things might be a little different, but likely not. Now Click the run button and test out your new application (or just hit F5). Try it out, click a button. It should disappear and the rest should be visible, click another, etc etc.

Congratulations, you've just created your first VB application. Hit "Ctrl + Shift + S" and save it as "Tutp1".

If you have any questions comments or concerns post them below, tell me if you think my tutorials are moving to slow or if you want me to go more in depth with some aspects. What are you looking for more? Make sure to tell me so I can adjust these tutorials to suite the needs. Thanks :D

Right now I'm going to be doing Tut 3 (No Program info on the important parts of programming, what things mean etc)  Tut 4 (app) tut 5 ( info on parts of programming) etc. So switching between programs and info. If you would rather more of one or the other be sure to tell me. I'm will assist anyone who had issues with the project as well so post em up!


Also keep in mind I have to start of slow with basics because not everyone has experience with programming. So keep that in mind.

Thanks for reading and happy Programming :)
Quote from:  Winston
We shall defend our island, whatever the cost may be, we shall fight on the beaches, we shall fight on the landing grounds, we shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender.
Quote from:  Zombie
Valuve Admin Steve: If not we at valve can act as a "guardian gateway".
Valuve Admin Steve: I will be your daddy.
Looking for graphic artist, Photoshopers, and other graphic related people. Hit me a PM if you can help!

Offline Wholegrain

Re: [VB] {#2} First Visual Basic Program!
« Reply #1 on: September 16, 2012, 06:15:36 AM »
later today im going to pop a adderal and sit down for a few hours doing coding

would be awesome if I could get sourcepawn and visual basic under my belt and on my resume when I apply for a job later on.

Conjoint Gaming [Game On]

Re: [VB] {#2} First Visual Basic Program!
« Reply #1 on: September 16, 2012, 06:15:36 AM »

 


* ShoutBox!

Refresh History
  • Careful what you post. Forum rules still apply in the shoutbox!
  • Pillz: new ZPS update tweaks a lot of the gameplay, some new official maps and other BS- ingame admin system looks interesting, hoping to have it running ASAP
    December 16, 2017, 04:32:35 PM
  • Inject OH 4: No problem. I don't back out on my promises
    December 06, 2017, 01:11:03 AM
  • Coreybush11: inject thanks for the gameeee
    December 03, 2017, 09:38:04 PM
  • q bert: https://soundcloud.com/qbert202/vanished-cover-with-fl-studio
    December 01, 2017, 06:50:49 AM
  • Inject OH 4: that games not even out corey lol
    November 26, 2017, 12:47:49 AM
  • Coreybush11: neverwinter nights enhanced edition server when
    November 25, 2017, 06:22:21 PM
  • Inject OH 4: WOWOW
    November 23, 2017, 07:13:55 PM
  • Inject OH 4: A NEW CG CONTEST?
    November 23, 2017, 07:13:49 PM
  • Inject OH 4: WOO WHATS THAT BOYS?
    November 23, 2017, 07:13:46 PM
  • Nexus: CG still kicking and breathing I see
    November 03, 2017, 02:51:39 AM
  • q bert: ove you too arbys
    October 25, 2017, 06:08:53 PM
  • Guztav.: yeah I think it's down
    October 15, 2017, 02:18:27 PM
  • Inject OH 4: I can put it back up if it's down. I'm hopeing I wont be so busy soon. Everything all messed up
    October 15, 2017, 02:44:35 AM
  • Guztav.: man i'd kill to have the ttt server up i havent played that shit in too long
    October 08, 2017, 07:01:49 PM
  • Inject OH 4: Anyone talked to jorgen? I'm not sure if hes mad at me. But I hope he's ok.
    October 05, 2017, 06:10:20 PM
  • Obviously not Gopib: COME BAACK
    October 05, 2017, 02:57:17 PM
  • Obviously not Gopib: i swear people always online like a few days before me
    October 05, 2017, 02:57:14 PM
  • Obviously not Gopib: of the great?
    October 05, 2017, 02:56:55 PM
  • Obviously not Gopib: the return?
    October 05, 2017, 02:56:50 PM
  • Guztav.: Revival update?
    October 01, 2017, 08:56:57 PM
  • Inject OH 4: :P
    September 11, 2017, 02:55:12 AM
  • Inject OH 4: guess*
    September 11, 2017, 02:55:09 AM
  • Inject OH 4: tear (in the eye)   tear (rip)
    September 11, 2017, 02:54:20 AM
  • Inject OH 4: Well don't forget words can be spelled the same and pernounced differently. There called Homophones. A TTS engine has to gusse how something is pernounced based on most likely methods.
    September 11, 2017, 02:54:15 AM
  • wellrgr: Trying to differentiate the pronunciation of there and their is an exercise in frustration though.
    September 08, 2017, 03:18:07 AM
  • wellrgr: google translator pronounces blaim as blime like in slime, and blame as lame with a b. I disagree with google translator, I think claim with a b instead of a c would be the pronunciation, but what do I know? That said, claim and blame don't sound exactly the same, just similar.
    September 08, 2017, 03:15:49 AM
  • Inject OH 4: to be fair they phonetically sound the same. So I mean it's not my problem that English got it wrong.
    September 07, 2017, 01:36:00 AM
  • oobla37: The good, the bad, the ulgy
    September 05, 2017, 05:35:30 PM
  • Guztav.: fun times might be gone, but not the funny ones such as Inject continuing to spell 'blame' as "blaim" >:D
    September 04, 2017, 11:42:28 AM
  • Inject OH 4: gaming communitys in general have fallen a lot. I blaim valve. Theres no good comunity based games anymore.
    September 03, 2017, 12:52:13 AM
  • oobla37: Times change. It was never meant to last
    August 31, 2017, 08:42:30 PM
  • oobla37: It's not your fault
    August 31, 2017, 08:42:22 PM
  • Inject OH 4: Im sorry
    August 31, 2017, 08:13:37 PM
  • oobla37: I miss the ttt days
    August 31, 2017, 07:56:51 PM
  • oobla37: :(
    August 31, 2017, 07:50:31 PM
  • oobla37: CG is kill
    August 31, 2017, 07:50:23 PM
  • Inject OH 4: what?
    August 31, 2017, 12:51:05 AM
  • Pillz: no oatmeal videos in that thread, nice try tho inject
    August 29, 2017, 05:35:00 PM
  • Inject OH 4: http://www.conjointgaming.com/forum/index.php?topic=7986.0
    August 20, 2017, 05:54:53 PM
  • Artemis: Feels good man
    August 12, 2017, 04:46:01 PM