I try not to use SQL, as it is complicated.
How to set upMake a form, put 3 option buttons on it (named Option1,2 and 3) and a button named Command1.
Recommended to edit the Option button captions to "Economy","Compact" and "Standard" respectively.
What this program doReads rental rates from a text file (rates.txt, in the same directory as the EXE file) in the order of Economy, Compact and Standard. Each category will have 1 value. Each value will be seperated with a new line.
What I assumeThe rates are by daily basis, calculated by multiplying rate by day.
code:
Public Rates(2) as Integer
Public RentDays as Integer
Public CatType as Integer
Public ErrMet as Boolean
'Add more as required, counts from zero instead of one, so this can store 6 values.
Private Sub Form_Load()
'Executed when program starts up
ReadFile
If ErrMet = True then
End 'end program as not all values needed are there.
End If
End Sub
Private Sub Command1_Click()
On Error Goto ErrorH: 'in case of any error
'Asks user for number of days.
RentDays = Inputbox("Please enter the number of days","Number of days" )
'In case some dumb user enter 0
If RentDays < 0 Then
Msgbox "Please enter a valid number.",vbExclamation,"Invalid number!"
Exit Sub 'exits the current code
Else 'if everything in order, ask for category.
CatType = InputBox("Please enter categoy type." & vbCrLf & "1 = Economy" & vbCrLf & "2 = Compact" & vbCrLf & "3 = Standard","Enter category number")
If CatType < 0 Then
Msgbox "Please enter a valid number.",vbExclamation,"Invalid number!"
Else
Msgbox CatAnalyze
End If
End If
ErrorH: 'error handler
Msgbox "Input error " & Err.Number & " " & Err.Description,vbCritical,"Input Error!"
End Sub
Private Function ReadFile()
Dim tempString as String
Dim x as Integer
x = 0
If Dir$(App.Path & "\rates.txt" ) = "" Then 'if rates file do not exist
Msgbox "Unable to find Rates.txt in the directory of this EXE.",vbExclamation,"Rates file not found"
ErrMet = True
Exit Function
Open App.Path & "\rates.txt" For Input As 1
While Not EOF(1)
Line Input #1, tempString
Rates(x) = tempString
x = x + 1
Wend
Close 1
'Check incase file do not contain all values empty...
For x = 0 to Rates().UBound
If Rates(x) = "" Then
Msgbox "Please ensure Rates.txt contain all required values.",vbExclamation,"Not all values present"
ErrMet = True
Exit Function
End If
Next
End If
End Function
Private Function CatAnalyze()
CatAnalyze = Rates(CatType - 1) * RentDays
End Function