My aim is to get this value.

[IMG]http://aycu40.webshots.com/image/46759/2005193521074775269_rs.jpg[/IMG]

What is the best approch to do so ? Do i create a text box ? and place it in the (1,1) (Row, Column).

When do i want this number to appear ?

When the calculate button is hit.

[IMG]http://aycu39.webshots.com/image/49638/2005162900054054381_rs.jpg[/IMG]

So i guess the code should go there.

Methodology ? I dont want the number to appear just like that. Since ive built a user interface that number specifically depends on the value entered in NUD controller that ive changed its name to pd.
This value entered here.
[IMG]http://aycu02.webshots.com/image/48201/2000960933809274588_rs.jpg[/IMG]

now what i want to happen back in the form that ive changed its name to Common_Features , i mean this form

[IMG]http://aycu40.webshots.com/image/46759/2005193521074775269_rs.jpg[/IMG]

A mathematical operation to take place. The concept or the rule i want to use is 1/(whatever value is entered in the pd NUD)

So how do i implement the call function ? Call whatever value is entered in the NUD bring it up to current form then 1/value.

Recommended Answers

All 33 Replies

i didn't get the point... and please insert a picture (you can attach..use forum facility), don't give a link.

Ok ill try to explain again.

As seen in the attachments Picture 4 shows you an interface ana a value = 0.25 in red.

I used a paint program to insert that number to tell exactly what i want.

Now inorder to get that number 0.25 what shall i add ? a label or text box ? Which is best ?.


Now i want that number to appear when the calculate button is clicked. ( See Picture 1 ).


The number 0.25 is a result of a caluclation that depends on another value form the NUD.


1.So i think i'll have to Declare one or more properties in the target form for the data that needs to be passed in. Then create the form object and then set the appropriate properties.

2. Declare a constructor in the target form and add a parameter for each value i want to pass in.

See the attachments for an animated GIF.

1. if u just want to display i think label is better.
2. use public shared variable to pass value from one to another form.

Thanx , i'll create a label.
But im not quite sure how to pass Values.

May you help me please ?

Ok.. see this example.
we have 2 form, you want to pass value from textboxt in form1 to label in form2.
in form 1 :
declare this code after windows generated code or before events.

Public Shared temp As String

in whatever event in form 1

temp = textbox1.text

in Form 2.
you just take the value in temp

label1.text = form1.temp

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 ?

Ok heres what ive done. In form1 i had this code

Public Class Form1

Public Shared Diametral_Pitch As String

and in the NUD controller i had this 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

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.

Now i tried putting the code in the calculation Button

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.

no, you don't have to terminate program, just close form2 and open again cause code works in form load event. why you put label in form2 not in common feature form?

if you want value always update, you can use timer.
put timer control on your form and add the code in it. don't forget to set timer enable properties = true

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        label1.Text = Form1.temp
    End Sub

oh..and set timer interval = 1 to get fast update.

I solved the problem by doing nothing in form2 eveything was done in form1.

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.

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 ?

cause the equation is (1.2 / 4) + 0.002 in your code not 1.25/4

Great Notice. I fixed the problem.

How do i merge cells in TableLayoutPanel ? Where one label can take place of the two colums ?

well, i never do this. i works under .net 2003 and .net 2003 not including TableLayoutPanel.

I created a label and then used columnspan = 2

it merged.

oh. its already solved. great. i think that i must migrate from .net 2003 to higher. more controls not included here.

Why cant i get those two numbers to add together ?

My Button 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
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

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 ?

(CDbl(Common_Features.Dedendum.Text) + CDbl(Pinion_Features.Pitch_Radius1.Text)).ToString

It adds Now what does CDbl actually does ??

I think i was doing text's together !

"Hello" + "World" = HelloWorld

are you have already solved them??

Two Questions.

First Question: Adding a timer will update the values every 1 second if changed ??


Second Question:

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 ?

(( See attachment for picture))

heres my code what shall i modify ??

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
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_Radiusp1.Text = (Pinion_Features.pinion1.Text / Diametral_Pitch).ToString / 2
        Pinion_Features.Pitch_Radiusp2.Text = (Pinion_Features.Pitch_Radiusp1.Text * 25.4).ToString

        Pressure_Angle = resultdp.Text
        Pinion_Features.Base_Circlep1.Text = (Pinion_Features.Pitch_Radiusp1.Text) * Math.Cos(Pressure_Angle)
        Pinion_Features.Base_Circlep2.Text = (Pinion_Features.Base_Circlep1.Text * 25.4).ToString


        Pinion_Features.Outer_Circlep1.Text = CDbl(Common_Features.Dedendum.Text) + CDbl(Pinion_Features.Pitch_Radiusp1.Text).ToString
        Pinion_Features.Outer_Circlep2.Text = CDbl(Pinion_Features.Outer_Circlep1.Text * 25.4).ToString

        Pinion_Features.Root_Radiusp1.Text = CDbl(Pinion_Features.Pitch_Radiusp1.Text) - CDbl(Common_Features.Dedendum.Text).ToString
        Pinion_Features.Root_Radiusp2.Text = CDbl(Pinion_Features.Root_Radiusp1.Text * 25.4).ToString

        Pinion_Features.Whole_Depthp1.Text = CDbl(Common_Features.Addendum.Text) + CDbl(Common_Features.Dedendum.Text).ToString
        Pinion_Features.Whole_Depthp2.Text = CDbl(Pinion_Features.Whole_Depthp1.Text * 25.4).ToString

        Pinion_Features.Working_Depthp1.Text = CDbl(Common_Features.Addendum.Text * 2).ToString
        Pinion_Features.Working_Depthp2.Text = CDbl(Pinion_Features.Working_Depthp1.Text * 25.4).ToString



        second.Show()
        Me.Hide()

    End Sub

Thanx. I can see you have explained the concept in general.

As for the first error. I debugged but still have no clue.

Dim intPA As Integer
        If Not String.IsNullOrEmpty(Pa.Text) AndAlso Not Pa.Text = "" Then

            If Not Double.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

As for error 2

Pa.Text = 25 
'related to error1

As for the errors 4

Dim intPA As Integer
        Integer.TryParse(Pa.Text, intPA)
        resultdp.Text = (intPA * Math.PI) / 180

As for error 5:
Diametral_Pitch

Common_Features.Addendum.Text = (1 / (Diametral_Pitch))

set strict on to off. it will make error. why you want to set it on??

To fix all errors that wont make my code sloppy..

I would love to learn how to


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.

How man i fix this ?

Public Class Form1
    Dim Pressure_Angle_Result As Double
    Dim Pressure_angle_Radian As Double
Dim Diametral_Pitch As Double
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
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.

Double to String Error

Common_Features.Addendum.Text = (1 / (Diametral_Pitch))

Correction:

Common_Features.Addendum.Text = (1 / (Diametral_Pitch)).ToString

How do i fix the String to Double error for this one ?

Common_Features.Addendum1.Text = (Common_Features.Addendum.Text) * 25.4

Correction :

Common_Features.Addendum1.Text = (CDbl(Common_Features.Addendum.Text) * 25.4).ToString

just set option strict to off. you make this more harder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.