By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Could some one help me Having Major issue with trying to figure out coding buttons

P: 11
5. When the “Accumulate” button is clicked:
i. You are to keep grand totals for the Hours and Amount Due for each type of Package.
i. This requires three class-level variables for the Hours, i.e. one for the Package A hours, one for the Package B hours, and one for the Package C hours.
ii. Similarly, you will need three class-level variables for the Amounts.
j. Check the RadioButtons to see which Package is selected and add the Hours and Amount Due into the corresponding set of class-level variables.
k. Also, disable the “Accumulate” button.

6. When the “Reset” button is clicked, display a MessageBox asking to verify the reset:
l. Include “OK” and “CANCEL” buttons.
m. If “OK” clicked, then:
i. Clear all Textboxes & Labels.
ii. Reset all RadioButtons & CheckBoxes.
iii. Reset the title bar to its original value.
iv. Enable the “Validate” button.
v. Disable the “Calculate” and “Accumulate” buttons.
n. If “CANCEL” clicked, then leave the form alone and exit.

7. When the “Exit” button is clicked:
o. Use a MessageBox to display the grand totals for each type of Package.
p. Close the form.




that is what I need to do and this is what I have.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub btnCustomer_Click(sender As Object, e As EventArgs) Handles btnCustomer.Click
  2.         btnCustomer.Enabled = True
  3.         btnCharges.Enabled = False
  4.         Dim lastName As String = Nothing
  5.         Dim spaceCharPos As Integer = txtName.Text.IndexOf(" ")
  6.         If spaceCharPos > -1 Then
  7.             lastName = txtName.Text.Substring(spaceCharPos)
  8.         End If
  9.         If txtName.Text = String.Empty Then
  10.             MessageBox.Show("Please enter your first and last name.")
  11.             txtName.Focus()
  12.         End If
  13.  
  14.  
  15.         If txtName.Text.IndexOf(" ") = -1 Then
  16.             MessageBox.Show("Please put a space between First and Last name.")
  17.         End If
  18.  
  19.         Dim city As String = Nothing
  20.         Dim commaCharPos As Integer = txtCityState.Text.IndexOf(",")
  21.         If commaCharPos > -1 Then
  22.             city = txtCityState.Text.Substring(0, commaCharPos)
  23.         End If
  24.         If txtCityState.Text = String.Empty Then
  25.             MessageBox.Show("Please enter your City and State")
  26.             txtCityState.Focus()
  27.         End If
  28.  
  29.  
  30.         If txtCityState.Text.IndexOf(",") = -1 Then
  31.             MessageBox.Show("Please insert a comma between Clity & State.")
  32.         End If
  33.  
  34.         Me.Text = lastName & " from " & city
  35.         btnCustomer.Enabled = False
  36.         btnCharges.Enabled = True
  37.         btnTotals.Enabled = True
  38.  
  39.     End Sub
  40.     Private Sub btnCharges_Click(sender As Object, e As EventArgs) Handles btnCharges.Click
  41.         btnCharges.Enabled = True
  42.         btnCustomer.Enabled = False
  43.  
  44.         Dim decTotal As Decimal
  45.         Dim intHours As Integer
  46.         Const decNonProfit As Decimal = 0.8D
  47.  
  48.             intHours = CInt(txtHours.Text)
  49.  
  50.             If CInt(txtHours.Text) > 744 Then
  51.                 MessageBox.Show("Monthly Hours Can't Exceed 744")
  52.                 txtHours.Text = String.Empty
  53.                 lblAmountDue.Text = String.Empty
  54.             End If
  55.             If radA.Checked = False Then
  56.             ElseIf radB.Checked = False Then
  57.             ElseIf radC.Checked = False Then
  58.  
  59.                 MessageBox.Show("Please select an internet package to proceed")
  60.                 btnTotals.Enabled = False
  61.             End If
  62.  
  63.  
  64.  
  65.             If radA.Checked Then
  66.                 If intHours > 10 Then
  67.                     decTotal = CDec((9.95 + ((intHours - 10) * 2)))
  68.                 ElseIf intHours <= 10 Then
  69.                     decTotal = CDec(9.95)
  70.                 End If
  71.             End If
  72.  
  73.             If radB.Checked Then
  74.                 If intHours > 20 Then
  75.                     decTotal = CDec((14.95 + ((intHours - 20) * 1)))
  76.                 ElseIf intHours <= 20 Then
  77.                     decTotal = CDec(14.95)
  78.                 End If
  79.         End If
  80.  
  81.             If radC.Checked Then
  82.                 decTotal = CDec(19.95)
  83.             End If
  84.  
  85.             If chkNonProfit.Checked = True Then
  86.                 decTotal = decTotal * decNonProfit
  87.  
  88.             End If
  89.  
  90.             lblAmountDue.Text = decTotal.ToString("c")
  91.  
  92.     End Sub
  93.  
  94.     Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
  95.         radA.Checked = False
  96.         radB.Checked = False
  97.         radC.Checked = False
  98.         chkNonProfit.Checked = False
  99.         lblAmountDue.Text = String.Empty
  100.         txtHours.Text = String.Empty
  101.         txtName.Clear()
  102.         txtCityState.Clear()
  103.         txtName.Focus()
  104.         btnCustomer.Enabled = True
  105.         btnCharges.Enabled = False
  106.         btnTotals.Enabled = False
  107.         VarGetInput()
  108.     End Sub
  109.  
  110.     Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
  111.         Dim GrandTotal As Integer
  112.         Dim decPackA, decPackB, decPackC As Decimal
  113.  
  114.         GrandTotal = CInt(decPackA + decPackB + decPackC)
  115.  
  116.         GrandTotal = CInt("Package A: " & decPackA.ToString("c"))
  117.         GrandTotal = CInt("Package B: " & decPackB.ToString("c"))
  118.         GrandTotal = CInt("Package C: " & decPackC.ToString("c"))
  119.         GrandTotal = CInt("Grand Total:" & GrandTotal.ToString("C"))
  120.  
  121.     End Sub
  122. End Class
