[VBS.NET] Tutorial Part 3 - Text Boxes

Discussion in 'Mixed Languages' started by jlgager, Nov 30, 2010.

  1. jlgager

    jlgager MDL Developer

    Oct 30, 2009
    363
    3,173
    10
    #1 jlgager, Nov 30, 2010
    Last edited by a moderator: Apr 20, 2017
    [VBS.NET]Tutorial Part 3 - Text Boxes ​


    In this series I will show you everything from the basics to the most advanced. If you would like me to cover a specific topic, just PM me or post below. If it is a topic I wasn’t planning on covering I will put a star next to its name so check back a lot for updates.

    This Tutorial is in a series. Here is the link for part 2.

    [VBS.NET] Tutorial Part 2 Variables and Labels


    Text Boxes - Basics

    Text boxes are used to extract user input to then save to a variable. U can even store information in them too. With these tutorials, I am going to be building on each one more and more. So because of that its time for you to make your own program without a lot of guidance. Here is the picture:

    [​IMG]

    This program takes the name input from the text boxes and combines them with variables to then show you a msgbox with: My name is: “John Richard Smith”.

    Here is the code:

    Code:
    Private Sub btnCombine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCombine.Click
            Dim First As String
            Dim Middle As String
            Dim Last As String
    
            First = txtFirst.Text
            Middle = txtMiddle.Text
            Last = txtLast.Text
    
            MsgBox("My Name is: " & First & " " & Middle & " " & Last)
            MsgBox("My Name is: " + First + " " + Middle + " " + Last)
    
        End Sub
    The code is pretty easy:

    It declares 3 variables one for each name. Then it assigns the text in the text boxes to their appropriate variables then with some string changes displays the person’s name.

    Now only one of the msgbox lines is needed this code would display the same msgbox twice. That’s because both the “&” symbol and the “+” symbol can combine strings but the “+” symbol can also be used with numbers like all of the operators can. If you tried to use the “&” symbol it would not add them together but add them together as strings. For example, 8 & 6 = 86 not 14 while 8 + 6 = 14.

    Remember the naming convention:
    txtName = Text Box, btnName = Button, lblName = Label, lstName = List Box

    In the next lesson, I will introduce you to list boxes.

    [​IMG]
    Want to thank me?
    Then just hit the thanks button on this post!
    Also post any ideas for future topics and any typos please.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...