Formatting Variables in Form


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: Formatting Variables in Form

Threaded View

  1. #1
    Join Date
    Jun 2005
    Location
    Boca Raton, Florida, USA
    Posts
    11

    Formatting Variables in Form

    Gentlemen:

    I face two issues with the code below for a Loan Calc application, my first, and they relate to:

    1. I would like all textboxes to display with proper format, however the Rate Function applied here will halt the operation after the initial calcuation if I then decide to clear any of the 1 to 6 variables, and re-enter a new factor.
    THe appl. will then zero out the Other Costs box, &/or halt due to an invalid procedure call.

    Below is described the changes made to get the operation to work, but I would nevertheless like to learn how to format the Price and Other Costs textboxes as finally displayed in the form.

    2. I also have remmed out the Keystroke sections as these are not permiting me to use the Debug feature to test the application.

    THe form has other uncoded as yet features that I will add later.

    I have resolved the conflicit in the latest Loan Calc VB6 application. I was formatting the Price Textbox which is the kingpin in the calculations, and so when I clear any of the 6 variables numbered 1 through 6 on the left of each variable either the Rate function formula would halt the operation as an invalid porcedure call, or the Other COsts textbox would be zeroed out.

    I now changed the formatting in the code for the Price, and the Other Costs textboxes and all is well again.



    Option Explicit

    Private Sub CmdCalculate_Click()

    Dim Price As Currency
    Dim DwnPmt As Double
    Dim principal As Currency
    Dim fRate As Double
    Dim Term As Long
    Dim payment As Currency
    Dim Points As Double
    Dim Costs As Currency
    Dim PmtwCosts As Currency
    Dim APR As Single
    Dim Loanwcosts As Currency
    Dim FutureValue As Currency
    Dim FVal As Currency
    Dim PayType As Integer
    Dim Guess As Double


    If Trim(TxtPrice.Text) = "" Then
    MsgBox "Enter a Price"
    TxtPrice.SetFocus
    Exit Sub
    End If
    If Trim(TxtDwnPmt.Text) = "" Then
    MsgBox "Enter a Down Payment"
    TxtDwnPmt.SetFocus
    Exit Sub
    End If

    If Trim(TxtfRate.Text) = "" Then
    MsgBox "Enter an Interest Rate"
    TxtfRate.SetFocus
    Exit Sub
    End If
    If Trim(TxtTerm.Text) = "" Then
    MsgBox "Enter a Term"
    TxtTerm.SetFocus
    Exit Sub
    End If
    If Trim(TxtPoints.Text) = "" Then
    MsgBox "Enter the Points"
    TxtPoints.SetFocus
    Exit Sub
    End If
    If Trim(TxtCosts.Text) = "" Then
    MsgBox "Enter the additional Costs"
    TxtCosts.SetFocus
    Exit Sub
    End If

    Price = Val(TxtPrice.Text) 'this is the purchase price
    'TxtPrice = FormatCurrency(Price)
    DwnPmt = Val(TxtDwnPmt.Text) / 100 'converts the dwon payment to value based on the purchase price
    TxtDwnPmt = Format(DwnPmt, "#0.00000%")
    principal = (Price * (1 - DwnPmt)) 'determines the loan amount after the down payment
    TxtPrincipal = FormatCurrency(principal)
    fRate = Val(TxtfRate.Text) / 100
    fRate = fRate / 12 'Converts the annual interest rate to a monthly rate
    TxtfRate.Text = Format(fRate * 12, "#0.00000%")
    Term = Val(TxtTerm.Text) * 12 'Converts the life of the loan from years to months
    payment = principal * (fRate / (1 - (1 + fRate) ^ -Term)) 'Computes the Monthly Payment & interest
    TxtPayment.Text = Format(payment, "$###,000.00")
    Points = Val(TxtPoints.Text) / 100 'Points are often paid to get favorable Interest Rates
    TxtPoints = FormatPercent(Points)
    Costs = Val(TxtCosts.Text) 'This covers all types of closing loan costs & other concepts
    'TxtCosts = FormatCurrency(Costs)
    PmtwCosts = principal + (principal * Points) + Costs ' This includes Intial Pmt + all other costs

    Loanwcosts = PmtwCosts * (fRate / (1 - (1 + fRate) ^ -Term)) ' This calculates the Pmt with all other costs
    TxtPmtWCosts = FormatCurrency(Loanwcosts)
    FVal = 0 'Normally for this exercise the Future Value is zero
    PayType = 0 ' 0 = Payment at end of Month; 1 = Payment at the beginning of the Month
    Guess = InputBox("What is your best guess-estimate of the Interest Rate expressed as a decimal {For example 10% would be .10}?") 'Prompts for Guess Rate
    APR = (Rate(Term, -Loanwcosts, principal, FVal, PayType, Guess) * 12) * 100 'Computes APR
    TxtAPR.Text = Format(APR / 100, "#0.00000%")

    End Sub


    Private Sub cmdClear_Click()

    TxtPrice.Text = vbNullString
    TxtDwnPmt.Text = vbNullString
    TxtPrincipal.Text = vbNullString
    TxtfRate.Text = vbNullString
    TxtTerm.Text = vbNullString
    TxtPayment.Text = vbNullString
    TxtPoints.Text = vbNullString
    TxtCosts.Text = vbNullString
    TxtPmtWCosts = vbNullString
    TxtAPR.Text = vbNullString
    TxtPrice.SetFocus

    End Sub

    Private Sub CmdClearDwnPmt_Click()
    TxtDwnPmt.Text = vbNullString

    End Sub

    Private Sub CmdClearOCosts_Click()
    TxtCosts.Text = vbNullString
    End Sub

    Private Sub CMdClearPoints_Click()
    TxtPoints.Text = vbNullString
    End Sub

    Private Sub CmdClearPrice_Click()
    TxtPrice.Text = vbNullString
    End Sub

    Private Sub CmdClearRate_Click()
    TxtfRate.Text = vbNullString
    End Sub

    Private Sub CMdClearTerm_Click()
    TxtTerm.Text = vbNullString
    End Sub

    Private Sub CmdExit_Click()
    Unload Me
    End Sub

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    If MsgBox("Are you sure that you'd like to exit?", vbInformation + vbYesNo, App.Title) = vbYes Then
    End
    Else
    Cancel = 1
    End If

    End Sub

    'Private Sub TxtRate_KeyPress(KeyAscii As Integer)


    'Select Case Chr(KeyAscii)
    ' Case "0" To "9" 'Allow numbers
    ' Case "." 'Allow "."
    ' Case "," 'Allow ","
    ' Case vbBack 'allows backspace to function
    ' Case Else
    ' KeyAscii = 0
    'End Select

    'End Sub

    'Private Sub TxtPrincipal_KeyPress(KeyAscii As Integer)

    'Select Case Chr(KeyAscii)
    ' Case "0" To "9" 'Allow numbers
    ' Case "." 'Allow "."
    ' Case "," 'Allow ","
    ' Case vbBack 'allows backspace to function
    ' Case Else
    ' KeyAscii = 0
    'End Select

    'End Sub

    'Private Sub TxtTerm_KeyPress(KeyAscii As Integer)

    'Select Case Chr(KeyAscii)
    ' Case "0" To "9" 'Allow numbers
    ' Case "." 'Allow "."
    ' Case "," 'Allow ","
    ' Case vbBack 'allows backspace to function
    ' Case Else
    ' KeyAscii = 0
    'End Select

    'End Sub


    'Private Sub Txtmax_Change()
    'LenMax = Val(Txtmax.Text)
    'End Sub

    Private Sub MenuPmts_Click()

    End Sub
    Attached Files Attached Files
    Respectfully,
    Herman Ortiz

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center