| Chapter 3- Data Types and Operators | Boolean Expressions Page 2 3 4 |
| The If Statement Page 2 3 4 5 6 7 8 9 | |
| Arithmetic Operations Page 2 3 4 5 6 | Boolean Operators and Nested If Statements Page 2 3 4 5 6 7 |
| Events and Sequential Processing Page 2 3 4 5 | More Examples Page 2 3 4 5 6 7 8 9 10 11 12 |
| Datatypes and Conversions Page 2 3 4 5 6 7 | Using Check Box and Option Controls Page 2 3 4 5 6 7 8 9 10 |
| Variable Declarations - Local and Global Page 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Exercises Page 2 3 4 5 6 7 8 |
| Chapter 4- Selection Statements | Review Questions |
| Introduction | |
3-4: Data Types in Visual Basic (continued)
In general, these data conversion functions take one or more arguments (the input values if you like) and produce a single result (called the return type in the table). The examples in the table all require just one argument, although in general the syntax for a function is
functionName(argument1, argument2, ... )where the argument list may contain (many) more than one argument. The function uses the values of the arguments to produce a single value as its result. That result value must be used in some way, i.e. assigned to some object property or used in an expression for example. Thus you might write
objectName.property = functionName(argument)or
objectName.property = 3.3 + functionName(argument)/2.5The argument is a value - an explicit value, a variable or property name, or an expression, for example. In the case of functions such as these it is clear that the argument will be some value (often the result of an expression) of a particular data type, and the result will be that value converted to the required data type.
In other words, taking the CDbl function as an example, the argument might be a string value (although other argument types are allowed this is the most common way we will use the function), and provided that the string value represents a valid real number of double data type, the function will convert it, producing a result value that can be used in arithmetic. Of course, if the argument value cannot possibly be a number the attempt to convert will fail.
Thus, in Exercise 3-2 we should write
txtInterest1.Text = CDbl(txtInterest.Text) *
Cdbl(txtInitialCap.Text)
txtCapital1.Text = CDbl(txtInitialCap.Text) +
CDbl(txtInterest1.Text)
txtInterest2.Text = CDbl(txtInterest.Text) *
CDbl(txtCapital1.Text)
txtCapital2.Text = CDbl(txtCapital1.Text) +
CDbl(txtInterest2.Text)
txtInterest3.Text = CDbl(txtInterest.Text) *
CDbl(txtCapital2.Text)
txtCapital3.Text = CDbl(txtCapital2.Text) +
CDbl(txtInterest3.Text)
or
txtInterest1.Text =
System.Convert.ToDouble(txtInterest.Text) * _