help with the syntax of my code

I wanna fix the syntax but Im no professional when it comes to vb.net

Page 1 of 1

7 Replies - 525 Views - Last Post: 24 January 2010 - 09:58 PM Rate Topic: -----

#1 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

help with the syntax of my code

Posted 24 January 2010 - 12:45 PM

I was working on a calculator for pieceworkers...I got most of the code implemented but I came up with build errors that would not let me continue, since I don't know how to fix the build errors, I am stuck. Any help would be appreciated...

Public Class Form1

	Private Sub SummaryBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryBut.Click
		Dim PiecesProdTxtbox As Integer
		Dim TotalPayTxtbox As Integer
		Dim PiecesCostTxtbox As Integer
		Dim AvgPayPerPersonTxtbox As Integer
		Dim MsgCenterTxtbox As String
		'this is a simple case select procedure to determine 
		'the cost of each piece.
		Select Case PiecesProdTxtbox
			Case "PiecesProdTxtbox <= 199"
				PiecesCostTxtbox = ".50"
			Case "PiecesProdTxtbox <= 399"
				PiecesCostTxtbox = ".55"
			Case "PiecesProdTxtbox <= 599"
				PiecesCostTxtbox = ".60"
			Case "PiecesProdTxtbox >= 600"
				PiecesCostTxtbox = ".65"
			Case Else
				MsgCenterTxtbox = "Invalid Input"
		End Select
		'this next line is to multiply the piece cost times the 
		'pieces produced resulting in the total Pay for said pieceworker
		 PiecesProdTxtbox * PiecesCostTxtbox = TotalPayTxtbox

		'this line of code divides Total Pay by Total number of pieces 
		'to get Average pay per pieceworker.
		 TotalPayTxtbox / PiecesProdTxtbox = AvgPayPerPersonTxtbox



	End Sub

	Private Sub CalcBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalcBut.Click
		Dim PiecesCostTxtbox As Integer
		Dim PiecesProdTxtbox As Integer
		Dim MsgCenterTxtbox As String
		Dim TotalDollarsEarnedTxtbox As Decimal

		Select Case PiecesProdTxtbox
			Case "PiecesProdTxtbox <= 199"
				PiecesCostTxtbox = ".50"
			Case "PiecesProdTxtbox <= 399"
				PiecesCostTxtbox = ".55"
			Case "PiecesProdTxtbox <= 599"
				PiecesCostTxtbox = ".60"
			Case "PiecesProdTxtbox >= 600"
				PiecesCostTxtbox = ".65"
			Case Else
				MsgCenterTxtbox = "Invalid Input"
		End Select
		(PiecesCostTxtbox * PiecesProdTxtbox = TotalDollarsEarnedTxtbox)
		'I really wanna find a way to keep the case structure from being enabled 
		'in this button's code since it is already used with the summary button
	End Sub

	Private Sub ClearBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearBut.Click
		TotalDollarsEarnedTxtbox.Clear()
		NameTxtbox.Clear()
		PiecesProdTxtbox.Clear()
	End Sub

	Private Sub ClearAllBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearAllBut.Click
		PiecesCostTxtbox.Clear()
		TotalPayTxtbox.Clear()
		AvgPayPerPersonTxtbox.Clear()


	End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: help with the syntax of my code

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: help with the syntax of my code

Posted 24 January 2010 - 12:52 PM

Please post the error(s). We can't suggest how to fix them if we don't know what they are.

This post has been edited by n8wxs: 24 January 2010 - 12:52 PM

Was This Post Helpful? 0
  • +
  • -

#3 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: help with the syntax of my code

Posted 24 January 2010 - 01:12 PM

Best I can tell, I think I'm mainly having issues with the conversion of my data types. It keeps telling me
Invalid Cast Exception was unhandled

This post has been edited by kweef19: 24 January 2010 - 01:15 PM

Was This Post Helpful? 0
  • +
  • -

#4 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: help with the syntax of my code

Posted 24 January 2010 - 04:44 PM

I guess I'll look at a few tuts and see if I can fix some of the problems...
Was This Post Helpful? 0
  • +
  • -

#5 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: help with the syntax of my code

Posted 24 January 2010 - 06:22 PM

I think your problem is here:
(PiecesCostTxtbox * PiecesProdTxtbox = TotalDollarsEarnedTxtbox)


and here:
TotalPayTxtbox / PiecesProdTxtbox = AvgPayPerPersonTxtbox


and here:
TotalPayTxtbox / PiecesProdTxtbox = AvgPayPerPersonTxtbox



Should be:
TotalDollarsEarnedTxtbox = PiecesCostTxtbox * PiecesProdTxtbox


and
AvgPayPerPersonTxtbox = TotalPayTxtbox / PiecesProdTxtbox


and
AvgPayPerPersonTxtbox = TotalPayTxtbox / PiecesProdTxtbox


Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,413
  • Joined: 29-May 08

Re: help with the syntax of my code

Posted 24 January 2010 - 07:24 PM

Your coding problems stem from an a basic misunderstanding of textboxes, to you (as a human) see a number but to the computer that same textboxes contains a bunch of characters (a string).

Strings are different to numbers (Integer & Double are examples of different Types of Number vb.net understands)

So you need to convert the textbox contents in to number type, this is called parseing.


Dim MyNumber As Double
If Double.TryParse(Textbox1.Text,MyNumber) Then
 ' MyNumber contains a valid double
Else
 ' The text (string) can not be parsed as a double.

EndIf 



See: My BlogPost on the subject
Was This Post Helpful? 0
  • +
  • -

#7 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: help with the syntax of my code

Posted 24 January 2010 - 09:52 PM

Could you possibly point me in the right direction to a tut of parsing so I can try and learn how to use it???
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,413
  • Joined: 29-May 08

Re: help with the syntax of my code

Posted 24 January 2010 - 09:58 PM

There are two in my previous post;- the code and the blog post.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1