• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VB6 Help

Gautama2

Golden Member
Dim intNumOfEmployees As Integer
Dim intAvg As Integer
Dim intTotalPay As Integer
Dim intNumOfPieces As Integer
Dim intTotalPieces As Integer

Private Sub mnuFileCalc_Click()
intNumOfPieces = Val(txtPieces)
lblPay = FormatCurrency(Pay(intNumOfPieces))
intNumOfEmployees = intNumOfEmployees + 1
intTotalPay = val(lblPay) + intTotalPay
intAvg = intNumOfEmployees / intTotalPay
intTotalPieces = intNumOfPieces + intTotalPieces
End Sub

Private Function Pay(intNumOfPiecesPASSED As Integer) As Currency
If intNumOfPiecesPASSED >= 1 And intNumOfPiecesPASSED <= 199 Then
Pay = intNumOfPiecesPASSED * 0.5
End If

If intNumOfPiecesPASSED >= 200 And intNumOfPiecesPASSED <= 399 Then
Pay = intNumOfPiecesPASSED * 0.55
End If

If intNumOfPiecesPASSED >= 400 And intNumOfPiecesPASSED <= 599 Then
Pay = intNumOfPiecesPASSED * 0.6
End If

If intNumOfPiecesPASSED >= 600 Then
Pay = intNumOfPiecesPASSED * 0.65
End If
End Function

intAvg = intNumOfEmployees / intTotalPay
is giving me division by zero error, what am I missing?
 
There's no way for us to know why intTotalPay has a value of 0. As the others suggested, you'll have to step through your logic and figure it out. Just glancing at it I wondered what value Pay() would return if intNumOfPiecesPassed were <= 0. Also, what is the effect of val(FormatCurrency(Pay(intNumOfPieces))) (which is what you're effectively doing)?
 
If the number of pieces is zero, you would be causing a divide by zero error.
 
lblPay = FormatCurrency(Pay(intNumOfPieces))

Based on Hungarian notation, you're setting a label object to a string object.

Therefore,

intTotalPay = val(lblPay) + intTotalPay

Is going to have the same issues. lblPay is most likely a label object where you'd want lblPay.Text (or is it Caption? I can never remember). Passing in lblPay will not result in an error, because the string representation of an object is the object's derivation (or something like that) so it's probably doing something along the line of val("System.Windows.Form.Label") which has no numbers in it. Also, val is not going to work out of the box with decimals as if you do val("10.50") you will get 1050 back. You can multiply by .01 and get the number you're really looking for.
 
Back
Top