multiple declares on one line

clmowers

New member
Joined
Oct 25, 2008
Messages
2
Programming Experience
Beginner
Ok...im taking some VB classes and this is driving me crazy...i want to declare multiple varibles for 1 data type on 1 line and then use them. Here is my code that im using
VB.NET:
        Const NyTaxRate As Decimal = 0.08D
        Dim sQty1, sQty2, sQty3, sQty4 As String
        Dim sPrice1, sPrice2, sPrice3, sPrice4 As String

        lblTotal1.Text = (Integer.Parse(sQty1) * Decimal.Parse(sPrice1)).ToString
        lblTotal2.Text = (Integer.Parse(sQty2) * Decimal.Parse(sPrice2)).ToString
        lblTotal3.Text = (Integer.Parse(sQty3) * Decimal.Parse(sPrice3)).ToString
        lblTotal4.Text = (Integer.Parse(sQty4) * Decimal.Parse(sPrice4)).ToString

        txtSubTotal.Text = (Decimal.Parse(lblTotal1.Text) + Decimal.Parse(lblTotal2.Text) _
        + Decimal.Parse(lblTotal3.Text) + Decimal.Parse(lblTotal4.Text)).ToString

        txtTax.Text = (Decimal.Parse(txtSubTotal.Text) * NyTaxRate).ToString
        txtGrandTotal.Text = (Decimal.Parse(txtSubTotal.Text) + Decimal.Parse(txtTax.Text)).ToString

    End Sub
End Class

Im getting an error that states that variable * was used before it was assigned a value. If i declare each one independently, like this
VB.NET:
dim sQty1 as String = txtQty1.text
dim sQty2 as String = txtQty2.text
dim sQty3 as String = txtQty3.text
dim sQty4 as String = txtQty4.text
dim sPrice1 as String = txtPrice1.text
dim sPrice2 as String = txtPrice2.text
dim sPrice3 as String = txtPrice3.text
dim sPrice4 as String = txtPrice4.text

it works fine, just when i do it on one line. How do i do this, my book doesn't go into this into to much depth, can anyone help me get this code working, if you need more information, please let me know
 
Back
Top