• 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.

Visual Basic question

Kur

Senior member
Everything works fine except I need to have "Package A,B,C" in front of the numbers outputted to the new window, I can't seem to figure out how to do this. Any help would be great.

Here's my btnCalculate coding.

Dim decPa As Double
Dim decPb As Double
Dim decPc As Double
Dim decTotal As Double

If IsNumeric(txtPackageA.Text) = False Then
MessageBox.Show("This must be a numeric number", "Error")
Return
End If
If IsNumeric(txtPackageB.Text) = False Then
MessageBox.Show("Package B must be a numeric number", "Error")
Return
End If
If IsNumeric(txtPackageC.Text) = False Then
MessageBox.Show("Package C must be a numeric number", "Error")
Return
End If

decPa = CDec(txtPackageA.Text)
decPb = CDec(txtPackageB.Text)
decPc = CDec(txtPackageC.Text)

If decPa >= 10 And decPa <= 19 Then
decPa = (decPa * 99) * 0.8
ElseIf decPa >= 20 And decPa <= 49 Then
decPa = (decPa * 99) * 0.7
ElseIf decPa >= 50 And decPa <= 99 Then
decPa = (decPa * 99) * 0.6
Else
decPa = (decPa * 99) * 0.5
End If

If decPb >= 10 And decPb <= 19 Then
decPb = (decPb * 199) * 0.8
ElseIf decPb >= 20 And decPb <= 49 Then
decPa = (decPb * 199) * 0.7
ElseIf decPb >= 50 And decPb <= 99 Then
decPb = (decPb * 199) * 0.6
Else
decPb = (decPb * 199) * 0.5
End If

If decPc >= 10 And decPc <= 19 Then
decPc = (decPc * 299) * 0.8
ElseIf decPc >= 20 And decPc <= 49 Then
decPc = (decPc * 299) * 0.7
ElseIf decPc >= 50 And decPc <= 99 Then
decPc = (decPc * 299) * 0.6
Else
decPc = (decPc * 299) * 0.5
End If

decTotal = decPa + decPb + decPc

If radGrandTotal.Checked = True Then
MessageBox.Show(FormatCurrency(decTotal), "Amount of Order")
Else
MessageBox.Show(FormatCurrency(decPa) & ControlChars.CrLf & FormatCurrency(decPb) & ControlChars.CrLf & FormatCurrency(decPc) & ControlChars.CrLf & FormatCurrency(decTotal), "Amount of Order")
End If
 
Is this what you are trying to do?

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim decPa As Double
Dim decPb As Double
Dim decPc As Double
Dim decTotal As Double

If IsNumeric(txtPackageA.Text) = False Then
MessageBox.Show("This must be a numeric number", "Error")
Return
End If
If IsNumeric(txtPackageB.Text) = False Then
MessageBox.Show("Package B must be a numeric number", "Error")
Return
End If
If IsNumeric(txtPackageC.Text) = False Then
MessageBox.Show("Package C must be a numeric number", "Error")
Return
End If

decPa = CDec(txtPackageA.Text)
decPb = CDec(txtPackageB.Text)
decPc = CDec(txtPackageC.Text)

If decPa >= 10 And decPa <= 19 Then
decPa = (decPa * 99) * 0.8
ElseIf decPa >= 20 And decPa <= 49 Then
decPa = (decPa * 99) * 0.7
ElseIf decPa >= 50 And decPa <= 99 Then
decPa = (decPa * 99) * 0.6
Else
decPa = (decPa * 99) * 0.5
End If

If decPb >= 10 And decPb <= 19 Then
decPb = (decPb * 199) * 0.8
ElseIf decPb >= 20 And decPb <= 49 Then
decPa = (decPb * 199) * 0.7
ElseIf decPb >= 50 And decPb <= 99 Then
decPb = (decPb * 199) * 0.6
Else
decPb = (decPb * 199) * 0.5
End If

If decPc >= 10 And decPc <= 19 Then
decPc = (decPc * 299) * 0.8
ElseIf decPc >= 20 And decPc <= 49 Then
decPc = (decPc * 299) * 0.7
ElseIf decPc >= 50 And decPc <= 99 Then
decPc = (decPc * 299) * 0.6
Else
decPc = (decPc * 299) * 0.5
End If

decTotal = decPa + decPb + decPc

If radGrandTotal.Checked = True Then
MessageBox.Show("Total - " & FormatCurrency(decTotal), "Amount of Order")
Else
MessageBox.Show("Package A - " & FormatCurrency(decPa) & ControlChars.CrLf & "Package B - " & FormatCurrency(decPb) & ControlChars.CrLf & "Package C - " & FormatCurrency(decPc) & ControlChars.CrLf & "Total - " & FormatCurrency(decTotal), "Amount of Order")
End If


End Sub
End Class
 
Yeah, String concatenation is done with the & operator in VB. So this is useful for any sort of Display or string manipulation you need to do as well.
 
Back
Top