#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Error in program I need to Alter for class..


    I'm new to programming in general, but I'd appreciate help from anyone. I've spent a good hour and can't figure out why I keep receiving errors in this vb application. The code is listed below.
    The error I receive is-

    " Error 1 Value of type 'String' cannot be converted to 'System.Windows.Forms.Label'."


    Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
    End Sub

    Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
    ' calculates the ending balance based on the beginning
    ' balance, amount earned, and amount spent

    Dim decBegin As Decimal
    Dim decEarned As Decimal
    Dim decSpent As Decimal
    Dim decEnding As Decimal

    ' assign input to variables
    Decimal.TryParse(txtBegin.Text, decBegin)
    Decimal.TryParse(txtSpent.Text, decSpent)

    ' calculate and display ending balance
    decEnding = decBegin + decEarned - decSpent
    lblEnding = decEnding.ToString("C2")
    End Sub
    End Class
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Looks like you're trying to assign a string value to the label object instead of the label object's text property ...
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    44
    I would be guessing, but it looks like you are trying to assign a value to a label. Label controls don't have a default property like Text boxes (.Text). You need to define a property (eg. lblEnding.Caption).

    J.A. Coutts
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Okay so I have it in a semi functional state, however the program refuses to add the money earned even though it is declared in decEnding. It can recognize the beginning balance as well as the money spent, but it does not recognize the money earned and just notes it as a 0 no matter what. Heres my updated code, thanks for your help I appreciate it. I don't expect an answer but a clue would help. Since I'm a new user I can't post a link but its just your basic looking app beginning balance on top, money earned inbetween, and money spent at the bottom. The ending balance is then displayed below.



    Public Class frmMain

    Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
    End Sub

    Private Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
    ' calculates the ending balance based on the beginning
    ' balance, amount earned, and amount spent

    Dim decBegin As Decimal
    Dim decEarned As Decimal
    Dim decSpent As Decimal
    Dim decEnding As Decimal

    ' assign input to variables
    Decimal.TryParse(txtBegin.Text, decBegin)
    Decimal.TryParse(txtSpent.Text, decSpent)

    ' calculate and display ending balance
    decEnding = decBegin + decEarned - decSpent
    lblEnding.Text = decEnding.ToString("C2")

    End Sub

    Private Sub txtEarned_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEarned.TextChanged

    End Sub
    End Class
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Location
    Terlingua, TX
    Posts
    15
    Rep Power
    0
    While I may be missing the obvious, you create decSpent and decBegin ...
    Might it not be wise to calculate decEarned - of course it's going to be a zero if you don't get it from somewhere ... no??

IMN logo majestic logo threadwatch logo seochat tools logo