Tuesday 15 October 2013

Introduction to String variables..

String variables:

In previous section we have learnt about INTEGER variables.
In this section we will learn about the STRING variables.

             And if we want Visual Basic to store text we need to use the word "String". To set up a variable to hold text we need to use As String and not As Integer. If the information we want to store in our variables is a First Name and a Last Name, we can set up two variables like this.

Dim FirstName As String
Dim LastName As String

Here also we can assign the values to the variables like Integer, but the difference is we can write them in between DOUBLE QUOTES.

ex: FirstName = "Geetha"
      LastName = "Rani" .

This is form design for the String variable :

First place one text box and one button on the form.
Then change the button name as "appending 2 strings" in button properties.




This is the code for the Button:

        Dim FirstName As String
        Dim LastName As String
        Dim FullName As String

        FirstName = "Geetha"
        LastName = "Rani"

         FullName = FirstName & LastName

        TextBox1.Text = FullName


Place this in between Private sub and End sub.


Then run the form.
click on button.
then the result will be Printed in TESTBOX .

this is the output:

In the above output the 2 strings are appended with no space between them.

If we want to give space in between them just insert the DOUBLE QUOTES with no date in between those strings:

Ex:
 Dim FirstName As String
        Dim LastName As String
        Dim FullName As String

        FirstName = "Geetha"
        LastName = "Rani"

         FullName = FirstName & " " & LastName

        TextBox1.Text = FullName


This is the output :






<---- Previous page                                    Next page ---->


VB.NET HOME PAGE













No comments:

Post a Comment