user input and multiply?

Thatonerandomguy

New member
Joined
Oct 14, 2010
Messages
4
Programming Experience
Beginner
I'm having trouble using Visual Basic. It's my first time with the program that my college course is requiring I use. I'm having problems programing the script for an application. It's suppose to take the rate of a bunch of employees that are programmed into the application using an array, and multiply it by a decimal number that the user inputs into the application. I'm having problems trying to figure out the code for it. How would I code this?
 
What code do you have so far?

Well I'm not sure if any of my code is correct, however.

Public Class Form1

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

Private Sub btnReport_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click

Dim intSalaries() As Integer = {2400,, 1500, 1600, 2790, 1000, 6300, 1300, 2700}
Dim strInputCode As String
Dim intCode As Integer
Dim intSubscribt As Integer

txtReport.Text = Val(intSalaries.text) * Val(txtRate.Text)

End Sub

End Class

It's basically suppose to be an application that allows the user to enter a bonus rate and then the application should use the rate, along with the eight sales amounts stored in the array, to calculate each salesperson's bonus amount. It also needs to calculates the total bonus which I have no clue on how to get that to work. The project asks for a one dimensional array whose elements are initialized to 2400, 1500, 1600, 2790, 1000, 6300, 1300, and 2700. It should only accept numbers, the period, and the backspace key. The contents of txtReport (The report of the bonus rates) should be cleared when a chance is made to the contents of txtRate control (which is the input box for the rate) I'm having problems figuring out exactly what it needs to get the job done. Like I know it needs the exit button (I already coded that) and the array. But besides that, I'm not sure how to actually get it to work.
 
So, quick update. This is what I've gotten to.

Public Class Form1

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

Private Sub btnReport_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click

Dim intSalaries() As Integer = {2400, 1500, 1600, 2790, 1000, 6300, 1300, 2700}
Dim i As Integer
txtReport.Text = intSalaries(i) * Val(txtRate.Text)
For i = (0) To (7)
Next i



End Sub

End Class
 
Okay, so with some help from the book, I've gotten it this far.

Public Class Bonus

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

Private Sub btnReport_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReport.Click

Dim intSales() As Integer = {2400, 1500, 1600, 2790, _
1000, 6300, 1300, 2700}

Dim decRate As Decimal = 0
Dim decBonus As Decimal = 0
Dim decTotalBonus As Decimal = 0

If Decimal.TryParse(txtRate.Text, decRate) Then
txtReport.Text &= "Bonus" & vbCrLf
For intRow As Integer = 0 To UBound(intSales)
decBonus = intSales(intRow) * decRate
decTotalBonus += decBonus
txtReport.Text &= FormatCurrency(decBonus) & vbCrLf
Next
txtReport.Text &= vbCrLf & "Total Bonus Paid = " & _
FormatCurrency(decTotalBonus)

End If

End Sub

I'm not sure why it's not working
 
serious, you gotta use the CODE tag to post CODE in the forum
I'm not sure what you're about but I guess you getting it far more complex than it needs to be:

VB.NET:
Dim intSales() As Integer = {2400, 1500, 1600, 2790, 1000, 6300, 1300, 2700}
Dim RatedSales(8) as Integer
Dim rate as Integer
Dim i as Integer

' I suggest use a masked box for the user to avoid him from not typing a number, but you still should check it:
if not IsNumeric(UserInputBox.Text) then
   MessageBox.Show("come on mate, type a damn number")
   Exit Sub
end if
rate = Conver.ToInt16(UserInputBox.Text)
For i = 0 to 7
RatedSales(i) = intSales(i) * Rate
Next i

remember, I didn't check this code and I typed it straight on the forum, there might be some lil syntaxes errors.
 
Back
Top