Visual Studio Development Bookmark and Share   
 index > Visual Basic Express Edition > Textbox changes during click event.
 

Textbox changes during click event.

I have a small problem with my click event.
I am using a textbox leave event to populate another textbox and using the second textbox in my calculations.
At some point I would lke to change the second textbox manually.
The probelm: when I manually change the textbox and click the button for the calculations (click event), the second text box reverts back to the original data. I need the second text box to keep what ever data I would manually put in.
I am not quite sure where I am going wrong.

 

Thanks again,
Flabroach

flabroach  Monday, October 05, 2009 7:08 PM
You can do it any way you wish.  Commit yourself to one path.
Please stop changing the requirements in the middle of the design. 
You get absolutely nothing done that way.  Case in point, this thread is still unanswered.


First make something that works, THEN make it better.
More times than not, that 'better' idea you had before it worked gets superseded by an even better idea after you get it working.


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer byflabroach Thursday, October 15, 2009 4:31 PM
  •  
Rudedog2  Thursday, October 15, 2009 4:11 PM

probably need to use a variable, and assign it's value to TextBox1.Text. Use that to populate TextBox2. Then update the variable any time TextBox2 is changed

Dim myText As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(myText)
    End Sub

    Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave
        myText = TextBox1.Text
        TextBox2.Text = myText
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        myText = TextBox2.Text
    End Sub
jwavila  Monday, October 05, 2009 7:22 PM
jwavila,

