View Full Version : VS 2005 VB - Just a Note on Casting Text to Double

03-29-2009, 08:16 PM

Just thought I would share this with you and maybe get some feed back too. I am kinda new to Visual Studios 2005 using VB and I was creating a special calculator for sheet metal bending. Well I noticed that if I used a Dialog box with the stock buttons (using the Me.Stuff.....) and I inserted my code in them I got a casting error on the text box array to my Double variables; But on another similar program I did not get these errors. Well it took me about an hour before I realized the one difference between the two programs was that on the one that did work, I had made my own button without all that (Me.Stuff) and it was able to cast string arrays from my text box input to a Double. If I used the stock dialog buttons that had the (Me.Stuff...) I got Casting errors and no matter what I did such as CDbl, or Double.Parse nothing worked, made my own simple button and it worked.

WTF :dunno

Anyone have a reason why?

03-30-2009, 11:00 AM
Can I see the actual code? I had a similar problem but it was because I was using ByVal instead of ByRef.

03-30-2009, 05:24 PM
Can I see the actual code? I had a similar problem but it was because I was using ByVal instead of ByRef.

Sure, This code works bellow as is:

Private Sub Button_Unfold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Unfold.Click
'Math Here
Dim legL1, legL2, legL3, legL4, legL5, matThk As Double
Dim capLipTop, capLipBtm, faceLength, bendRad, cutTo As Double
Dim partNumber, rev, matType As String
Dim fsb, hsb, bndL1, bndL2, bndL3, bndL4, bndL5end As Double

matType = TextBoxMatType.Text
matThk = TextBoxMatThk.Text
bendRad = TextBoxBndRad.Text
legL1 = TextBoxLeg1.Text
legL2 = TextBoxLeg2.Text
legL3 = TextBoxLeg3.Text
legL4 = TextBoxLeg4.Text
legL5 = TextBoxLeg5.Text
capLipTop = TextBoxECTL.Text
capLipBtm = TextBoxECBL.Text
faceLength = TextBoxFaceLength.Text
partNumber = TextBoxPrtNum.Text
rev = TextBoxRev.Text

fsb = (1.298 * matThk) + (0.4295 * bendRad)
hsb = (fsb / 2)
bndL1 = (legL1 - hsb)
bndL2 = (legL2 - fsb)
bndL3 = (legL3 - fsb)
bndL4 = (legL4 - fsb)
bndL5end = (legL5 - hsb)
cutTo = (bndL1 + bndL2 + bndL3 + bndL4 + bndL5end)
'now send values to another dialog box:
T6_FP.TextBoxPrtNum.Text = partNumber
T6_FP.TextBoxRev.Text = rev
T6_FP.TextBoxMatType.Text = matType
T6_FP.TextBoxFaceWidth.Text = faceLength
T6_FP.TextBoxBndLine1.Text = bndL1
T6_FP.TextBoxBndLine2.Text = bndL2
T6_FP.TextBoxBndLine3.Text = bndL3
T6_FP.TextBoxBndLine4.Text = bndL4
T6_FP.TextBoxBndEnd.Text = bndL5end
T6_FP.TextBoxCutTo.Text = cutTo
T6_FP.TextBoxHSB.Text = hsb
T6_FP.TextBoxFSB.Text = fsb

End Sub
End Class

But the same code under this stock button code is where I got the casting errors:

Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.OK

'code here did not work

End Sub