The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
Error in program I need to Alter for class..
Discuss Error in program I need to Alter for class.. in the Visual Basic Programming forum on Dev Shed. Error in program I need to Alter for class.. Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 11th, 2012, 02:49 AM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 2
Time spent in forums: 2 h 26 m
Reputation 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
|

September 11th, 2012, 10:43 AM
|
 |
Type Cast Exception
|
|
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
|
|
|
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
|

September 11th, 2012, 10:58 AM
|
|
|
|
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
|

September 11th, 2012, 08:48 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Posts: 2
Time spent in forums: 2 h 26 m
Reputation 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
|

September 23rd, 2012, 02:58 PM
|
|
Registered User
|
|
Join Date: Sep 2012
Location: Terlingua, TX
|
|
|
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??
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|