Mar 14 '16 #1
Share this Question
Share on Google+
13 Replies


100+
P: 299
You have not stated what kind of error you're getting, what's not working, or where exactly in the code you're having an issue. A little more detail would be mighty helpful.


You also have quite a bit of cleanup that can be done to make your code easier to look at to decipher what's going on. See below for examples:


This:
Expand|Select|Wrap|Line Numbers
  1. If radA.Checked = False Then
  2.  ElseIf radB.Checked = False Then
  3.  ElseIf radC.Checked = False Then
  4.  
  5.  MessageBox.Show("Please select an internet package to proceed")
  6.  btnTotals.Enabled = False
  7.  End If
To This:
Expand|Select|Wrap|Line Numbers
  1. If radA.Checked = False andAlso radB.Checked = False andAlso radC.Checked = False Then
  2.   MessageBox.Show("Please select an internet package to proceed")
  3.   btnTotals.Enabled = False
  4. End If
and This:
Expand|Select|Wrap|Line Numbers
  1. If radA.Checked Then
  2.  If intHours > 10 Then
  3.  decTotal = CDec((9.95 + ((intHours - 10) * 2)))
  4.  ElseIf intHours <= 10 Then
  5.  decTotal = CDec(9.95)
  6.  End If
  7.  End If
  8.  
  9.  If radB.Checked Then
  10.  If intHours > 20 Then
  11.  decTotal = CDec((14.95 + ((intHours - 20) * 1)))
  12.  ElseIf intHours <= 20 Then
  13.  decTotal = CDec(14.95)
  14.  End If
  15.  End If
  16.  
To This:
Expand|Select|Wrap|Line Numbers
  1. If radA.Checked andAlso intHours > 10 Then
  2.   decTotal = CDec((9.95 + ((intHours - 10) * 2)))
  3. ElseIf radA.Checked andAlso intHours <= 10 Then
  4.   decTotal = CDec(9.95)
  5. End If
  6.  
  7. If radB.Checked andAlso intHours > 20 Then
  8.   decTotal = CDec((14.95 + ((intHours - 20) * 1)))
  9. ElseIf radB.Checked andAlso intHours <= 20 Then
  10.   decTotal = CDec(14.95)
  11. End If
Mar 14 '16 #2

P: 11
I think I figured out the getting a messagebox to work on my reset button but I am new to this and cannot seem to figure out a how to get the code the calculations on the accumulate and how to get the grand total working on the exit button for a message box. I am not using the right coding for any so the error messages are multiple. Like Conversion from string "Package A: $0.00" to type 'Integer' is not valid.
Mar 14 '16 #3

P: 11
thank you for that much easier and help more on it making sense
Mar 14 '16 #4

100+
P: 299
No problem. Your exit button can be cleaned up by doing the following, but please note, you're not actually specifying amounts for deckPackA, B, or C anywhere in your code:

Expand|Select|Wrap|Line Numbers
  1. MsgBox("Package A: " & decPackA & "c" & vbCrLf & "Package B: " & decPackB & "c" & vbCrLf & "Package C: " & decPackC & "c" & vbCrLf & "Grand Total: " & GrandTotal & "C")
Mar 14 '16 #5

P: 11
I know that is where the accumulate button comes in and I don't know how to do that.

When the “Accumulate” button is clicked:
i. You are to keep grand totals for the Hours and Amount Due for each type of Package.
i. This requires three class-level variables for the Hours, i.e. one for the Package A hours, one for the Package B hours, and one for the Package C hours.
ii. Similarly, you will need three class-level variables for the Amounts.
j. Check the RadioButtons to see which Package is selected and add the Hours and Amount Due into the corresponding set of class-level variables.
k. Also, disable the “Accumulate” button.
Mar 14 '16 #6

