Starting Out with Visual Basic 8e — Tony Gaddis | Quiz 3 due Jun 12
Use a TextBox control to let users type text into your application.
TextBox1.Clear() and TextBox1.Focus() to reset for next entry.A variable is a named storage location in memory. Declare with Dim.
| Type | Stores | Example |
|---|---|---|
Integer | Whole numbers (-2B to 2B) | Dim x As Integer = 5 |
Double | Floating-point numbers | Dim y As Double = 3.14 |
Decimal | High-precision (money) | Dim z As Decimal = 19.99D |
String | Text | Dim s As String = "Hello" |
Boolean | True/False | Dim b As Boolean = True |
Char | Single character | Dim c As Char = "A"c |
totalSales).VB supports standard arithmetic operators:
Operator Precedence (highest to lowest):
( )^* / \Mod+ -VB converts types automatically (implicit conversion) unless Option Strict is On.
Type conversion functions:
CDec() for currency/money calculations to avoid floating-point rounding errors.Declared outside any procedure, inside the form class. Accessible from all procedures in the form.
Use TryParse to safely convert input without crashing:
Or use Try-Catch blocks:
Test your knowledge. 25 questions covering variables, calculations, types, and more.
Click a card to flip it. Review key terms and concepts.
Card 1 / 30
Quick reference for Quiz 3. All the essentials in one place.
| Type | Size | Range / Values | Suffix |
|---|---|---|---|
Integer | 32-bit | -2,147,483,648 to 2,147,483,647 | — |
Double | 64-bit | ±4.94×10⁻³²⁴ to ±1.8×10³⁰⁸ | R or # |
Decimal | 128-bit | ±7.9×10⁻²⁸ to ±7.9×10²⁸ (28-29 digits) | D or @ |
String | varies | 0 to ~2 billion chars | " " |
Boolean | 16-bit | True or False | — |
Char | 16-bit | Single Unicode char | "A"c |
| Function | Result Type |
|---|---|
CInt(value) | Integer (rounds) |
CDbl(value) | Double |
CDec(value) | Decimal ← use for money! |
CStr(value) | String |
CBool(value) | Boolean |
CChar(value) | Char |
| Specifier | Name | Example (1234.5) |
|---|---|---|
"C" | Currency | $1,234.50 |
"N2" | Number (2 decimals) | 1,234.50 |
"F0" | Fixed (0 decimals) | 1235 |
"P1" | Percent | 12.3% |
"E2" | Scientific | 1.23E+003 |
7 / 3 = 2.333 but 7 \ 3 = 2 (backslash = integer division)17 Mod 4 = 1 (remainder)19.99D not 19.99 for Decimal literalsInteger.TryParse(text, variable) — returns True/False, puts value in variable