VB6convertSavAcctCls

 

Option Strict Off

Option Explicit On

Friend Class Form1

Inherits System.Windows.Forms.Form

' a simple class with 2 properties and 2 methods

Dim objSavAcct As SavAcct

Dim wkTranAmt As Decimal

Private Sub cmdDpsit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDpsit.Click

objSavAcct.Deposit((wkTranAmt))

lblClsBal.Text = CStr(objSavAcct.Balance)

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

Private Sub cmdReset_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReset.Click

lblOpnBal.Text = CStr(objSavAcct.Balance)

lblClsBal.Text = ""

txtTrnAmt.Text = ""

cmdDpsit.Enabled = True

cmdWthDrwl.Enabled = True

cmdReset.Enabled = False

End Sub

Private Sub cmdWthDrwl_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdWthDrwl.Click

objSavAcct.WithDrawal((wkTranAmt))

lblClsBal.Text = CStr(objSavAcct.Balance)

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

objSavAcct = New SavAcct

Call cmdReset_Click(cmdReset, New System.EventArgs())

End Sub

Private Sub txtTrnAmt_Validating(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles txtTrnAmt.Validating

Dim Cancel As Boolean = eventArgs.Cancel

wkTranAmt = CDec(txtTrnAmt.Text)

eventArgs.Cancel = Cancel

End Sub

End Class

 

Option Strict Off

Option Explicit On

Friend Class SavAcct

Private curBalance As Decimal

Private intIntRate As Short

Public ReadOnly Property Balance() As Decimal

Get

Balance = curBalance

End Get

End Property

Public Property IntRate() As Short

Get

IntRate = intIntRate

End Get

Set(ByVal Value As Short)

intIntRate = Value

End Set

End Property

Public Sub WithDrawal(ByVal vTranAmt As Decimal)

curBalance = curBalance - vTranAmt

End Sub

Public Sub Deposit(ByVal vTranAmt As Decimal)

curBalance = curBalance + vTranAmt

End Sub

End Class

 

From the original VB6

 

Form

 

Option Explicit

 

' a simple class with 2 properties and 2 methods

 

Dim objSavAcct As SavAcct

Dim wkTranAmt As Currency

 

Private Sub cmdDpsit_Click()

objSavAcct.Deposit (wkTranAmt)

lblClsBal.Caption = objSavAcct.Balance

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

 

Private Sub cmdReset_Click()

lblOpnBal.Caption = objSavAcct.Balance

lblClsBal.Caption = ""

txtTrnAmt.Text = ""

cmdDpsit.Enabled = True

cmdWthDrwl.Enabled = True

cmdReset.Enabled = False

End Sub

 

Private Sub cmdWthDrwl_Click()

objSavAcct.WithDrawal (wkTranAmt)

lblClsBal.Caption = objSavAcct.Balance

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

 

Private Sub Form_Load()

Set objSavAcct = New SavAcct

Call cmdReset_Click

End Sub

 

Private Sub txtTrnAmt_Validate(Cancel As Boolean)

wkTranAmt = txtTrnAmt.Text

End Sub

 

Class

Option Explicit

 

Private curBalance As Currency

Private intIntRate As Integer

 

 

Public Property Get Balance() As Currency

Attribute Balance.VB_UserMemId = 0

Balance = curBalance

End Property

 

 

Public Property Get IntRate() As Integer

IntRate = intIntRate

End Property

 

Public Property Let IntRate(ByVal vIntRate As Integer)

intIntRate = vIntRate

End Property

 

Public Sub WithDrawal(ByVal vTranAmt As Currency)

curBalance = curBalance - vTranAmt

End Sub

 

Public Sub Deposit(ByVal vTranAmt As Currency)

curBalance = curBalance + vTranAmt

End Sub

 

VbconvertSavAcctCls01

 

Option Strict Off

Option Explicit On

Friend Class Form1

Inherits System.Windows.Forms.Form

 

' a simple class with 2 properties and 2 methods and 1 event

Dim WithEvents objSavAcct As SavAcct

Dim wkTranAmt As Decimal

Dim ans As String

Private Sub cmdDpsit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDpsit.Click

objSavAcct.Deposit((wkTranAmt))

lblClsBal.Text = CStr(objSavAcct.Balance)

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

Private Sub cmdReset_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReset.Click

lblOpnBal.Text = CStr(objSavAcct.Balance)

lblClsBal.Text = ""

txtTrnAmt.Text = ""

cmdDpsit.Enabled = True

cmdWthDrwl.Enabled = True

cmdReset.Enabled = False

End Sub

Private Sub cmdWthDrwl_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdWthDrwl.Click

ans = ""

objSavAcct.WithDrawal((wkTranAmt))

If ans = "" Then

lblClsBal.Text = CStr(objSavAcct.Balance)

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

Else

txtTrnAmt.Text = ""

txtTrnAmt.Focus()

End If

End Sub

Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

objSavAcct = New SavAcct

Call cmdReset_Click(cmdReset, New System.EventArgs())

End Sub

Private Sub objSavAcct_InsufficientFunds() Handles objSavAcct.InsufficientFunds

ans = CStr(MsgBox("Insfficient funds to cover withdrawal!", MsgBoxStyle.OKOnly))

End Sub

Private Sub txtTrnAmt_Validating(ByVal eventSender As System.Object, ByVal eventArgs As System.ComponentModel.CancelEventArgs) Handles txtTrnAmt.Validating

Dim Cancel As Boolean = eventArgs.Cancel

wkTranAmt = CDec(txtTrnAmt.Text)

eventArgs.Cancel = Cancel

End Sub

End Class

 

Option Strict Off

Option Explicit On

Friend Class SavAcct

Event InsufficientFunds()

Private curBalance As Decimal

Private intIntRate As Short

Public ReadOnly Property Balance() As Decimal

Get

Balance = curBalance

End Get

End Property

Public Property IntRate() As Short

Get

IntRate = intIntRate

End Get

Set(ByVal Value As Short)

intIntRate = Value

End Set

End Property

Public Sub WithDrawal(ByVal vTranAmt As Decimal)

If curBalance < vTranAmt Then

RaiseEvent InsufficientFunds()

Else

curBalance = curBalance - vTranAmt

End If

End Sub

Public Sub Deposit(ByVal vTranAmt As Decimal)

curBalance = curBalance + vTranAmt

End Sub

End Class

 

From version 6 SavAcctCls01

 

Option Explicit

 

' a simple class with 2 properties and 2 methods and 1 event

 

 

Dim WithEvents objSavAcct As SavAcct

Attribute objSavAcct.VB_VarHelpID = -1

Dim wkTranAmt As Currency

Dim ans As String

 

Private Sub cmdDpsit_Click()

objSavAcct.Deposit (wkTranAmt)

lblClsBal.Caption = objSavAcct.Balance

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

End Sub

 

Private Sub cmdReset_Click()

lblOpnBal.Caption = objSavAcct.Balance

lblClsBal.Caption = ""

txtTrnAmt.Text = ""

cmdDpsit.Enabled = True

cmdWthDrwl.Enabled = True

cmdReset.Enabled = False

End Sub

 

Private Sub cmdWthDrwl_Click()

ans = ""

objSavAcct.WithDrawal (wkTranAmt)

If ans = "" Then

lblClsBal.Caption = objSavAcct.Balance

cmdDpsit.Enabled = False

cmdWthDrwl.Enabled = False

cmdReset.Enabled = True

Else

txtTrnAmt.Text = ""

txtTrnAmt.SetFocus

End If

End Sub

 

Private Sub Form_Load()

Set objSavAcct = New SavAcct

Call cmdReset_Click

End Sub

 

Private Sub objSavAcct_InsufficientFunds()

ans = MsgBox("Insfficient funds to cover withdrawal!", vbOKOnly)

End Sub

 

Private Sub txtTrnAmt_Validate(Cancel As Boolean)

wkTranAmt = txtTrnAmt.Text

End Sub

 

VERSION 1.0 CLASS

BEGIN

MultiUse = -1 'True

Persistable = 0 'NotPersistable

DataBindingBehavior = 0 'vbNone

DataSourceBehavior = 0 'vbNone

MTSTransactionMode = 0 'NotAnMTSObject

END

Attribute VB_Name = "SavAcct"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = True

Attribute VB_PredeclaredId = False

Attribute VB_Exposed = False

Option Explicit

 

Event InsufficientFunds()

 

Private curBalance As Currency

Private intIntRate As Integer

 

 

Public Property Get Balance() As Currency

Attribute Balance.VB_UserMemId = 0

Balance = curBalance

End Property

 

 

Public Property Get IntRate() As Integer

IntRate = intIntRate

End Property

 

Public Property Let IntRate(ByVal vIntRate As Integer)

intIntRate = vIntRate

End Property

 

Public Sub WithDrawal(ByVal vTranAmt As Currency)

If curBalance < vTranAmt Then

RaiseEvent InsufficientFunds

Else

curBalance = curBalance - vTranAmt

End If

End Sub

 

Public Sub Deposit(ByVal vTranAmt As Currency)

curBalance = curBalance + vTranAmt

End Sub

 

 

VB6convertraise

 

Option Strict Off

Option Explicit On

Friend Class frmItemSet

Inherits System.Windows.Forms.Form

 

'This code instanciates the new object which means it sets up the memory

'location and the references, however the new object does not actually get

'created until it is refered to in the project.

Private WithEvents mItem As CItemSet

Dim wkMsg As String

Private Sub cmdChangeCost_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdChangeCost.Click

Dim intChangeCost As Short

intChangeCost = Val(InputBox("What is the new cost?", "Change Cost"))

mItem.ChangeCost(intChangeCost)

txtCost.Text = CStr(mItem.Cost)

End Sub

Private Sub cmdExit_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdExit.Click

Me.Close()

End Sub

Private Sub cmdReceive_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReceive.Click

Dim intNewAmt As Short

intNewAmt = Val(InputBox("How many were received?", "Inventory Receipt"))

'This calls the objects method which I coded

mItem.ReceiveItem(intNewAmt)

txtOnHand.Text = CStr(mItem.OnHand)

txtOnOrder.Text = CStr(mItem.OnOrder)

End Sub

Private Sub cmdSellProduct_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSellProduct.Click

Dim intAmtSold As Short

intAmtSold = Val(InputBox("How many were sold?", "Inventory Sale"))

mItem.SellProduct(intAmtSold)

txtOnHand.Text = CStr(mItem.OnHand)

End Sub

Private Sub frmItemSet_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

mItem = New CItemSet

txtOnHand.Text = CStr(500)

txtOnOrder.Text = CStr(250)

txtCost.Text = CStr(75)

mItem.OnHand = Val(txtOnHand.Text)

mItem.OnOrder = Val(txtOnOrder.Text)

mItem.Cost = Val(txtCost.Text)

End Sub

'UPGRADE_WARNING: Form event frmItemSet.Unload has a new behavior. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup2065"'

Private Sub frmItemSet_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed

'This releases the object reference

'UPGRADE_NOTE: Object mItem may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="vbup1029"'

mItem = Nothing

End Sub

Private Sub mItem_NeedToOrder() Handles mItem.NeedToOrder

wkMsg = "Quantity below reorder point of 50"

MsgBox(wkMsg, MsgBoxStyle.Exclamation, "Need to Order")

End Sub

Private Sub mItem_NothingOnOrder() Handles mItem.NothingOnOrder

wkMsg = "There is nothing on order"

MsgBox(wkMsg, MsgBoxStyle.Information, "No Order Pending")

End Sub

End Class

 

Option Strict Off

Option Explicit On

Friend Class CItemSet

Private modvarOnHand As Short

Private modvarOnOrder As Short

Private modvarCost As Short

Event NeedToOrder()

Event NothingOnOrder()

Public Property OnHand() As Short

Get

'Retrieve the current onhand value

OnHand = modvarOnHand

End Get

Set(ByVal Value As Short)

'Assign the onhand property value

modvarOnHand = Value

If modvarOnHand < 50 Then

RaiseEvent NeedToOrder()

End If

End Set

End Property

Public Property OnOrder() As Short

Get

OnOrder = modvarOnOrder

End Get

Set(ByVal Value As Short)

modvarOnOrder = Value

If modvarOnOrder = 0 Then

RaiseEvent NothingOnOrder()

End If

End Set

End Property

Public Property Cost() As Short

Get

Cost = modvarCost

End Get

Set(ByVal Value As Short)

modvarCost = Value

End Set

End Property

Public Sub ReceiveItem(ByRef intNewAmt As Short)

'Increase on hand and decrease on order

modvarOnHand = modvarOnHand + intNewAmt

If modvarOnHand < 50 Then

RaiseEvent NeedToOrder()

End If

modvarOnOrder = modvarOnOrder - intNewAmt

If modvarOnOrder = 0 Then

RaiseEvent NothingOnOrder()

End If

End Sub

Public Sub ChangeCost(ByRef intNewCost As Short)

modvarCost = intNewCost

End Sub

Public Sub SellProduct(ByRef intSold As Short)

'Decrease on hand

modvarOnHand = modvarOnHand - intSold

If modvarOnHand < 50 Then

RaiseEvent NeedToOrder()

End If

End Sub

End Class