100+
P: 299
I will try to find some time to help tomorrow unless someone else steps in. I don't have Visual Studio on my computer at home and my work day is over. Good luck and keep me up-to-date if you make any progress!
Mar 14 '16 #7

P: 11
I will do that and Thank you very much for your help
Mar 14 '16 #8

100+
P: 299
Good morning, ldelvoye. Below should help you in moving forward.

First things first, you need to declare 7 class variables. Three for package totals, three for package hours, and one for the grandtotal of cost. That would look like this:
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim decPackA As Integer
  3.     Dim decPackB As Integer
  4.     Dim decPackC As Integer
  5.     Dim decPackAHours As Integer
  6.     Dim decPackBHours As Integer
  7.     Dim decPackCHours As Integer
  8.     Dim GrandTotal As Integer
Next, you need to know what to do with those variables. You need to manipulate them by always making them larger each time the btnCharges button is clicked. Like this:
Expand|Select|Wrap|Line Numbers
  1.         If radA.Checked AndAlso intHours > 10 Then
  2.             decTotal = CDec((9.95 + ((intHours - 10) * 2)))
  3.             decPackA = decPackA + decTotal
  4.             decPackAHours = decPackAHours + intHours
  5.         ElseIf radA.Checked AndAlso intHours <= 10 Then
  6.             decTotal = CDec(9.95)
  7.             decPackA = decPackA + decTotal
  8.             decPackAHours = decPackAHours + intHours
  9.         End If
  10.  
  11.         If radB.Checked AndAlso intHours > 20 Then
  12.             decTotal = CDec((14.95 + ((intHours - 20) * 1)))
  13.             decPackB = decPackB + decTotal
  14.             decPackBHours = decPackBHours + intHours
  15.         ElseIf radB.Checked AndAlso intHours <= 20 Then
  16.             decTotal = CDec(14.95)
  17.             decPackB = decPackB + decTotal
  18.             decPackBHours = decPackBHours + intHours
  19.         End If
Then, in your accumulate button and exit button, you need to specify the grandTotal, by adding decPackA, B, and C, throw a MsgBox with that data, and close the form. Like this:
Expand|Select|Wrap|Line Numbers
  1.         GrandTotal = decPackA + decPackB + decPackC
  2.         MsgBox("Package A: " & decPackA.ToString("c") & vbCrLf & "Package A Hours: " & decPackAHours & vbCrLf & "Package B: " & decPackB.ToString("c") & vbCrLf & "Package B Hours: " & decPackBHours & vbCrLf & "Package C: " & decPackC.ToString("c") & vbCrLf & "Package C Hours: " & decPackCHours & vbCrLf & "Grand Total: " & GrandTotal.ToString("c"))
  3.         Me.Close()
One other thing you would be wise to do is, if you have a messagebox throwing an "error" to the end user because they forgot to fill out data, you should exit the sub routine so that the code does not keep running when it should actually be exiting. I added a little bit of error handling to one of your sections of code so you can see what I'm talking about. Like this:
Expand|Select|Wrap|Line Numbers
  1.         If (txtHours.Text.Length > 0) Then
  2.             intHours = CInt(txtHours.Text)
  3.         Else
  4.             MsgBox("Please enter an amount of hours")
  5.             Exit Sub
  6.         End If
I hope all of this helps! If you need any more help, please feel free to keep posting.
Mar 15 '16 #9

P: 11
That is good but I do not need to have a messagebox in my accumulate button I just need it to accumulate the packages choose then show up in a messagebox when you exit. Here is an idea of how it is to end up.

Grand Total
PackageA = 40hours for $55.95
PackageB = 0hours for $0.00
PackageC = 10hours for $19.95
Mar 15 '16 #10

100+
P: 299
So, should you click accumulate after every time you click btnCharges? If so, I've given you plenty of data to work your way to that result.
Mar 15 '16 #11

P: 11
I am not sure I am totally confuse with this stuff but I don't think so this is what it tells me to do

When the “Accumulate” button is clicked:
i. You are to keep grand totals for the Hours and Amount Due for each type of Package.
i. This requires three class-level variables for the Hours, i.e. one for the Package A hours, one for the Package B hours, and one for the Package C hours.
ii. Similarly, you will need three class-level variables for the Amounts.
j. Check the RadioButtons to see which Package is selected and add the Hours and Amount Due into the corresponding set of class-level variables.
k. Also, disable the “Accumulate” button.
Mar 15 '16 #12

100+
P: 299
Precisely. So instead of doing the addition to the class variables within the btnCharge click, you must do them when you click the accumulate button. All of the information is in my response for you to move forward. As much as I'd love to do all of your homework, I won't. :)
Mar 15 '16 #13

P: 11
And I thank you for the help. But I was thinking it was easier than that. So what you are telling me is that what I had in the calculate button is also what goes in the accumulate button. This is what confuses me. Because when you click the calculate btn the amount shows in the amount due label and when you click the accumulate btn it stores it for the exit btn.
Mar 16 '16 #14

Post your reply

Sign in to post your reply or Sign up for a free account.