Results 1 to 4 of 4

Thread: val(text1.text) - Help Please (Financial Calculator)

  1. #1

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262

    Lightbulb

    Here is a snippet of my code for a financial calculator program. The Val(lstInterest.Text) works if the interest rate does not contain a number after the decimal point. (7.00%) However, if the text contains a number (7.25%), then I get a type mismatch error.

    Any Ideas???

    Code:
    Dim MonPmt As Double, dblRate As Double, intPmts As Integer, dblPrncpl As Double
    
    Public Sub Interest()
    dblPrncpl = txtPrincipal.Text
    dblRate = Val(lstInterest.Text)
    dblRate = dblRate / 100
    MonPmt = Pmt(dblRate / 12, intPmts, -dblPrncpl)
    lblPayment = Format(MonPmt, "$###,###,##0.00")
    
    End Sub
    Private Sub cmdCalc_Click()
    
    Interest
    
    End Sub
    
    Private Sub Form_Load()
        frmMthlyPay.Left = (Screen.Width - frmMthlyPay.Width) / 2
        frmMthlyPay.Top = (Screen.Height - frmMthlyPay.Height) / 2
    End Sub
    
    
    Private Sub mnuFileExit_Click()
    End
    End Sub
    
    Private Sub mnuFilePrint_Click()
    frmMthlyPay.PrintForm
    End Sub
    
    Private Sub mnuFormatBackground_Click()
    dlgCommon.Flags = cdlCCRGBInit
    dlgCommon.ShowColor
    frmMthlyPay.BackColor = dlgCommon.Color
    End Sub
    
    Private Sub mnuFormatFont_Click()
    dlgCommon.Flags = cdlCFBoth
    
    dlgCommon.FontName = lblPayment.FontName
    dlgCommon.FontBold = lblPayment.FontBold
    dlgCommon.FontItalic = lblPayment.FontItalic
    dlgCommon.FontSize = lblPayment.FontSize
    
    lblPayment.FontName = dlgCommon.FontName
    lblPayment.FontBold = dlgCommon.FontBold
    lblPayment.FontItalic = dlgCommon.FontItalic
    lblPayment.FontSize = dlgCommon.FontSize
    dlgCommon.ShowFont
    End Sub
    
    Private Sub mnuFormatInfo_Click()
    dlgCommon.Flags = cdlCCRGBInit
    dlgCommon.ShowColor
    fraInfo.BackColor = dlgCommon.Color
    End Sub
    
    Private Sub optTerm_Click(Index As Integer)
    Select Case Index
    Case 0
    intPmts = 24
    Case 1
    intPmts = 36
    Case 2
    intPmts = 48
    Case 3
    intPmts = 60
    End Select
    End Sub
    VB-6 Professional Edition (Sp3)
    www.safemall.cc
    [email protected]

    Climb & Maintain FL410,
    Cleared Direct Rainr

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Where exactly? Type mismatches are very easy to track and get rid of, but i don't have your project so i can't tell you
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member Sal's Avatar
    Join Date
    Mar 2000
    Posts
    262
    It is on this line:

    Code:
    dblRate = Val(lstInterest)
    The variable creating the problem contains a percentage number with more than a zero after the problem. There is no error message if the user inputs say 7.00%. But if the input is 7.25% then there is a type mismatch.

    Hmmm
    Thanks for the help,
    Sal
    VB-6 Professional Edition (Sp3)
    www.safemall.cc
    [email protected]

    Climb & Maintain FL410,
    Cleared Direct Rainr

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    It doesn't accept the "%" so you can do this:
    dblRate = Val(left(lstInterest,len(lstInterest)-1))
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width