I already have code for both the leave event and the click event.
Code is as follows:

 

Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
'Check to make sure there is data in textbox
If (Me.LOC.Text = Nothing) Then
MsgBox("Please Enter Data!")
Me.LOC.Focus()
Return
End If
'Check to make sure there is data in textbox
If (Me.OD.Text = Nothing) Then
MsgBox("Please Enter Data!")
Me.OD.Focus()
Return
End If
'Check to make sure there is data in textbox
If (Me.ID.Text = Nothing) Then
MsgBox("Please Enter Data!")
Me.ID.Focus()
Return
End If
'Check to make sure there is data in textbox
If (Me.Taper.Text = Nothing)Then
MsgBox("Please Enter Data!")
Me.Taper.Focus()
Return
End If
If (Me.FinishTeeth.Text = Nothing) Then
MsgBox("Please Enter Data!")
Me.FinishTeeth.Focus()
Return
End If
'
Check to make sure there is data in textbox
If (Me.Edge.Text = Nothing) Then
MsgBox("Please Enter Data")
Me.Edge.Focus()
Return
End If
'Check to make sure there is data in textbox
If (Me.PartMaterial.Text = Nothing) Then
MsgBox("Please Enter Data!")
Me.PartMaterial.Focus()
Return
End If
'Check to make sure there is data in textbox
myBroachMaterial = BroachMaterial.Text
If (BroachMaterial.Text = Nothing) Then
MsgBox("What Broach Material Should Be Used?")
Me.BroachMaterial.Focus()
Return
End If
'Check to make sure there is data in textbox
If Me.PullType.Enabled = True Then
If (Me.PullType.Text = Nothing) Then
MsgBox("Puller Type Is Required: Please Enter Puller Type")
Me.PullType.Focus()
Return
End If
End If
'Check to make sure there is data in textbox
If Me.PullSize.Enabled = True Then
If (Me.PullSize.Text = Nothing) Then
MsgBox("Puller Size Is Required: Please Enter Puller Size")
Me.PullSize.Focus()
Return
End If
End If
'Check to make sure there is data in textbox
If (Me.PullLength.Text = Nothing) Then
MsgBox("Puller Length Is Required: Please Enter Puller Length")
Me.PullLength.Focus()
Return
End If
'Start of calculations
myOD = Me.OD.Text
OD.Text = Val(myOD)
OD.Text = Format(myOD,
"###,###.####")
myID = Val(
Me.ID.Text)
ID.Text = Format(myID,
"###,###.####")
myTaper =
Me.Taper.Text
myPitch = Val(
Me.Pitch.Text)
If SemiTeeth.Value = 8 Then
ydelta = 0.008
ElseIf SemiTeeth.Value = 7 Then
mydelta = 0.007
ElseIf SemiTeeth.Value = 6 Then
mydelta = 0.006
ElseIf SemiTeeth.Value = 5 Then
mydelta = 0.005
ElseIf SemiTeeth.Value = 4 Then
mydelta = 0.004
ElseIf SemiTeeth.Value = 3 Then
mydelta = 0.003
ElseIf SemiTeeth.Value = 2 Then
mydelta = 0.002
ElseIf SemiTeeth.Value = 1 Then
mydelta = 0.001
ElseIf SemiTeeth.Value = 0 Then
mydelta = 0
End If
Call myRoundStockRemoval()
StockRemoval.Text = myRoundStockRemoval()
myTh_Engaged = myLOC / myPitch
Me.ThEngaged.Text = Val(myTh_Engaged)
hEngaged.Text = Format(myTh_Engaged,
"#.####")
Me.TeethEngaged.Text = Math.Ceiling(myTh_Engaged)
myTaper_Teeth = Val(
Me.StockRemoval.Text) / Val(Me.Taper.Text)
Me.TaperTeeth.Text = Val(myTaper_Teeth)
Me.TaperTeeth.Text = Math.Ceiling(myTaper_Teeth)
mySemiTeeth =
Me.SemiTeeth.Value
myFinish_Teeth =
Me.FinishTeeth.Value
myTotal_Teeth = myTaper_Teeth + mySemiTeeth + myFinish_Teeth
myTotal_Teeth = Math.Ceiling(myTotal_Teeth)
Me.TotalTeeth.Text = Val(myTotal_Teeth)
mySpaces = myTotal_Teeth - 1
calculated_spaces = myRoundStockRemoval() / myTaper
Me.Spaces.Text = Val(mySpaces)
myCutting_Teeth_Length = (mySpaces * Pitch.Text)
CuttingTeethLength.Text = Val(myCutting_Teeth_Length)
myStroke = myCutting_Teeth_Length + myLOC
Stroke.Text = Format(myStroke,
"##,###.##")
myRearPilot = myLOC * myPitch
myPuller = Val(
Me.PullLength.Text)
myBroachEnd = Val(
Me.BroachEndLength.Text)
myOAL = Val(myCutting_Teeth_Length + myPuller + myRearPilot + myBroachEnd)
myOAL = Math.Round(myOAL, 4, MidpointRounding.AwayFromZero)
Me.BroachLength.Text = Format(myOAL, "###,###.####")
adjusted_rear_pilot = myOAL - (myCutting_Teeth_Length + myPuller + myBroachEnd)
If adjusted_rear_pilot < 2 * myPitch Then
adjusted_rear_pilot = adjusted_rear_pilot + 1
End If
Me.RearPilot.Text = adjusted_rear_pilot
C
all OverAllLength()
Me.BroachLength.Text = OverAllLength()
'Start calculations for forces
myPartMaterial = Me.PartMaterial.Text
Select Case myPartMaterial
Case "Aluminum"
Me.BroachingConstant.Text = 350000
Case "Brass"
Me.BroachingConstant.Text = 200000
Case "Bronze"
Me.BroachingConstant.Text = 350000
Case "Bronze - Soft"
Me.BroachingConstant.Text = 200000
Case "Bronze - Phox."
Me.BroachingConstant.Text = 200000
Case "Copper"
Me.BroachingConstant.Text = 250000
Case "Iron - Cast"
Me.BroachingConstant.Text = 350000
Case "Iron - Malleable"
M
e.BroachingConstant.Text = 300000
Case "Iron - Meehanite"
Me.BroachingConstant.Text = 300000
Case "Iron - Pearlitic"
Me.BroachingConstant.Text = 300000
Case "Stainless Steel"
M
e.BroachingConstant.Text = 650000
Case "Stainless, 15-5/17-4 PH"
Me.BroachingConstant.Text = 700000
Case "Steel - Casting"
Me.BroachingConstant.Text = 450000
Case "Steel - Forged"
Me.BroachingConstant.Text = 550000
Case "Steel - Hot-rolled"
Me.BroachingConstant.Text = 500000
Case "Steel - Mild"
Me.BroachingConstant.Text = 450000
Case "Steel - Nickel"
Me.BroachingConstant.Text = 600000
Case "Steel - SAE 1010-2512"
Me.BroachingConstant.Text = 450000
Case "Steel - SAE 3115-4615"
Me.BroachingConstant.Text = 500000
Case "Steel - SAE 5120-6195"
Me.BroachingConstant.Text = 550000
Case "Steel - 11L14, 12L15"
Me.BroachingConstant.Text = 450000
Case "Zinc"
Me.BroachingConstant.Text = 350000
Case "Zinc - Die Cast"
Me.BroachingConstant.Text = 350000
Case "Inconel"
Me.BroachingConstant.Text = 650000
Case "Monel"
Me.BroachingConstant.Text = 650000
Case "Nitralloy"
Me.BroachingConstant.Text = 600000
Case "Waspaloy"
Me.BroachingConstant.Text = 650000
Case Else
Me.BroachingConstant.Text = 500000
End Select
myBroachingConstant = Val(BroachingConstant.Text)
myedge = Val(
Me.Edge.Text)
myTh_Engaged = Val(
Me.TeethEngaged.Text)
Call myPullForce()
Me.Force.Text = myPullForce()
If myGulletDepth > Val(ID.Text / 6) Then
myGulletDepth = Val(ID.Text / 6)
myGulletDepth = Format(myGulletDepth,
"###,###.###")
End If
Me.GulletDepth.Text = myGulletDepth
Call myslender()
SlenderRatio.Text = myslender()
Call myChipRatio()
ChipRatio.Text = myChipRatio()
If myChipRatio() < 1.75 Then
MsgBox("Chip Ratio May Be Of Concern", MsgBoxStyle.OkOnly, "Chip Ratio")
End If
Call myFirstToothTS()
Me.FirstToothTensileStrength.Text = myFirstToothTS()
'Calculations for steel purchase
mySteelLength = OverAllLength() + 0.06
Me.SteelLength.Text = Val(mySteelLength)
SteelLength.Text = Format(mySteelLength,
"###,###.###")mySteelDiameter = myOD + 0.06
Me.SteelDiameter.Text = Val(mySteelDiameter)
SteelDiameter.Text = Format(mySteelDiameter,
"###,###.###")
Select Case myBroachMaterial
Case "M2"
myDensity = 0.294
Case "M3"
myDensity = 0.295
Case "PM-M4"
myDensity = 0.288
Case "PM-T15"
myDensity = 0.296
Case "M42"
myDensity = 0.282
End Select
Call RoundSteelWeight()
Me.SteelWeight.Text = RoundSteelWeight()
Me.TabControl1.SelectTab("DataTab")
LOC.Focus()
If myPullForce() > (myFirstToothTS() * 0.85) Then
Me.Force.BackColor = Color.LightSalmon
Me.FirstToothTensileStrength.BackColor = Color.LightSalmon
MsgBox(
" Check Pull Force Ratio ", MsgBoxStyle.OkOnly, "Pull Force Analysis")
ElseIf myPullForce() < (myFirstToothTS() * 0.85) Then
Me.Force.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
Me.FirstToothTensileStrength.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
End If
If myPullForce() > Val(TensileStrength.Text * 0.85) Then
Me.Force.BackColor = Color.LightSalmon
Me.TensileStrength.BackColor = Color.LightSalmon
ElseIf myPullForce() < Val(TensileStrength.Text * 0.85) Then
Me.Force.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
Me.TensileStrength.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
End If
End Sub


