Hi,
A few things for you then:-
1) Since you are just starting out with VB turn Option Strict ON and Option Explicit On in your project settings and leave them on for all your projects. This will help you to avoid bad practices from the start.
2) With Option Strict On, this will immediately tell you where you are currently getting your type conversion error so that you can see what you need to deal with.
3) If you need to Explicitly set any values in your projects then these should always be declared as constants. i.e:-
4) When declaring variables in your project then always use descriptive names since Num1, Num2 etc etc means nothing and will easily confuse you later on in your programming.Code:Const Num5 As Single = 8.3 Const Num6 As Single = 1000000
5) The next thing to do is to always validate any input from the project before you use them in your calculations. For instance, you are looking for 4 single type values to be returned from your 4 TextBoxes, but what would happen if someone were to type text values into these TextBoxes? So, you would use TryParse of the type you are expecting to validate any input before you use it. i.e:-
6) Once all the above is done the calculation should now be simple:-Code:Dim Num1, Num2, Num3, Num4 As Single If Single.TryParse(TextBox1.Text, Num1) AndAlso Single.TryParse(TextBox2.Text, Num2) _ AndAlso Single.TryParse(TextBox3.Text, Num3) AndAlso Single.TryParse(TextBox4.Text, Num4) Then 'Write your valid calculation code here Else MessageBox.Show("Invalid Data in TextBoxes!") End If
Be careful with the division character that you are using. In your last post you used the character "\" which is the symbol to perform INTEGER DIVISION and not standard division.Code:Product = (Num1 * Num2 * Num3 * Num4 * Num5) / Num6
Hope that helps.
Cheers,
Ian




Reply With Quote