Chapter 5 Visual Basic Variables and Formulas, and the .NET Framework 151
If RadioButton2.Checked = True Then
TextBox3.Text = FirstNum Mod SecondNum
End If
If RadioButton3.Checked = True Then
TextBox3.Text = FirstNum ^ SecondNum
End If
If RadioButton4.Checked = True Then
TextBox3.Text = FirstNum & SecondNum
End If
Like the Basic Math program, this program loads data from the text boxes and places
it in the FirstNum and SecondNum variables. The program then checks to see which
radio button the user checked and computes the requested formula. In this event
procedure, the integer division (\), remainder (Mod), exponentiation (^), and string
concatenation (&) operators are used. Now that you’ve changed the data type of the
variables to String, run the program again to see how the & operator works on text.
- Click the Start Debugging button.
- Type birth in the Variable 1 text box, type day in the Variable 2 text box, click
Concatenation, and then click Calculate.
The program now concatenates the string values and doesn’t produce a run-time error,
as shown here: - Click the Quit button to close the program.
As you can see, the String data type has fixed the concatenation problem. However, it is
not a total solution because variables of type String will not function correctly if you
try the Integer Division, Remainder, or Exponentiation operations with them. So, if you
really wanted to have your program process numbers and text strings interchangeably,
you’d need to add some additional program logic to your code. For now, however,
you’re finished working with the Advanced Math program.