Any suggestions?
Flabroach

flabroach  Monday, October 05, 2009 8:24 PM
Since you have about a million textboxes...

I don't know which 2 textboxes you are talking about.

Also, can you re-post your code? Click the </> button above, then in the language drop-down select VB.NET
jwavila  Monday, October 05, 2009 8:44 PM
Sorry about that.
I diod bnot know how to get the code in the message.
Now I do.

I am looking at the LOC textbox and the Pitch textbox.
The LOC textbox will fill the Pitch textbox.
But if I need to change the Pitch then I cannot have the pitch revert back to the original data supplied by the LOC text box.
Thanks,

Flabroach

    Private Sub LOC_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles LOC.Leave
        'Get pitch data from legnth of cut
        myLOC = Val(Me.LOC.Text)
        LOC.Text = Format(myLOC, "###,###.####")

        Select Case myLOC
            Case Is > 12
                MsgBox("There are no standard pitches for this length of cut!", MsgBoxStyle.OkOnly, "Pitch")
            Case Is >= 8.25
                Me.Pitch.Text = 1.25
                myGulletDepth = 0.5
                myGulletArea = 0.3144
            Case Is >= 7.25
                Me.Pitch.Text = 1.0
                myGulletDepth = 0.4
                myGulletArea = 0.2012
            Case Is >= 6.25
                Me.Pitch.Text = 0.9375
                myGulletDepth = 0.375
                myGulletArea = 0.1769
            Case Is >= 5.5
                Me.Pitch.Text = 0.875
                myGulletDepth = 0.35
                myGulletArea = 0.1541
            Case Is >= 4.75
                Me.Pitch.Text = 0.8125
                myGulletDepth = 0.325
                myGulletArea = 0.1328
            Case Is >= 4
                Me.Pitch.Text = 0.75
                myGulletDepth = 0.3
                myGulletArea = 0.1132
            Case Is >= 3.25
                Me.Pitch.Text = 0.6875
                myGulletDepth = 0.275
                myGulletArea = 0.0951
            Case Is >= 2.5
                Me.Pitch.Text = 0.625
                myGulletDepth = 0.25
                myGulletArea = 0.0786
            Case Is >= 2
                Me.Pitch.Text = 0.5625
                myGulletDepth = 0.225
                myGulletArea = 0.0637
            Case Is >= 1.62
                Me.Pitch.Text = 0.5
                myGulletDepth = 0.2
                myGulletArea = 0.0503
            Case Is >= 1.25
                Me.Pitch.Text = 0.4375
                myGulletDepth = 0.175
                myGulletArea = 0.0385
            Case Is >= 0.88
                Me.Pitch.Text = 0.375
                myGulletDepth = 0.15
                myGulletArea = 0.0283
            Case Is >= 0.75
                Me.Pitch.Text = 0.34375
                myGulletDepth = 0.138
                myGulletArea = 0.0238
            Case Is >= 0.62
                Me.Pitch.Text = 0.3125
                myGulletDepth = 0.125
                myGulletArea = 0.0197
            Case Is >= 0.5
                Me.Pitch.Text = 0.28125
                myGulletDepth = 0.112
                myGulletArea = 0.0159
            Case Is >= 0.38
                Me.Pitch.Text = 0.25
                myGulletDepth = 0.1
                myGulletArea = 0.0126
            Case Is >= 0.25
                Me.Pitch.Text = 0.21875
                myGulletDepth = 0.088
                myGulletArea = 0.0096
            Case Is >= 0.22
                Me.Pitch.Text = 0.1875
                myGulletDepth = 0.075
                myGulletArea = 0.0071
            Case Is >= 0.19
                Me.Pitch.Text = 0.15625
                myGulletDepth = 0.062
                myGulletArea = 0.0048
            Case Is >= 0.12
                Me.Pitch.Text = 0.125
                myGulletDepth = 0.05
                myGulletArea = 0.0031
            Case Is < 0.12
                Me.Pitch.Text = 0.0625
                myGulletDepth = 0.025
                myGulletArea = 0.0008
        End Select
        myPitch = Val(Me.Pitch.Text)
        'myPullerLength = myLOC + 9.0
        'myPullerLength = Math.Round(myPullerLength, 3)
        'Me.PullLength.Text = myPullerLength
    End Sub

    Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
        'Check to make sure there is data in textbox
        If (Me.LOC.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.LOC.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If (Me.OD.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.OD.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If (Me.ID.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.ID.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If (Me.Taper.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.Taper.Focus()
            Return
        End If
        If (Me.FinishTeeth.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.FinishTeeth.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If (Me.Edge.Text = Nothing) Then
            MsgBox("Please Enter Data")
            Me.Edge.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If (Me.PartMaterial.Text = Nothing) Then
            MsgBox("Please Enter Data!")
            Me.PartMaterial.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        myBroachMaterial = BroachMaterial.Text
        If (BroachMaterial.Text = Nothing) Then
            MsgBox("What Broach Material Should Be Used?")
            Me.BroachMaterial.Focus()
            Return
        End If
        'Check to make sure there is data in textbox
        If Me.PullType.Enabled = True Then
            If (Me.PullType.Text = Nothing) Then
                MsgBox("Puller Type Is Required: Please Enter Puller Type")
                Me.PullType.Focus()
                Return
            End If
        End If
        'Check to make sure there is data in textbox
        If Me.PullSize.Enabled = True Then
            If (Me.PullSize.Text = Nothing) Then
                MsgBox("Puller Size Is Required: Please Enter Puller Size")
                Me.PullSize.Focus()
                Return
            End If
        End If
        'Check to make sure there is data in textbox
        If (Me.PullLength.Text = Nothing) Then
            MsgBox("Puller Length Is Required: Please Enter Puller Length")
            Me.PullLength.Focus()
            Return
        End If

        'Start of calculations 
        myOD = Me.OD.Text
        OD.Text = Val(myOD)
        OD.Text = Format(myOD, "###,###.####")
        myID = Val(Me.ID.Text)
        ID.Text = Format(myID, "###,###.####")
        myTaper = Me.Taper.Text


        If SemiTeeth.Value = 8 Then
            mydelta = 0.008
        ElseIf SemiTeeth.Value = 7 Then
            mydelta = 0.007
        ElseIf SemiTeeth.Value = 6 Then
            mydelta = 0.006
        ElseIf SemiTeeth.Value = 5 Then
            mydelta = 0.005
        ElseIf SemiTeeth.Value = 4 Then
            mydelta = 0.004
        ElseIf SemiTeeth.Value = 3 Then
            mydelta = 0.003
        ElseIf SemiTeeth.Value = 2 Then
            mydelta = 0.002
        ElseIf SemiTeeth.Value = 1 Then
            mydelta = 0.001
        ElseIf SemiTeeth.Value = 0 Then
            mydelta = 0
        End If

        Call myRoundStockRemoval()
        StockRemoval.Text = myRoundStockRemoval()
        myTh_Engaged = myLOC / myPitch
        Me.ThEngaged.Text = Val(myTh_Engaged)
        ThEngaged.Text = Format(myTh_Engaged, "#.####")
        Me.TeethEngaged.Text = Math.Ceiling(myTh_Engaged)
        myTaper_Teeth = Val(Me.StockRemoval.Text) / Val(Me.Taper.Text)
        Me.TaperTeeth.Text = Val(myTaper_Teeth)
        Me.TaperTeeth.Text = Math.Ceiling(myTaper_Teeth)
        mySemiTeeth = Me.SemiTeeth.Value
        myFinish_Teeth = Me.FinishTeeth.Value
        myTotal_Teeth = myTaper_Teeth + mySemiTeeth + myFinish_Teeth
        myTotal_Teeth = Math.Ceiling(myTotal_Teeth)
        Me.TotalTeeth.Text = Val(myTotal_Teeth)
        mySpaces = myTotal_Teeth - 1
        calculated_spaces = myRoundStockRemoval() / myTaper
        Me.Spaces.Text = Val(mySpaces)
        myCutting_Teeth_Length = (mySpaces * Pitch.Text)
        CuttingTeethLength.Text = Val(myCutting_Teeth_Length)
        myStroke = myCutting_Teeth_Length + myLOC
        Stroke.Text = Format(myStroke, "##,###.##")
        myRearPilot = myLOC * myPitch
        myPuller = Val(Me.PullLength.Text)
        myBroachEnd = Val(Me.BroachEndLength.Text)
        myOAL = Val(myCutting_Teeth_Length + myPuller + myRearPilot + myBroachEnd)
        myOAL = Math.Round(myOAL, 4, MidpointRounding.AwayFromZero)
        Me.BroachLength.Text = Format(myOAL, "###,###.####")
        adjusted_rear_pilot = myOAL - (myCutting_Teeth_Length + myPuller + myBroachEnd)
        If adjusted_rear_pilot < 2 * myPitch Then
            adjusted_rear_pilot = adjusted_rear_pilot + 1
        End If
        Me.RearPilot.Text = adjusted_rear_pilot
        Call OverAllLength()
        Me.BroachLength.Text = OverAllLength()

        'Start calculations for forces
        myPartMaterial = Me.PartMaterial.Text
        Select Case myPartMaterial
            Case "Aluminum"
                Me.BroachingConstant.Text = 350000
            Case "Brass"
                Me.BroachingConstant.Text = 200000
            Case "Bronze"
                Me.BroachingConstant.Text = 350000
            Case "Bronze - Soft"
                Me.BroachingConstant.Text = 200000
            Case "Bronze - Phox."
                Me.BroachingConstant.Text = 200000
            Case "Copper"
                Me.BroachingConstant.Text = 250000
            Case "Iron - Cast"
                Me.BroachingConstant.Text = 350000
            Case "Iron - Malleable"
                Me.BroachingConstant.Text = 300000
            Case "Iron - Meehanite"
                Me.BroachingConstant.Text = 300000
            Case "Iron - Pearlitic"
                Me.BroachingConstant.Text = 300000
            Case "Stainless Steel"
                Me.BroachingConstant.Text = 650000
            Case "Stainless, 15-5/17-4 PH"
                Me.BroachingConstant.Text = 700000
            Case "Steel - Casting"
                Me.BroachingConstant.Text = 450000
            Case "Steel - Forged"
                Me.BroachingConstant.Text = 550000
            Case "Steel - Hot-rolled"
                Me.BroachingConstant.Text = 500000
            Case "Steel - Mild"
                Me.BroachingConstant.Text = 450000
            Case "Steel - Nickel"
                Me.BroachingConstant.Text = 600000
            Case "Steel - SAE 1010-2512"
                Me.BroachingConstant.Text = 450000
            Case "Steel - SAE 3115-4615"
                Me.BroachingConstant.Text = 500000
            Case "Steel - SAE 5120-6195"
                Me.BroachingConstant.Text = 550000
            Case "Steel - 11L14, 12L15"
                Me.BroachingConstant.Text = 450000
            Case "Zinc"
                Me.BroachingConstant.Text = 350000
            Case "Zinc - Die Cast"
                Me.BroachingConstant.Text = 350000
            Case "Inconel"
                Me.BroachingConstant.Text = 650000
            Case "Monel"
                Me.BroachingConstant.Text = 650000
            Case "Nitralloy"
                Me.BroachingConstant.Text = 600000
            Case "Waspaloy"
                Me.BroachingConstant.Text = 650000
            Case Else
                Me.BroachingConstant.Text = 500000
        End Select
        myBroachingConstant = Val(BroachingConstant.Text)
        myedge = Val(Me.Edge.Text)
        myTh_Engaged = Val(Me.TeethEngaged.Text)
        Call myPullForce()
        Me.Force.Text = myPullForce()
        If myGulletDepth > Val(ID.Text / 6) Then
            myGulletDepth = Val(ID.Text / 6)
            myGulletDepth = Format(myGulletDepth, "###,###.###")
        End If
        Me.GulletDepth.Text = myGulletDepth
        Call myslender()
        SlenderRatio.Text = myslender()
        Call myChipRatio()
        ChipRatio.Text = myChipRatio()
        If myChipRatio() < 1.75 Then
            MsgBox("Chip Ratio May Be Of Concern", MsgBoxStyle.OkOnly, "Chip Ratio")
        End If
        Call myFirstToothTS()
        Me.FirstToothTensileStrength.Text = myFirstToothTS()
        'Calculations for steel purchase
        mySteelLength = OverAllLength() + 0.06
        Me.SteelLength.Text = Val(mySteelLength)
        SteelLength.Text = Format(mySteelLength, "###,###.###")
        mySteelDiameter = myOD + 0.06
        Me.SteelDiameter.Text = Val(mySteelDiameter)
        SteelDiameter.Text = Format(mySteelDiameter, "###,###.###")
        Select Case myBroachMaterial
            Case "M2"
                myDensity = 0.294
            Case "M3"
                myDensity = 0.295
            Case "PM-M4"
                myDensity = 0.288
            Case "PM-T15"
                myDensity = 0.296
            Case "M42"
                myDensity = 0.282
        End Select
        Call RoundSteelWeight()
        'mySteelWeight = ((((mySteelDiameter ^ 2 * Math.PI) / 4) * myOAL) * myDensity)
        Me.SteelWeight.Text = RoundSteelWeight()
        'SteelWeight.Text = Format(mySteelWeight, "###,###.###")
        Me.TabControl1.SelectTab("DataTab")
        LOC.Focus()
        If myPullForce() > (myFirstToothTS() * 0.85) Then
            Me.Force.BackColor = Color.LightSalmon
            Me.FirstToothTensileStrength.BackColor = Color.LightSalmon
            MsgBox(" Check Pull Force Ratio ", MsgBoxStyle.OkOnly, "Pull Force Analysis")
        ElseIf myPullForce() < (myFirstToothTS() * 0.85) Then
            Me.Force.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
            Me.FirstToothTensileStrength.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
        End If
        If myPullForce() > Val(TensileStrength.Text * 0.85) Then
            Me.Force.BackColor = Color.LightSalmon
            Me.TensileStrength.BackColor = Color.LightSalmon
        ElseIf myPullForce() < Val(TensileStrength.Text * 0.85) Then
            Me.Force.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
            Me.TensileStrength.BackColor = System.Windows.Forms.TextBox.DefaultBackColor
        End If
    End Sub

flabroach  Monday, October 05, 2009 8:55 PM
first, I would take out the Select Case from the TextBox_Leave (you'll see why below) event and put it in the TextBox_Validating event.

Also use Double.TryParse instead of Val - unless you can say with 100% you will never type the wrong data into the textboxes.

then I would take out the check for all the textboxes from the button click event, and put that into a separate sub. Add a handle for each textbox you want to this Sub. Then you can verify all the textboxes with a couple lines of code

as far as the value from the Pitch textbox, as I said assign the correct value from the value of the LOC textbox to a variable. Then if you change the Pitch textbox, you change the variable.

try this in a new app with 1 button and 2 textboxes. you'll see how it all works. Look at the Handles for the VerifyTB Sub. Also try typing a letter in each of these textboxes - if you try that in your code, you'll probably get a crash


Dim dblPitch As Double
    Dim myLOC As Double

    Private Sub VerifyTB(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles TextBox1.Leave, TextBox2.Leave

        Dim tb As TextBox = CType(sender, TextBox)
        If tb.TextLength = 0 Then
            MessageBox.Show("Please enter data")
            tb.Focus()
            tb.Select()
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MessageBox.Show(dblPitch.ToString)

        MessageBox.Show((dblPitch * myLOC).ToString)
    End Sub

    Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

        If Not Double.TryParse(TextBox1.Text, myLOC) Then
            e.Cancel = True
            TextBox1.Select(0, TextBox1.Text.Length)
        Else
            Select Case myLOC
                Case Is >= 10
                    dblPitch = 1.25
                Case Is >= 5
                    dblPitch = 1.0
                Case Is >= 2.5
                    dblPitch = 0.75
                Case Is > 0
                    dblPitch = 0.5
            End Select
            TextBox2.Text = dblPitch.ToString
        End If

    End Sub

    Private Sub TextBox2_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
        If Not Double.TryParse(TextBox2.Text, dblPitch) Then
            e.Cancel = True
            TextBox2.Select(0, TextBox2.Text.Length)
        End If
    End Sub



jwavila  Tuesday, October 06, 2009 5:27 AM

jwavila ,
I have done the textbox_validating sub that you suggexted with the selcet case.
I may have forgotten to tell you that I have the Pitch textbox bound to a data source so the user can choose any number of different pitches.
This may be causing the problem because it still does the same thing.
I am working on the "VerifyTB" now but have trouble with the pull down boxes.

Well, I finished with the Leave event for the textboxes and now I cannot  exit the application.
I believe that is why I put it in the Click Event.
Thanks in advance.
flabroach  Tuesday, October 06, 2009 12:45 PM

Well, I have tried the approach from the previous posts.
It still has not solved my problem.
Let me articulate a little further.

The "Pitch" is the most important aspect of the program.
I have databound the pitch textbox to populate the textbox.
The "LOC" controls what "Pitch" is to be used.
Sometimes the user will want a different "Pitch" than what the "LOC" determines.
The user then can manually pick from the databound "Pitch" textbox and use that as the primary driver for the program.
Since I need the "LOC" textbox to at least start the user on the right path to the correct "Pitch",
how can I use the "LOC" textbox to tell the databound "Pitch" texbox to display what should be the correct "Pitch"?

Thanks for helping on thsi matter.

flabroach

flabroach  Wednesday, October 07, 2009 7:50 PM
jwavila,

I have done what you have suggested again. I made a new form with two textboxes and a button and used your code supplied above.
If you use your code, you cannot change the textbox2 value at all. It does not allow for any change whatsoever.
It actually does not work if you try to change the value.
I would need to be able to change the textbox2 value, and use that value in my final calculations.

I have used this forum for a lot of information.
I did not think that my question would go unanswered for a week.
Can anyone help me with this particualr problem.

Much appreciated.

flabroach
flabroach  Wednesday, October 14, 2009 7:39 PM

Please don't act surprised that it has gone on for a week unresolved.  It's your own fault.
You keep changing the scenario.  "Oh that doesn't work because I forgot to mention something."

Every suggestion would have worked, but not without all of the facts.
Here's my suggestion since you have a databound textbox.
I'm not going to write code to demonstrate this.

Add a button to change operating mode, "Auto" and "Manual".
Here's the confusing part.  Declare 3 Textbox objects.  Sorry no Form Designer support for this.

Dim TextBoxAuto as TextBox ' used when in "Auto" mode.
Dim TextBoxManual as TextBox ' used when in "Manual" mode.

Please note that when I say *used* above, that does mean *displayed*, just not at the same time.
Those objects will be referenced by the 3rd textbox, which does not display at all. 

Dim TextBoxReference as TextBox

When you switch modes, you will toggle the visible properties of the first 2 textboxes.  Display one or the other.
You will also set 'TextBoxReference' equal to either 'TextBoxAuto' or 'TextBoxManual', whichever is visible.

Why the 3rd TextBox?  If you have not figured it out by now, I will tell you.
When you do your calculations, you will use TextBoxReference exclusively. 
As long as it 'points' to the correct TB, everything should work out just fine.

Are you still with me on that? 

Rudedog   =8^D

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Wednesday, October 14, 2009 8:25 PM

Please don't act surprised that it has gone on for a week unresolved.  It's your own fault.
You keep changing the scenario.  "Oh that doesn't work because I forgot to mention something."


WOW !
WOW !
WOW !

Now I know why you have the nick you have.
Please excuse me for not being a programming wizard or having a master's degree in computer science.
I come here to try and learn from the experts.
Now I know not to question anything any more.

SORRY FOR THE INTERRUPTION.

That about shoots my programming fun.
I will try another forum.
Thanks for the people who don.t mind helping a struggling programmer.

Later.

flabroach

flabroach  Wednesday, October 14, 2009 9:22 PM
I help lots of people, especially struggling programmers.

I provided you with a description for a simple solution, but I was not sure if you would understand it.
Your posted code is untestable without several hours of work to recreate a form.
A form that would most likely not have all of the features that yours seems to have.
So why bother recreating one...which would also need to be bound to a database that I would have to reconstruct.

So I put forth a solution in words, and asked if you understood it.
I'll take that as a "no".  Too bad you gave up, because no one gave up on you.

Happy Coding.

Rudy   =8^D
Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Wednesday, October 14, 2009 9:41 PM
I gave your issue some more thought, and I think a custom control that behaves as I described above is the easiest thing to do.

You would need a to create two textboxes that sit on top of one another, but only displays.
You would need a property that shows which mode the custom control is in, make it boolean, ManualMode.
You would would need to expose the properties of the AutoTextBox that you need in order to bind it.  Resist making the control itself a property.
You would need to add an overloaded constructor that accepts a Button as a parameter so that you could implement the switching.
You would need to add a property to expose the "Text" property of the control for your data processing.

Are you still with me on that?

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Wednesday, October 14, 2009 10:10 PM
Your posted code is untestable without several hours of work to recreate a form.
A form that would most likely not have all of the features that yours seems to have.
So why bother recreating one...which would also need to be bound to a database that I would have to reconstruct.

So I put forth a solution in words, and asked if you understood it.
I'll take that as a "no".  Too bad you gave up, because no one gave up on you.
I absolutely have not given up, and I do not think that anyone gave up on me either.
I will continue to seek the answers to my problem whether at this forum or elsewhere.
I DO take offense to the way you offer your solutions with your own opinionated rhetoric.
I am trying to understand a language that is foreign to me, and I am ignorant  to the answers that I seek.
If somehow I offended you in my curiosity to solve a dilemma that I have created, then I must apologize.
My program is far from complete and I would like to at least finish this form which is one of 17 forms that I have already finished.

I understand the three textboxes you have suggested in the previous post and will try to implement that into a form.
I do not, however, understand the second post. Like I said.......ignorant.....



flabroach  Wednesday, October 14, 2009 11:41 PM
Here is what I have accomplished so far.
The form has three (3) textboxes
1) TextBoxAuto
2) TextBoxManual
3) TextBoxReference - set the property of this TB to visibility = false during run time

The form has three (3) buttons
1) Button1 - named "Auto"
2) Button2 - named "Manual"
3) Calculate Button

The following is the code for turning the textbox visiblity off and on.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBoxAuto.Visible = True
        TextBoxManual.Visible = False
        If TextBoxAuto.Visible = True Then
            TextBoxReference = TextBoxAuto
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBoxAuto.Visible = False
        TextBoxManual.Visible = True
        If TextBoxManual.Visible = True Then
            TextBoxReference = TextBoxManual
        End If
    End Sub
    Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
        MessageBox.Show(TextBoxReference.ToString)
    End Sub
I placed numbers in each textbox and toggled back and forth so the visibility changed.
Then when I clicked the Calculate button the correct number was displayed.
Is this the correct way to do this?

Thanks

flabraoch

flabroach  Thursday, October 15, 2009 12:49 PM
That is the basic idea. 

My vision had been for the Man/Auto textboxes to be of identical size and location.
Changing mode would simply swap textboxes with little change of appearance to the user....which could be a problem.
Providing the user some sort of visual cue would be good....changing backcolor of textbox and/or button?

Mark the best replies as answers. "Fooling computers since 1971."
  • Edited byRudedog2 Thursday, October 15, 2009 1:42 PM
  •  
Rudedog2  Thursday, October 15, 2009 1:25 PM

The If statements in the button click event handlers are unnecessary.

Dave299  Thursday, October 15, 2009 1:30 PM
Maybe I am going about this in the wrong matter.
Since I have the TextBox bound to the info I need anyway, can I make the first textbox give me the closest match and then I can choose if that is correct or not.

Like this:

1) TextBox1 - named LOC
2) TextBox2 - named Pitch (Make a small dataset that contains numbers running from .0625 to 1.25 in .0625 increments)

