Page 99 - Open Soource Technologies 304.indd
P. 99

Unit 5: VB String and Operators



               Objectives

               After studying this unit, you will be able to:
                  • Understand string in visual basic
                  • Discuss operator and math operators
                  • Explain concatenation operators
                  • Understand logical operator
               Introduction


               A string is one or a combination of characters. To declare a variable for it, you can use either
               the string or the Object data types. To initialize the variable, put its value in double-quotes and
               assign it to the variable. Here are examples:
                   Public Module Exercise
                      Public Function Main( ) As Integer
                      Dim First Name As Object

                      Dim Last Name As String
                      First Name = “William”
                      Last Name = “Sansen”
                      Return 0
                      End Function

                   End Module
               An Operator is a code element that performs an operation on one or more code elements that
               hold values. Value elements include variables, constants, literals, properties, returns from Func-
               tion and Operator procedures, and expressions.

               5.1 Strings

               The most common types of data processed by Visual Basic are numbers and strings. Sentences,
               phrases, words, letters of the alphabet, names, telephone numbers, addresses, and Social Security
               numbers are all examples of strings. Formally, a String literal is a sequence of characters that
               is treated as a single item. String literals can be assigned to variables, displayed in text boxes
               and list boxes, and combined by an operation called concatenation (denoted by &).

               5.1.1 Variables and Strings
               A String variable is a name used to refer to a String. The allowable names of String variables
               are the same as those of numeric variables. The value of a String variable is assigned or altered
               with assignment statements and displayed in a list box like the value of a numeric variable.
               String variables are declared with statements of the form






                                      LOVELY PROFESSIONAL UNIVERSITY                         93
   94   95   96   97   98   99   100   101   102   103   104