Beginner Question Engineering Calculator

chall

Member
Joined
Feb 21, 2014
Messages
5
Programming Experience
Beginner
Hi,

I'm a beginner to VB and started using visual Studio 2013 just 2 days ago (I have some experience but this is with writing post processors for CNC machines using different languages) so please go easy on me.

I am creating an engineering calculator, the user inputs a few values and hits the calculate button to work out two variables. Now I am wanting the calculation to work both ways depending on what variables are know by the user but I cant seem to get it to do both currently. This is where I am at currently;


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


 
 
 
rev.Text = (Val(ssf.Text) * 1000) / (3.14159 * Val(tool.Text))
fe.Text = Val(rev.Text) * Val(fpt.Text)


 
 
ssf.Text = (Val(rev.Text) * 3.14159 * Val(tool.Text)) / 1000
fpt.Text = Val(fe.Text) / Val(rev.Text)


 
 
rev.Text = FormatNumber(rev.Text, 0)
fe.Text = FormatNumber(fe.Text, 0)
ssf.Text = FormatNumber(ssf.Text, 0)
fpt.Text = FormatNumber(fpt.Text, 2)

End Sub

I basically want it to either perform the red text or the blue text calculations depending on what text boxes are filled in with information.

Also is there anyway for the calculation to automatically calculate with out the use of a button? so it constantly refreshes/ updates.

Sorry if this is a bit of a basic question, I am only just starting to get into it.

Any advice would be much appreciated.

Regards
Mat
 
To answer the first question, that's what If statements are for. You test a condition and do something If it is True. In your case, that condition is the appropriate TextBox(es) containing text. You can add Else and/or ElseIf statements depending on what actions you want to perform under what circumstances.

To answer you second question, you just have to handle a different event. You have to decide what needs to happen in the application to cause the calculation to be performed and then determine what event is raised when that happens. At the moment, what needs to happen in the application is that the user needs to click Button1 and the event that's raised is the Click event of that Button.
 
Thank you for the reply.

Do you have an example code of the statement required for text boxes containing text?
 
Thank you for the reply.

Do you have an example code of the statement required for text boxes containing text?

What do you think it would be?
 
got a bit of free time and solved my problem. I did it like this:Private Sub ssf_TextChanged(sender As Object, e As EventArgs) Handles ssf.TextChanged


If tool.Text.Length >= 1 Then
rev.Text = (Val(ssf.Text) * 1000) / (3.14159 * Val(tool.Text))

End If

If ssf.Text.Length >= 1 And rev.Text.Length >= 1 Then
fe.Text = Val(rev.Text) * Val(fpt.Text)

End If

End Sub

Private Sub fpt_TextChanged(sender As Object, e As EventArgs) Handles fpt.TextChanged

If ssf.Text.Length >= 1 And tool.Text.Length >= 1 And rev.Text.Length >= 1 Then
fe.Text = Val(rev.Text) * Val(fpt.Text)

End If

End Sub
 

Private Sub tool_TextChanged(sender As Object, e As EventArgs) Handles tool.TextChanged

If ssf.Text.Length >= 1 Then
rev.Text = (Val(ssf.Text) * 1000) / (3.14159 * Val(tool.Text))

End If

If ssf.Text.Length >= 1 And rev.Text.Length >= 1 Then
fe.Text = Val(rev.Text) * Val(fpt.Text)

End If


End Sub

i just need to find an alternative way of setting the decimal point as the method i was using is now messing up the calculations.
 
Back
Top