1) Button - Calculate

The LOC tb would have a calculation that goes (.35 * sqaure root of LOC)
Use the validating event for the LOC tb (I guess)
The calculation should get me close to the actual number I want to use.
Can we then grab the number that is closest to, but not under, that calculation?
Then when I use the textchanged event in the Pitch tb that would control the variable of Pitch
When the calculate button is clicked, the calculation could be (Pitch * Loc)
Does that make sense?
flabroach  Thursday, October 15, 2009 3:44 PM
You can do it any way you wish.  Commit yourself to one path.
Please stop changing the requirements in the middle of the design. 
You get absolutely nothing done that way.  Case in point, this thread is still unanswered.


First make something that works, THEN make it better.
More times than not, that 'better' idea you had before it worked gets superseded by an even better idea after you get it working.


Mark the best replies as answers. "Fooling computers since 1971."
  • Marked As Answer byflabroach Thursday, October 15, 2009 4:31 PM
  •  
Rudedog2  Thursday, October 15, 2009 4:11 PM

You can use google to search for other answers

Custom Search

More Threads

• Display problems for my application
• progressbar color...it can be done
• How to delete my data?
• Keydown on main window?
• Installation Issues
• What is the code to start mediaplayer with a button_click or a if then
• install in a certain place
• SQL UpdateCommand Troubles
• An amateurs question
• clocks and Excel, or ?