0% found this document useful (0 votes)
27 views

Chapter 5 Code

"You've gone over budget." "you need to work some overtime." "remember to pay your taxes" "this module displays a message box on the screen"
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Chapter 5 Code

"You've gone over budget." "you need to work some overtime." "remember to pay your taxes" "this module displays a message box on the screen"
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Option Compare Database

Private blnUnderBudget As Boolean


Private blnOverBudget As Boolean
Const curBudget = 1000
Private Sub GoShoppingSuits()
Dim intSuits As Integer
Dim curSuitPrice As Currency
Dim curTotalPrice As Currency
curSuitPrice = 100
intSuits = InputBox("Enter the desired number of suits", "Suits")
For i = 1 To intSuits
curTotalPrice = curTotalPrice + curSuitPrice
If curTotalPrice > curBudget Then
blnOverBudget = True
Else
blnUnderBudget = False
End If
Next
If blnUnderBudget = False Then
OverBudget
End If
End Sub
Private Sub OverBudget()
Debug.Print "You've gone over budget."
Debug.Print "You need to work some overtime."
Debug.Print "Remember to pay your taxes."
End Sub
Private Sub GoShopping()
Dim intSuits As Integer
Dim curSuitPrice As Currency
Dim curTotalPrice As Currency
curSuitPrice = 100
intSuits = InputBox("Enter the desired number of suits", "Suits")
For i = 1 To intSuits
curTotalPrice = curTotalPrice + curSuitPrice
If curTotalPrice > curBudget Then
blnUnderBudget = False
Else
blnUnderBudget = True
End If
Debug.Assert blnUnderBudget
Next
End Sub
Private Sub DisplayMessageBox()
'This module displays a message box on the screen
Dim intNumRecords As Integer
Dim intNumCustomers As Integer
Dim dtOrderDate As Date
Dim txtCustomerName As String
Dim txtCustomerAddress As String
Dim txtCustomerStreet As String
Dim txtCustomerZip As String
Dim txtCustomerState As String
Dim i As Integer
For i = 1 To 10
txtCustomerName = "ABC Exports"
Next
End Sub
Private Sub OpenDatabaseConnection()
Dim objConn As ADODB.Connection
Dim objRST As ADODB.Recordset
Dim strSQL As String
Dim strConn As String
Dim strState As String
Set objConn = CreateObject("ADODB.Connection")
Set objRST = CreateObject("ADODB.Recordset")
strState = "California"
strState = InputBox("Please enter a state", "EnterState")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Databases\Addresses.m
db;"
strSQL = "SELECT [CustomerName], [CustomerCode], [CustomerAddress1]" _
& ", [CustomerCity], [CustomerState], [CustomerZip] FROM" _
& "Customers WHERE [CustomerState] is Not Null;"

strSQL = "Select * from tblCustomers WHERE CustomerState = '" & strState & "';"
objConn.Open (strConn)
objConn.Mode = adModeRead
objRST.Open strSQL, objConn, adOpenForwardOnly, adLockOptimistic
objRST.MoveFirst
While Not objRST.EOF
Debug.Print objRST.Fields("CustomerName")
Debug.Print objRST.Fields("CustomerState")
Debug.Print objRST.Fields("CustomerCountry")
objRST.MoveNext
Wend
objRST.Close
objConn.Close
Set objRST = Nothing
Set objConn = Nothing
End Sub
Sub CoffeeTime()
Dim curLatteAllowance As Currency
Dim curLattePrice As Currency
Dim intNumLattes As Integer
Dim curTotalExpenses As Currency
curLattePrice = 3.5
curLatteAllowance = InputBox("Enter the amount of money you have for lattes." _
, "Latte Allowance")
While curTotalExpenses < curLatteAllowance
intNumLattes = intNumLattes + 1
curTotalExpenses = curTotalExpenses + curLattePrice
Wend
Debug.Print intNumLattes
MsgBox "You can purchase " & intNumLattes & " lattes.", _
vbOKOnly, "Total Lattes"

End Sub

You might also like