Problem with code

tigerlilly
02-05-2002, 11:19 AM
I posted this problem yesterday, I have included the code below and also the form is attached. I am having trouble with displaying the data and validating the fields. Can someone please help me with this code.
Thank You very much


Option Explicit
'Detail column width constants
Private Const cfyearswidth As Long = 10
Private Const cfdeprwidth As Long = 11
Private Const cfEOYvaluewidth As Long = 11
Private Const cfAccumDepwidth As Long = 11

Private fyears As Integer 'number of years
Private fdepr As Long 'depreciation
Private feoyvalue As Long 'end of year value
Private faccumdepr As Long 'accumulated depreciation
Private fprice As Currency
Private fsvalue As Currency

'Purpose: When the Calculate button is clicked, it displays the Year, Depreciation, end of year
'value, and the accumulated depreciation.
Private Sub cmdCalculate_Click()
Call DisplayHeader
Call DisplayDetail
cmdCalculate.Enabled = False

End If
End Sub

'Purpose: Terminates the program when the exit button is clicked.
Private Sub cmdexit_Click()
Unload frmMain
End Sub

'Purpose: Create a formated string containing year, depreciation, end of year value,
'Accumulated depreciation. Concatenate the string to the end of the txtschedule text property.

Private Sub DisplayDetail()
Dim I As Long
Dim AccumDep As Long
Dim EOY As Long
Dim decp As Long
'calculate and display detail 'This is where I am having trouble.
AccumDep = faccumdepr
For I = 1 To fyears
decp = (fprice - fsvalue) / fyears
If I < fyears Then
EOY = (fprice - AccumDep)
AccumDep = (decp * 2)

Else
EOY = 0
End If

'Build the formated detail line and add to the text box
txtschedule.Text = txtschedule.Text & vbNewLine & _
RightAlign(Format(I, "0"), cfyearswidth) & _
RightAlign(Format(decp, "0.00"), cfdeprwidth) & _
RightAlign(Format(EOY, "0.00"), cfEOYvaluewidth) & _
RightAlign(Format(AccumDep, "0.00"), cfAccumDepwidth)
End Sub

'Purpose: Create a formatted string containing two lines of header for the depreciation table.
'Assign the string to the text property of the txtschedule text box.
Private Sub DisplayHeader()
txtschedule.Text = RightAlign("EOY", cfEOYvaluewidth) & _
RightALign("Accum", cfAccumdepwidth) & vbNewLine & _
RightAlign("Year", cfyearswidth) & _
RightAlign("Depr", cfdeprwidth) & _
RightAlign("Value", cfEOYvaluewidth) & _
RightAlign("Depr", cfdeprwidth)
End Sub


'Purpose: Disable the Calculate button when the form is loaded
Private Sub Form_Load()
cmdCalculate.Enabled = False
ENd Sub

'Purpose: Validate the entry in the text box parameter. Return true if the entry is numeric and positive, otherwise place the focus
'on the text box, display an error message and return false. The second parameter is used to construct the error message.
Private Function IsNumericAndPositive(ByVal txtBox as Textbox, _
ByVal Item as String) As Boolean

If not Isnumeric(txtBox.text) then
Call MsgBox(Item & "Must be numeric", vbExclamation)
txtBox.Setfocus
IsNumericAndPositive = False
ElseIf CDbl(txtbox.text) <=0 Then
Call MsgBox(Item & " must be positive", vbExclamation)
txtBox.setfocus
IsNumericAndPositive = False
Else
IsNumericAndPositive = True
End IF
End Function


'Purpose: Validate the entry in the price, salvage value, years text box. The item is valid if it is numeric and positive
Private Function ValidateInputs() As Boolean
If Not ValidatePrice Then
ValidateInputs = False
ElseIf Not ValidateSalvageValue Then
ValidateInputs = False
Elseif Not ValidateYears Then
ValidateInputs = False
Else
ValidateInputs = True
End IF
End Function

'Purpose: Validate the entry in the price text box. The item is valid if it is numeric or positive
Private Function ValidatePrice() As Boolean
ValidatePrice = _
IsNumericAndPositive(txtprice, "Price")
End Function

'Purpose: Validate the entry in the Salvage value text box. The item is valid if it is numeric and positive.
Private Function ValidateSalvageValue() As Boolean
ValidateSalvageValue = _
IsNumericAndPositive(txtsvalue, "Salvage Value")
End Function

'Purpose: Validate the entry in the Years text box. The item is valid if it is numeric, positive.
Private Function ValidateYears() As Boolean
If Not IsNumericAndPositive(txtyears, "Years") Then
ValidateYears = False
ElseIf Cdbl(txtyears.text) <> Int(txtyears.text) Then
Call MsgBox("Years must be an integer", vbExclamation)
txtyears.setfocus\
ValidateYears= False
Else
ValidateYears = True
End If
End Function


Add code tags

ChiefRedBull
02-05-2002, 12:44 PM
Is there a specific problem?

Ps - when posting code, use the [ code ][ /code ] tags... (remove the spaces)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum