# Visual Basic 2005 - Language Summary v2

Assume:

       Private rand As Random = new Random

String
| s = | String.Empty | String.Empty is the same as "".
| s2 = | s.ToUpper | Create new string all in upper case.
| s2 = | s.ToLower | Create new string all in lower case.
| b = | String.IsNullOrEmpty(s) | True if s is null or empty.
Converting from strings to numbers
| b = | type.TryParse(s, var) | Converts s to type, assigns to var. Returns false if bad input.
x | n = | Val(s) | Use `datatype.TryParse(s, v)` instead.
Converting from numbers to strings
| s = | n.ToString() | Converts n to a string.
| s = | n.ToString(fmt) | Convert n to a string using string format fmt. fmt is a code character optionally followed by a digit indicating number of digits to the right of decimal point to display. If no digit specified, the default is 2. Codes: "C" currency, "D" decimal integer (no decimal point), "F" fixed point, "N" number, "P" percent.
x | s = | Format(n, "currency") | Use n.ToString("C") instead.
x | s = | Convert.ToString(n) | Use `n.toString()` or `n.ToString(fmt)` instead.
Misc
| d = | Financial.Pmt(Rate, NPer, PV [,FV, DUE]) | Calculates loan payments. See p 337.
| i = | rand.next(min, upto) | Random integer in range min up to but not includeing upto.

## Selection statements

    If ... Then
        . . .
    End If
    If ... Then
        . . .
    Else
        . . .
    End If
    If ... Then
        . . .
    ElseIf ... Then
        . . .
    ElseIf ... Then
        . . .
    Else
        . . .
    End If
    Select Case ...
        Case v1
            . . .
        Case v2, v3
            . . .
        Case v4 To v5
            . . .
        Case Is comparison v6
            . . .
        Case Else
            . . .
    End Select

## Subroutines, procedures, methods, functions, ...

    Private Sub name(params,...)
        . . .
    End Sub

## Loops: For...Next, Do...Loop

    For cntr [As type] = start To end [Step stepval]
        . . .
        'Exit can be used inside to terminate loop.
    Next cntr
    Do {While | Until} cond
        . . .
    Loop
    Do
        . . .
    Loop {While | Until} cond

## Other

Types | `Integer, Double, Decimal, String, Boolean`.
Declarations | `Dim, Private, Static, Const`.
Constants | `ControlChars.NewLine, String.Nothing`.
Like patterns | ? (one char), * (zero or more chars), # (digit), [...] (chars in set), [!...] (chars not in set)

## Operators

Arithmetic Ops | `+ - * / \ mod ^`
String Ops | `& Like`
Comparison Ops | `= > >= < <= <> Is (object equality)`
Logical Ops | `AndAlso OrElse Not And Or Xor`
Other Ops | `= TypeOf`

Public Domain 2007 Fred Swartz