Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 11th, 2012, 02:49 AM
braddey braddey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 2 braddey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old September 11th, 2012, 10:43 AM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,938 medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)  Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Months 2 Weeks 2 Days 19 m 8 sec
Reputation Power: 8490
Facebook
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

Reply With Quote
  #3  
Old September 11th, 2012, 10:58 AM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 165 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 16 h 44 m 37 sec
Reputation Power: 43
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

Reply With Quote
  #4  
Old September 11th, 2012, 08:48 PM
braddey braddey is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Posts: 2 braddey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old September 23rd, 2012, 02:58 PM
aljones aljones is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2012
Location: Terlingua, TX
Posts: 15 aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level)aljones User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 50 m 3 sec
Reputation 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??

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Error in program I need to Alter for class..

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap