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

Unit 4: VB Programming Fundamentals



               In this case, the variable  NumberTrains  is a variant, which means it can take any
               type of data. For example, here we place an integer value into  NumberTrains  (note
               that we specify that 5 is an integer by using the percent sign [%] suffix as specified in Table 3.1):
               Private Sub Command1_Click()
               Dim NumberTrains
               NumberTrains = 5%
               End Sub
               We could have used other data types as well; here, for example, we place a string into
               NumberTrains:
               Private Sub Command1_Click()
               Dim NumberTrains
               NumberTrains = “Five”
               End Sub
               And here we use a floating point value (! is the suffix for single values):
               Private Sub Command1_Click()
               Dim NumberTrains
               NumberTrains = 5.00!
               End Sub
               Be careful of variants, however_they waste time because Visual Basic has to
               translate them into other data types before using them, and they also take up more space than
               other data types.

               4.3.3 Converting Between Data Types
               Visual Basic supports a number of ways of converting from one type of variable to  another in
               fact, that is one of the strengths of the language.
               Visual Basic
               data
               conversion Use This
               function
               To Do This
               ANS value
               to string

               String to
               lowercase or
                                                                 Chr
               uppercase
               Data to
                                                         Format. L Case. U Case
               serial
               number
                                                         Data Serial. Data Value
               Decimal


                                      LOVELY PROFESSIONAL UNIVERSITY                         83
   84   85   86   87   88   89   90   91   92   93   94