Datatypes project (see PowerPoint datatypes)
PublicClass frmDataTypes
Inherits System.Windows.Forms.Form
'Note these examples use the default setting for
'Option Strict as off
PrivateSub btnSysDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSysDate.Click
txtSysDate.Text = Now()
EndSub
PrivateSub btnToday_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToday.Click
txtToday.Text = Today()
EndSub
PrivateSub btnNewYear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewYear.Click
txtNewYear.Text = #1/1/2005#
EndSub
PrivateSub btnVal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVal.Click
'Correct way
txtVal.Text = Val("123") * 2
'Relying on implicit conversion
txtValImplicit.Text = "123" * 2
EndSub
PrivateSub btnToString_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToString.Click
Dim wkVariable AsInteger = 123
txtToString.Text = "The number is " & wkVariable
EndSub
PrivateSub btnInteger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInteger.Click
Dim wkInteger AsInteger
wkInteger = 123.45
txtInteger.Text = wkInteger
EndSub
PrivateSub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecimal.Click
Dim wkDecimal AsDecimal
wkDecimal = 123.45
txtDecimal.Text = wkDecimal
EndSub
EndClass
Calculations project (see PowerPoint datatypes)
PublicClass frmCalculations
Inherits System.Windows.Forms.Form
PrivateSub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click
Dim wkNum AsInteger = 5
txtPower2.Text = wkNum ^ 2
txtPower3.text = wkNum ^ 3
EndSub
PrivateSub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
Dim wkToDivide AsDecimal
wkToDivide = 234.56
txtDivide.Text = wkToDivide / 2
EndSub
PrivateSub btnIntegerDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIntegerDivide.Click
Dim wkIntDivide AsDecimal
wkIntDivide = 234.56
txtIntegerDivide.Text = wkIntDivide \ 2
EndSub
PrivateSub btnMod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMod.Click
Dim wkMod AsInteger, wkMod1 AsDecimal
wkMod = 20
txtMod.Text = wkMod Mod 7
wkMod1 = 20.45
txtMod1.Text = wkMod1 Mod 7
EndSub
EndClass
OrderOperations Project (see PowerPoint datatypes)
PublicClass frmOper
Inherits System.Windows.Forms.Form
PrivateSub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
Dim aa AsInteger = 2
Dim bb AsInteger = 6
Dim cc AsInteger = 4
Dim dd AsInteger = 2
Dim ee AsInteger = 3
lblFirst.Text = "a + b - c / d + e or 2 + 6 - 4 / 2 + 3"
txtFirst.Text = Val(aa + bb - cc / dd + ee)
EndSub
PrivateSub btnSecond_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSecond.Click
Dim aa AsInteger = 2
Dim bb AsInteger = 6
Dim cc AsInteger = 4
Dim dd AsInteger = 2
Dim ee AsInteger = 3
lblSecond.Text = "(a + b - c) / (d + e) or (2 + 6 - 4) / (2 + 3)"
txtSecond.Text = Val((aa + bb - cc) / (dd + ee))
EndSub
PrivateSub btnThird_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThird.Click
Dim aa AsInteger = 10
Dim bb AsInteger = 3
Dim cc AsInteger = 4
Dim dd AsInteger = 500
Dim ee AsInteger = 2
lblThird.Text = "(aa^bb * cc - dd) / ee or (10^3 * 4 - 500) / 2"
txtThird.Text = (aa ^ bb * cc - dd) / ee
EndSub
EndClass
Convert Project (see PowerPoint datatypes)
PublicClass frmConvert
Inherits System.Windows.Forms.Form
PrivateSub btnCBool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCBool.Click
Dim wkNum0 AsInteger = 0
Dim wkNum1 AsInteger = 1
txtBool0.Text = CBool(wkNum0)
txtBool1.Text = CBool(wkNum1)
EndSub
PrivateSub btnCBoolean_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCBoolean.Click
Dim wkRslt AsBoolean
Dim wkFirst AsInteger = 100
Dim wkSecond AsInteger = 200
wkRslt = (wkFirst = wkSecond)
txtBool.text = wkRslt
EndSub
PrivateSub btnCDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCDate.Click
Dim wkDatetoConvert AsString = "December 12, 2004"
Dim wkDate AsDate
wkDate = CDate(wkDatetoConvert)
txtDate.text = wkDate
EndSub
PrivateSub btnCDec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCDec.Click
Dim wkDollar AsString = "$15,567.89"
Dim wkDec AsDecimal
wkDec = CDec(wkDollar)
txtCDec.Text = wkDec
EndSub
PrivateSub btnCInt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCInt.Click
txtCInt.Text = CInt(378.287)
txtCInt1.Text = CInt(378.787)
EndSub
PrivateSub btnCStr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCStr.Click
Dim wkSq AsInteger = 6 ^ 2
txtCStr.Text = CStr(wkSq) & " is the square of " & CStr(6)
EndSub
EndClass
Formatting Project (see PowerPoint datatypes)
PublicClass frmFormat
Inherits System.Windows.Forms.Form
PrivateSub frmFormatNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles frmFormatNumber.Click
Dim wkNum AsDecimal = 123456.789
txtFN.Text = FormatNumber(wkNum, 3)
EndSub
PrivateSub btnFormatCurrency_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFormatCurrency.Click
Dim wkCurr AsDecimal = 123456.789
txtFC.Text = FormatCurrency(wkCurr)
EndSub
PrivateSub btnFormatPercent_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFormatPercent.Click
Dim wkNum AsDecimal = 12.34
txtFP.Text = FormatPercent(wkNum, 1)
EndSub
PrivateSub btnFormatPercent2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFormatPercent2.Click
Dim wkNum AsDecimal = 0.1234
txtFP2.Text = FormatPercent(wkNum)
EndSub
PrivateSub btnFOrmatDateTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFOrmatDateTime.Click
Dim wkDate = "#10/15/2004#"
txtFDT.Text = FormatDateTime(wkDate, DateFormat.LongDate)
EndSub
EndClass
AppwithLoad Project (see PowerPoint datatypes)
PublicClass frmAppLoad
Inherits System.Windows.Forms.Form
PrivateSub frmAppLoad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
lblDate.Text = Today()
txtCostCr.Text = FormatCurrency(100)
EndSub
PrivateSub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim wkTotal AsDecimal
wkTotal = Val(txtNumCrs.Text) * CDec(txtCostCr.Text)
txtTotal.Text = FormatCurrency(wkTotal)
EndSub
PrivateSub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
txtName.Clear()
txtStAdr.Clear()
txtCSZ.Clear()
txtNumCrs.Clear()
txtTotal.Clear()
EndSub
PrivateSub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
EndSub
EndClass