Welcome, Guest. Please login or register.

Author Topic: [VB] {#2} First Visual Basic Program!  (Read 1221 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!
  • Inject OH 4: And yes thank you very much Finnie! You are a champion xP
    March 22, 2024, 05:59:12 PM
  • Inject OH 4: Hey abrys agreed we should.
    March 22, 2024, 05:59:02 PM
  • Finniespin: Totally not a spam-bot, also totally not a limited time offer
    March 03, 2024, 05:25:06 PM
  • Finniespin: Anyone looking for a datacenter technician job? We got postings available around US and Europe (EMEA)
    February 17, 2024, 07:23:12 AM
  • Finniespin: https://www.google.com/about/careers/applications/jobs/results/118336179041903302-data-center-technician-global-server-operations
    February 17, 2024, 07:20:25 AM
  • Finniespin: Gave Inject 50 euros to pay for fees ^^
    February 17, 2024, 07:17:42 AM
  • xXArbysOvenMittXx: we gotta get the crew together again one day and hang, add me on discord: ogarbies
    February 12, 2024, 06:52:07 PM
  • xXArbysOvenMittXx: yo who is still paying for this lol
    February 12, 2024, 06:19:47 PM
  • Klondor: wow CG still lives, mind blown
    February 09, 2024, 05:13:53 AM
  • Finniespin: The website is back online!!!
    February 06, 2024, 03:17:05 PM
  • Inject OH 4: xD
    January 14, 2024, 05:55:44 PM
  • Finniespin: Get a load of this guy
    December 16, 2023, 09:16:03 AM
  • Inject OH 4: Sure
    December 09, 2023, 07:22:27 PM
  • HailToTheKing: cum shot . and cum shot. an d cum shot
    December 01, 2023, 01:54:12 PM
  • Finniespin: ffuck
    November 24, 2023, 03:43:47 PM
  • Inject OH 4: ee
    October 12, 2023, 01:13:56 AM
  • Sly: dd
    August 09, 2023, 03:13:48 AM
  • Inject OH 4: cc
    August 03, 2023, 09:51:36 PM
  • Finniespin: bb
    August 02, 2023, 06:12:50 PM
  • Inject OH 4: aa
    July 04, 2023, 10:29:35 PM
  • Shikaru: Been a very long time
    February 20, 2023, 05:42:04 PM
  • Shikaru: Oh wow my account is STILL active :)
    February 20, 2023, 05:42:00 PM
  • Napoleon BonaPARTY: yooo we got a lovense sponsor???
    December 16, 2022, 03:45:43 PM
  • Napoleon BonaPARTY: holy shit
    December 16, 2022, 03:45:24 PM
  • Napoleon BonaPARTY: oh wow its still here
    December 16, 2022, 03:45:21 PM
  • HailToTheKing: legends never die
    October 16, 2022, 01:28:09 PM
  • Live Bait: Oh wow. Still remember my old password.
    September 23, 2022, 08:37:38 AM
  • Mr_Rainbow: Still alive. Hope all is well with everyone this Christmas
    December 09, 2021, 03:31:04 AM
  • SlyWilliam: Much love, from our MC server to our ZPS server <3
    December 07, 2021, 10:23:37 PM
  • SlyWilliam: For the record, I don't REALLY remember all of you, but goddamn do I MISS all of you <3
    December 07, 2021, 10:23:10 PM
  • Pyro: parrot
    September 07, 2021, 05:23:18 AM
  • Inject OH 4: Do you mean for people that haven't come on in a long time and have to reagree?
    August 02, 2021, 11:39:42 PM
  • Inject OH 4: I'm not sure what you mean. Could you be more specific?
    August 02, 2021, 11:38:54 PM
  • Inject OH 4: https://cdn.discordapp.com/attachments/323969454050377729/871930017595133963/unknown.png
    August 02, 2021, 11:38:45 PM
  • Inject OH 4: @SlowLefty I'll look into it.
    August 02, 2021, 11:38:02 PM
  • Ghast: Hope everyone from CG is doing well. :)
    June 25, 2021, 10:38:49 AM
  • Ghast: damn, inject still has this site running eh.
    June 25, 2021, 10:37:38 AM
  • SlowLefty: The javascript for the updated user agreement is broken, I had to use html inspector to add the submit button.
    April 16, 2021, 10:09:58 PM
  • JohnCyKlopZ: hey guys
    March 31, 2021, 08:45:24 AM
  • Mercy: Lol it's been 10 years since you last asked
    March 24, 2021, 01:18:52 AM

SimplePortal 2.3.5 © 2008-2012, SimplePortal