Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Problem with code


Reply
 
Thread Tools Display Modes
  #1  
Old 02-05-2002, 11:19 AM
tigerlilly
Guest
 
Posts: n/a
Default Problem with code


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

Code:
 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
Edit: Add code tags
Attached Files
File Type: zip depreciation.zip (2.7 KB, 8 views)

Last edited by Flyguy; 02-05-2002 at 02:41 PM.
Reply With Quote
  #2  
Old 02-05-2002, 12:44 PM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Is there a specific problem?

Ps - when posting code, use the [ code ][ /code ] tags... (remove the spaces)
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->