0

Hi I just started playing around with Visual Basics today and thought it would be cool if I could make a program to work out the weight and the price of a square peice of steel. I have tried to solve the problem and fixed many errors but now I'm stuck. The program give's me a total 0f zero all the time I need help.
This is the formula for the weight os the steel. Length x Width x thickness x 8.3 (rounded off Its not critical for this purpose) devided by 1000000 to get rid of the zero's. So a square plate 300mm x 300mm x 12mm x 8.3 / 100000 (this is just to get rid of all the zero's) =8.964 KG. This is the first total to get and for the program to show. The next is to multiply 8.964 x 12 (the price per Kg in My currency Rand) then the total cost sould be R107.568 for the peice of steel.

This is what ive done

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim num1, num2, num3, num4, num5, num6, product As Single, weight As Single
    num1 = TextBox1.Text
    num2 = TextBox2.Text
    num3 = TextBox3.Text
    num4 = TextBox4.Text
    num5 = Val(8.3)
    num6 = Val(1000000)
    TextBox5.Text = product
    TextBox6.Text = weight
    weight = num1 * num2 * num3 * num5
    product = weight * num4 / num6


End Sub

Like I said I'm new to this don't enven know if this is the right way to do this.
Any help would be appreciated.
2
Contributors
5
Replies
17
Views
4 Years
Discussion Span
Last Post by Chris450
1

You are so close! The problem is that on lines 9 and 10, you don't have a value calculated for variables "product" and "weight". Move those two lines down below lines 11 and 12 and it should work fine.

Hope this helps! Happy coding!

0

Thank you But I did manage o get it right.
This is what I did. I think it is what you said I sould do.
But thank you any way for your time and for helping me.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim num1, num2, num3, num4, num5, num6, num7, product As Single, weight As Single, quantity As Single, total As Single
    num1 = TextBox1.Text
    num2 = Textbox2.Text
    num3 = TextBox3.Text
    num4 = TextBox4.Text
    num5 = Val(8.3)
    num6 = Val(1000000)
    num7 = TextBox7.Text
    weight = num1 * num2 * num3 * num5 / num6
    product = weight * num4
    quantity = product * num7
    total = quantity * product
    TextBox8.Text = quantity
    TextBox5.Text = product
    TextBox6.Text = weight

End Sub
0

BTW is there a way that I can ad an R infront of the amount and KG behind the weight.

0

Yes...you can use the CStr function on your numeric variables, then just contatenate with a string literal like so:

TextBox6.Text = CStr(weight) + " kg"

I think you can figure out how to prefix the "R" using this same sort of technique. Best of luck!

Edited by BitBlt

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.