-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
vb Code:
Dim intTemp As Integer
If Not Integer.TryParse(pa.Text, intTemp) Then
MsgBox("Warning: You entered text instead of a number")
End If
If intTemp > 25 Then
pa.Text = 25
MsgBox("Pressure angle cannot exceed 25!", vbExclamation, "Error!")
ElseIf intTemp < 0 Then
pa.Text = 0
MsgBox("Pressure angle cannot be less than zero!", vbExclamation, "Error!")
End If
The only problem is that i get a warning message when i hit the minus sign - or even when i use backspace i get the warning mesage. is there anyway that i can make exceptions for both the minus sign and the backspace ?
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Easy use a NumericUpDown Control instead of a text box.
I just realised that you have this in the TextChanged event of the textbox. So what is happening is that when you press the "-" then it tries to change this to a number, and "-" is not a number. If you are going to use textboxes then the easiest way is to validate the textboxes when you click the Calculate button or to validate the text when focus leaves the textbox (Use the pa.LostFocus() event)
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
vbnet Code:
Private Sub pa_LostFocus(byval sender as object, byval e as System.EventArgs) handles pa.LostFocus()
if not pa.Text.IsNullOrEmpty(pa.Text) andalso not pa.Text = "" Then
'This checks for blanks in the text box
Dim intPA as Integer = Convert.ToInt32(pa.Text)
if intPA > 25 Then
pa.Text = 25
MessageBox.show("Pressure angle cannot exceed 25 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf intPA < 0 Then
pa.Text = 0
MessageBox.show("Pressure angle cannot be less than 0 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End if
End Sub
You could try this sub procedure. Comment all the TextChanged code out and then add this code.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Thanx for the code will try it now
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
change this line
vbnet Code:
if not pa.Text.IsNullOrEmpty(pa.Text) andalso not pa.Text = "" Then
to read like this
vbnet Code:
if not string.IsNullOrEmpty(pa.Text) andalso not pa.Text = "" Then
Otherwise you will get an error here.
Also after each of the MessageBox lines you could add another line
This will force that text box to become the one that is active.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
vb Code:
Private Sub pa_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pa.LostFocus
If Not String.IsNullOrEmpty(pa.Text) AndAlso Not pa.Text = "" Then
'This checks for blanks in the text boxDim intPA as Integer = Convert.ToInt32(pa.Text)
Dim intPA As Integer = Convert.ToInt32(pa.Text)
If intPA > 25 Then
pa.Text = 25
MessageBox.Show("Pressure angle cannot exceed 25 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
ElseIf intPA < 0 Then
pa.Text = 0
MessageBox.Show("Pressure angle cannot be less than 0 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
End If
End If
i entered the following code i still want to modify the code so that when the calculate button and text is entered i get a msgbox saying
if text was entered
msgbox "Text was entered!"
pa.text = Clear
end if
how am i able to do so ?
http://img526.imageshack.us/img526/9585/a1yl2.jpg
http://img142.imageshack.us/img142/6572/a2pu7.jpg
http://img341.imageshack.us/img341/6649/a3ef2.jpg
http://img253.imageshack.us/img253/9002/a4sv0.jpg
http://img405.imageshack.us/img405/3791/a5gf4.jpg
http://img135.imageshack.us/img135/637/a6ky6.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Finally found the solution and works like charm
vb Code:
Private Sub pa_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pa.LostFocus
Dim intPA As Integer
If Not String.IsNullOrEmpty(pa.Text) AndAlso Not pa.Text = "" Then
If Not Integer.TryParse(pa.Text, intPA) Then
'Text was entered
MessageBox.Show("Text was entered!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Error)
pa.Text = ""
Else
'This checks for blanks in the text boxDim
If intPA > 25 Then
pa.Text = 25
MessageBox.Show("Pressure angle cannot exceed 25 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
ElseIf intPA < 0 Then
pa.Text = 0
MessageBox.Show("Pressure angle cannot be less than 0 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
End If
End If
End If
End Sub
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
If im to modify the above code and let it accept decimals what should i modify i tried the following but no luck:
vb Code:
Dim intPA As Double = 0.0
intPA = Convert.ToDouble(pa.Text)
If Not String.IsNullOrEmpty(pa.Text) AndAlso Not pa.Text = "" Then
If Not Integer.TryParse(pa.Text, intPA) Then
'Text was entered
MessageBox.Show("Text was entered!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Error)
pa.Text = ""
Else
'This checks for blanks in the text boxDim
If intPA > 25 Then
pa.Text = 25
MessageBox.Show("Pressure angle cannot exceed 25 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
ElseIf intPA < 0 Then
pa.Text = 0
MessageBox.Show("Pressure angle cannot be less than 0 degrees!", "Pressure angle", MessageBoxButtons.OK, MessageBoxIcon.Information)
pa.Focus()
End If
End If
End If
End Sub
http://img525.imageshack.us/img525/3500/decimallp1.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
The simple thing is do as demausdauth says: Delete the "pa" control from your form. Replace it with a NumericalUpDown control. This way, it's impossible to put in a non-numeric value. If you name the NumericalUpDown the same thing as your Textbox "pa", then you get your value with: pa.Value
This is a case of "Use the right tool for the right job!". Use Textboxes for "Text", use NumericalUpDowns for "Numbers".
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Done But the problem is i want to take the value from that NUD and do some invisible calculations which i want to be taken to a new forum or what i usually call the next page. So for that to happen shall i use a textbox ? to carry the answer invisible after doing some calculation. or is there something better besides the textbox. As an input i'll use NUD for all but as an output what shall i use ?
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
No, that's what variables are for.
Make a variable:
Dim myVariable as Double
and work with it (random garbage equation):
myVariable = ((intPA + 700) /90) - (intAA * 2)^2
Then assign it back to a control:
NumericUpDown1.Value = myVariable
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
You can use the Click event of the button to perform all your calculations. What we need to know now is what are you going to do with the values that you calculate.
vbnet Code:
Private Sub Calculate(byval sender as object, byval e as system.eventargs) handles 'Whatever the button name is .Click
'Preform your Calculations here
'If you are going to pass these values to another screen then we need to
'decide how to pass them.
' method1
Dim frmObject as New frmNextForm(value1, value2, value3, value4, value5)
frmObject.show()
'method2
' this one requires that frmNextForm has variables declared as public on it
Dim frmObject as New frmNextForm()
frmObject.Value1 = value1
frmObject.Value2 = value2
frmObject.Value3 = value3
frmObject.Value4 = value4
frmObject.Value5 = value5
frmObject.Show()
' then you will probably want to close the first screen and leave the
' second one open. Make sure to change the properties of the project
' under the Application tab -> Shutdown mode to When last form closes
Me.Close()
I know there are other methods for passing values and there are better ways, but one of these methods I think is the easiest and quickest way to get'er done. :)
Your next form will need something like this:
Method 1
Declare 5 variables above the Visual Studio generated code. In my case I am using Value1, Value2, etc...
vbnet Code:
Dim Value1 as decimal = 0.0, Value2 as decimal = 0.0, Value3 as decimal = 0.0, Value4 as decimal = 0.0, Value5 as decimal = 0.0
Public Sub New(byval PassValue1 as Decimal, byval PassValue2 as decimal, byval PassValue3 as decimal, byval PassValue4 as decimal, byval PassValue5 as decimal)
' I specify them as decimal because I don't know what type they would be
' You would have to specify whatever the type you want to pass
Value1 = PassValue1
Value2 = PassValue2
Value3 = PassValue3
Value4 = PassValue4
Value5 = PassValue5
End Sub
There now your values have been passed by method 1 and you will be able to use them on the next form.
Method 2
Declare 5 variables above the Visual Studio generated code. In my case I am using Value1, Value2, etc...
vbnet Code:
Public Value1 as decimal = 0.0
Public Value2 as decimal = 0.0
Public Value3 as decimal = 0.0
Public Value4 as decimal = 0.0
Public Value5 as decimal = 0.0
There now your values have been passed by method 2 and you will be able to use them on the next form.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Quote:
Originally Posted by demausdauth
You can use the Click event of the button to perform all your calculations. What we need to know now is what are you going to do with the values that you calculate.
I believe he's going to take his input numbers, use them to create a table that calculates the perimeter of each gear, attaches an offset to that perimeter, figure out the X-Y coordinates for various discrete intervals along that curve, then use those X-Y coordinates to write lines of code to command a CNC machine to cut the gear out.
Each line of code would be "go to point X-Y", and the machine would obey. If his points are fine enough, it can essentially cut curves as well. The offset is because the cutting bit on the machine has thickness (a 1" diameter cutter would need a 0.5" offset since your position is the center of the tool).
Depending on how fine he slices his computation table these are all easily achievable.
The program's purpose is simple in the end: Input a handful of variables -> Output a file containing CNC machine instructions for how to cut a set of shapes.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Quote:
Originally Posted by demausdauth
You can use the Click event of the button to perform all your calculations. What we need to know now is what are you going to do with the values that you calculate.
vbnet Code:
Private Sub Calculate(byval sender as object, byval e as system.eventargs) handles 'Whatever the button name is .Click
'Preform your Calculations here
'If you are going to pass these values to another screen then we need to
'decide how to pass them.
' method1
Dim frmObject as New frmNextForm(value1, value2, value3, value4, value5)
frmObject.show()
'method2
' this one requires that frmNextForm has variables declared as public on it
Dim frmObject as New frmNextForm()
frmObject.Value1 = value1
frmObject.Value2 = value2
frmObject.Value3 = value3
frmObject.Value4 = value4
frmObject.Value5 = value5
frmObject.Show()
' then you will probably want to close the first screen and leave the
' second one open. Make sure to change the properties of the project
' under the Application tab -> Shutdown mode to When last form closes
Me.Close()
I know there are other methods for passing values and there are better ways, but one of these methods I think is the easiest and quickest way to get'er done. :)
Your next form will need something like this:
Method 1
Declare 5 variables above the Visual Studio generated code. In my case I am using Value1, Value2, etc...
vbnet Code:
Dim Value1 as decimal = 0.0, Value2 as decimal = 0.0, Value3 as decimal = 0.0, Value4 as decimal = 0.0, Value5 as decimal = 0.0
Public Sub New(byval PassValue1 as Decimal, byval PassValue2 as decimal, byval PassValue3 as decimal, byval PassValue4 as decimal, byval PassValue5 as decimal)
' I specify them as decimal because I don't know what type they would be
' You would have to specify whatever the type you want to pass
Value1 = PassValue1
Value2 = PassValue2
Value3 = PassValue3
Value4 = PassValue4
Value5 = PassValue5
End Sub
There now your values have been passed by method 1 and you will be able to use them on the next form.
Method 2
Declare 5 variables above the Visual Studio generated code. In my case I am using Value1, Value2, etc...
vbnet Code:
Public Value1 as decimal = 0.0
Public Value2 as decimal = 0.0
Public Value3 as decimal = 0.0
Public Value4 as decimal = 0.0
Public Value5 as decimal = 0.0
There now your values have been passed by method 2 and you will be able to use them on the next form.
Very valuable post to me THANKS!
Thanks ive been away for the past day. How do i open another window and close the active window when the button calculate is clicked ?
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Quote:
Originally Posted by demausdauth
vbnet Code:
Private Sub Calculate(byval sender as object, byval e as system.eventargs) handles 'Whatever the button name is .Click
'Preform your Calculations here
'If you are going to pass these values to another screen then we need to
'decide how to pass them.
' method1
Dim frmObject as New frmNextForm(value1, value2, value3, value4, value5)
frmObject.show()
'method2
' this one requires that frmNextForm has variables declared as public on it
Dim frmObject as New frmNextForm()
frmObject.Value1 = value1
frmObject.Value2 = value2
frmObject.Value3 = value3
frmObject.Value4 = value4
frmObject.Value5 = value5
frmObject.Show()
' then you will probably want to close the first screen and leave the
' second one open. Make sure to change the properties of the project
' under the Application tab -> Shutdown mode to When last form closes
Me.Close()
End Sub
(I edited my quote and added the End Sub that I forgot in the original posting :))
Line 8 (Line 13) will create space in memory for the new form.
Line 9 (Line 19) will cause the new form to be shown and Line 24 will cause the current form ( the one that you have just entered values on ) to close.
Remember that in this sub procedure I am using two different methods to achieve the same thing. You will need to choose one and go with.
I am not exactly sure where the Application settings are in VS2008 but I would think that if you right-click on the project name in the Solution Explorer that you should be able to click on Properties. From there you should be able to find the Application tab, then find the Shutdown mode. This has to be changed to When the Last Form Closes or when the program hits the Me.Close() the application will end.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Thanks Buddy. Im trying to do this passing method but no luck so far.
1.I want The function of the "Calculate" Button to be as follows.Take value from NUD and send them to the third form.
http://aycu19.webshots.com/image/499...0305776_rs.jpg
2. Open the second form ( which i know how to do ) & Do apply this law in the third formCommon_Features. 1/(whatever NUD value is selected in form1).
This is the Second form.
http://aycu09.webshots.com/image/458...6578283_rs.jpg
3. See the number 0.25 for example if the NUD of diametral pitch was set to 4. [1/4]=0.25
http://aycu19.webshots.com/image/499...0020895_rs.jpg
I tried following up your tutorial but i always get error mesages. May you ut me on the correct track again please ?
Edit:I am sending the value into one form then showing a different form.
Purpose is that the different form consists of 3 tables so i set them into buttons. each button will open a table.I can read many options in my mind. Do everything in the Calculation Button ?(form1) or Send values to second form then from second to third to mylabel ?
If you were in my place what approach will you use ?
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Ok heres what ive done. In form1 i had this code
Public Class Form1
Code:
Public Shared Diametral_Pitch As String
and in the NUD controller i had this code
Code:
Private Sub dp_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dp.ValueChanged
Diametral_Pitch = dp.Text
End Sub
I was testing to see if im getting the correct value.
In the Second form i had a label.
and the following code
Code:
Private Sub second_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = Form1.Diametral_Pitch
End Sub
End Class
The problem was that the value was less than the NUD value by 1. And after i hit the back button and change the value of the NUD and hit the calculate button. The previous values remains so in my case the number 6 remains forever untill i terminate the program and run again.
http://img149.imageshack.us/img149/4335/19173162yh3.jpg
http://img151.imageshack.us/img151/6294/97406613oc2.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Now i tried putting the code in the calculation Button
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Diametral_Pitch = dp.Text
second.Show()
Me.Hide()
End Sub
When i hit the calculate button i get the same exact number as in the NUD.
I hit the "back" button change the value of the NUD and hit the "Calculate" Button and no changes take effect. So now it works only for one time. i want to change infinite number of times.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
I solved the problem by doing nothing in form2 eveything was done in form1.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Diametral_Pitch = dp.Text
Common_Features.Distance_Center.Text = (1 / (Form1.Diametral_Pitch))
second.Show()
Me.Hide()
End Sub
Works fine back and forth.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Code:
If Diametral_Pitch < 0 Then
Common_Features.Dedendum.Text = (1.25 / Diametral_Pitch).ToString
ElseIf Diametral_Pitch > 0 Then
Common_Features.Dedendum.Text = ((1.2 / Diametral_Pitch) + 0.002).ToString
End If
The only problem is that the answer i get from VB is 0.302 while the answer i get when i use my calculater is 0.3125
The equation is as follows 1.25/4 So why am i getting 0.302 ?
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Watch your variables for consistency. Is Diametral_Pitch a String like you have it in above examples, or a Double or a Decimal? You can't go about assigning numbers to strings and expect math to work.
If you got a variable, and you know it's a number, then you must define it as a number. Even if you're getting that number from something like a Textbox which holds strings, the first thing you do is use a function like CDbl() or CDec() or CInt() to convert it to a Double, Decimal, or Integer.
Your Textboxes should be:
Dim Diametral_Pitch as Double
Diametral_Pitch = CDbl(dp.Text)
Also, your If/Elseif... what happens if Diametral_Pitch = 0? Common_Features.Dedendum.Text never gets assigned.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
If Diametral_Pitch = 0 then "do nothing"
Actually there is nothing wrong with the code. Because the Diametral Pitch is ">0" i selected the number 4. That explains why the second equation was used. Correction is ">20".
Code that i wrote:
Code:
Public Class Form1
Public Shared Diametral_Pitch As String
Public Shared Velocity_Ratio As String
Public Shared gear As String
Public Shared Pressure_Angle As String
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Diametral_Pitch = dp.Text
Common_Features.Addendum.Text = (1 / (Diametral_Pitch))
Common_Features.Addendum1.Text = (Common_Features.Addendum.Text) * 25.4
If Diametral_Pitch < 20 Then
Common_Features.Dedendum.Text = (1.25 / Diametral_Pitch).ToString
ElseIf Diametral_Pitch > 20 Then
Common_Features.Dedendum.Text = ((1.2 / Diametral_Pitch) + 0.002).ToString
End If
Common_Features.Dedendum1.Text = (Common_Features.Dedendum.Text * 25.4).ToString
If Diametral_Pitch < 20 Then
Common_Features.clearance.Text = (0.25 / Diametral_Pitch).ToString
ElseIf Diametral_Pitch > 20 Then
Common_Features.clearance.Text = ((0.2 / Diametral_Pitch) + 0.002).ToString
End If
Common_Features.clearance1.Text = (Common_Features.clearance.Text * 25.4).ToString
Velocity_Ratio = vr.Text
gear = gearteeth1.Text
Pinion_Features.pinion1.Text = Math.Floor(Velocity_Ratio * gear)
Pinion_Features.Pitch_Radius1.Text = (Pinion_Features.pinion1.Text / Diametral_Pitch).ToString / 2
Pinion_Features.Pitch_Radius2.Text = (Pinion_Features.Pitch_Radius1.Text * 25.4).ToString
Pressure_Angle = resultdp.Text
Pinion_Features.Base_Circle1.Text = (Pinion_Features.Pitch_Radius1.Text) * Math.Cos(Pressure_Angle)
Pinion_Features.Base_Circle2.Text = (Pinion_Features.Base_Circle1.Text * 25.4).ToString
Pinion_Features.Outer_Circle1.Text = (Common_Features.Dedendum.Text) + (Pinion_Features.Pitch_Radius1.Text)
second.Show()
Me.Hide()
End Sub
Why arent they adding together ?It only gives the value of the Common_Features.Dedendum.text which is "0.31252" . The value of Pinion_Features.Pitch_Radius1.text Which is "2" is not being added why ?
http://aycu22.webshots.com/image/474...0629062_rs.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Because you're adding text. It's doing exactly what you told it to: 0.3125 + 2 = 0.31252. It's like adding "Hello" + "World" = HelloWorld
Do this:
(CDbl(Common_Features.Dedendum.Text) + CDbl(Pinion_Features.Pitch_Radius1.Text)).ToString
Once again, you MUST use proper variables! Programs are not like Excel, they won't convert everything for you. VB.NET when not in Strict mode will do a lot of behind the scenes conversion, but more often than not, this will get you into trouble as you've just seen.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
THANKS !!! Problem Solved :
What does CDbl actually does ?? Take the value from the text ?
By looking at my code do you see at anypoint where i shall add CDbl or do any modifications ?
Thanks again :-)
http://aycu29.webshots.com/image/493...9440538_rs.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
In the previous Code i had
Code:
Pinion_Features.Pitch_Radius2.Text = (Pinion_Features.Pitch_Radius1.Text * 25.4).ToString
ok is this the coorect format ? Or shall i put it in this way ?
Pinion_Features.Pitch_Radius2.Text = Cdbl((Pinion_Features.Pitch_Radius1.Text * 25.4)).ToString
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Just the text part which is a string:)
Code:
Pinion_Features.Pitch_Radius2.Text = Cdbl((Pinion_Features.Pitch_Radius1.Text) * 25.4).ToString
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
I went to project properties and set Option Strict to On
I tried running the program and i got 31 errors ! I didnt undertand a word from the errors may you please help me out ?
http://www.vbforums.com/[/B]
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
With Strict off, VB will try to do the simple conversions for you behind the scenes. It makes your program slower, and the code more sloppy, and as you found out, can lead to all kinds of unwanted behavior. With Strict on, VB won't do anything. You have to specifically program for each variable.
Here's the basics:
Everything in Visual Basic has a data type. Common ones are:
String
Double
Integer
Boolean
Decimal
Date
Now, every property has a data type associated with it. For example, the property of: Textbox.Text is a String. What those errors are telling you is, you can't take a number and stick it in a spot that is only for a string.
One of the biggest problems a new programmer might have is the concept that "You can have a String of Numbers". If I type in 123 into a Textbox, and read Textbox.Text, it's NOT A NUMBER. It's a STRING. The computer doesn't even consider it a number. It's no different to the computer than if you typed in ABC.
So, in order for the computer to consider it a number, you have to convert it to a number. That's where CDbl() comes in.
There are some handy conversion functions that try to convert one data type into another, they are:
CStr()
CDbl()
CInt()
CBool()
CDec()
CDate()
And they try to convert whatever is in the () to each of the above data types respectively. CDbl() will convert whatever is in the () into a Double (a floating point number)
Now your problem is, you also can't do the reverse. You can't take a data type Double and stick it where it's expecting a String! To do this, you have to convert it BACK into a string with CStr() or, the handy .ToString tag.
Also, moving data into and out of Textboxes should be the very first, and very last things you do. You should be making variables for each item you're working with.
If you got 5 text boxes for input and they're going to all be numbers and 3 for output, your code should look similar to this:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dblLength As Double = CDbl(txtInput1.Text)
Dim dblHeight As Double = CDbl(txtInput2.Text)
Dim dblDepth As Double = CDbl(txtInput3.Text)
Dim dblXRot As Double = CDbl(txtInput4.Text)
Dim dblYRot As Double = CDbl(txtInput5.Text)
Dim dblResult1 As Double
Dim dblResult2 As Double
Dim dblResult3 As Double
dblResult1 = dblLength * dblHeight * dblDepth
dblResult2 = Math.Sqrt(dblLength ^ 2 + dblHeight ^ 2)
dblResult3 = Math.Sin(dblXRot) * Math.Cos(dblYRot)
txtOutput1.Text = CStr(dblResult1)
txtOutput2.Text = CStr(dblResult2)
txtOutput3.Text = CStr(dblResult3)
End Sub
So... what do the errors mean? Simple, they're saying: You can't stick a (whatever type1) into a (whatever type2). i.e. You can't put an Integer into a spot for a String.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Thanks i'll try that immediately.
The only part i did not understand is
Code:
txtOutput1.Text = CStr(dblResult1)
Does it mean take the value from dblresult1 only if so whys the CStr there what happens if it wanst there ?
Quote:
Also, moving data into and out of Textboxes should be the very first, and very last things you do. You should be making variables for each item you're working with.
I deleted the code in error 1. Im using a NUD controller so i dont need it.
I edited error number 4 to
Code:
resultpa.Text = CDbl(Pa.Text * Math.PI) / 180
So now i have 28 errors , all are the same.
Strict On disallows implicit conversions from 'String'
http://www.vbforums.com/
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Once again, if you type "12345" in a text box, it's NOT A NUMBER.
The computer sees 12345 as: Character "1" from the keyboard, character "2" from the keyboard... etc
Anything typed into a textbox is one and only one thing to a computer: A line of characters typed in from the keyboard. It doesn't care that you typed numbers or words, it's ALL TEXT. Even if you only typed numbers, it's STILL TEXT.
In order for the computer to understand 12345 is a number, you have to tell it "this IS a number", and convert it to a number with CDbl()
CDbl("12345") = 12345
CDbl("a12345") = ERROR!
CDbl("12345a") = ERROR!
To PUT anything back into a textbox, you need to convert it BACK to text if it's not already.
Textbox.Text = 12345 ERROR!!
Textbox.Text = "12345" OK!
Textbox.Text = CDbl(MyNumber) ERROR!!
Textbox.Text = CStr(MyNumber) OK!
Also, strings have "quotes" around them. Numbers don't.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
here is one error correction you should get an idea of what needs to be done for the other
Code:
TextBox.Text = (CDbl(pa1.Text) * Math.PI / 180).ToString
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
resultpa.Text = CStr((CDbl(Pa.Text) * Math.PI) / 180)
resultpa.Text is a String
Pa.Text is a String, you CAN'T multiply PI times a string!
CDbl(Pa.Text) is a number, it converts the string Pa.Text into a number. you CAN multiply it by PI
(CDbl(Pa.Text) * Math.PI) / 180) is a NUMBER, you CAN'T store it in resultpa.Text because you can only store strings there.
CStr((CDbl(Pa.Text) * Math.PI) / 180) is a string, and you can store it in resultpa.Text
EDIT: Clanguage beat me to it :) There's no difference in using .ToString and CStr() by the way.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Thanx Guys. But i would really love to learn this.
-Code will be Less.
- I have all Equations needed.
tell me what you think ?
Quote:
class to store all of the information on a gear (or gears) you can have properties for all of the inputs and readonly properties to hold calculated values (this will be a big help) and you can include methods for calculating things (to store in the read only properties) and functions for getting calculated answers that don't need to be stored in the class itself.
Then if you make a global instance of this class (declare a variable as <your class name> with a scope of 'Friend') you can access this class via the variable from any form or module in the entire program.
This would avoid you having to deal with passing information from one form to another from when the "other" form is being opened.
BTW i tried what you mentioned in the previous post.
the moment i dimmed the two lines and tried to run the program.
http://aycu05.webshots.com/image/488...8425817_rs.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Oh! Don't set it = to Textbox at the top of the form!
Here's how it usually opens the form:
1) Read variables at the top of the form.
2) Run the "New()" subroutine.
3) Make the controls
4) Run the Form_Load() event
You're trying to assign it something that doesn't exist yet.
It hasn't made the textbox yet when you have it there.
Do this:
Dim Pressure_angle_Radian as Double
and:
Private Sub Form1_Load(ByVal sender.....
Pressure_angle_Radian = CDbl(Pa.Text)
MyLabel1.NormalText = "Di.....
Making a gear-class would be the proper way to do things, but it's a little more advanced than what you're trying to do right now. Making a special class does solve a lot of variable issues especially when moving between forms.
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Code:
Public Class Form1
Dim Pressure_Angle_Result As Double
Dim Pressure_angle_Radian As Double
Dim Diametral_Pitch As Double
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Pressure_angle_Radian = CDbl(Pa.Text)
Diametral_Pitch = CDbl(dp.Text)
End Sub
Code:
Private Sub pa_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Pressure_Angle_Result = (Pressure_angle_Radian * Math.PI) / 180
End Sub
Am i on the correct track ? because its working fine and im getting the numbers to show. The number of errors have reduced to 19.
http://aycu23.webshots.com/image/463...6349867_rs.jpg
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Double to String Error
Code:
Common_Features.Addendum.Text = (1 / (Diametral_Pitch))
Correction:
Code:
Common_Features.Addendum.Text = (1 / (Diametral_Pitch)).ToString
How do i fix the String to Double error for this one ?
Code:
Common_Features.Addendum1.Text = (Common_Features.Addendum.Text) * 25.4
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
You cannot multiply a string so set it to double but after that you need to reset everything to a string
Code:
Common_Features.Addendum1.Text = (CDbl(Common_Features.Addendum.Text) * 25.4).ToStrign
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Yup, understanding data types is a HUGE leap for a new programmer, congrats! :D You're almost got it!
-
Re: [2008] Please help me Build a Visual Basic Program from this Excel file
Thanks Guys heres what i ve done
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Pressure_angle_Radian = CDbl(Pa.Text)
Diametral_Pitch = CDbl(dp.Text)
Common_Features.Addendum.Text = CDbl(Common_Features.Addendum.Text).ToString
Common_Features.Addendum1.Text = CDbl(Common_Features.Addendum1.Text).ToString
End Sub
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Common_Features.Addendum.Text = (1 / (Diametral_Pitch)).ToString
Common_Features.Addendum1.Text = (Common_Features.Addendum.Text) * 25.4
End Sub
Why am i still getting and error although i did this to prevent writing CDbl(Common_Features.Addendum.Text).ToString and CDbl(Common_Features.Addendum1.Text).ToString every single time.I'll do the same for others.
http://aycu08.webshots.com/image/480...7279755_rs.jpg