Consulting

Results 1 to 3 of 3

Thread: VS 2005 VB - Just a Note on Casting Text to Double

  1. #1

    Cool VS 2005 VB - Just a Note on Casting Text to Double

    Hi,

    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

    Anyone have a reason why?
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

  2. #2
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    Can I see the actual code? I had a similar problem but it was because I was using ByVal instead of ByRef.

  3. #3
    Quote Originally Posted by Tommy
    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:

    [VBA]
    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

    T6_FP.Show()
    End Sub
    End Class

    [/VBA]


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

    [VBA]

    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
    [/VBA]
    My {Tube Amp} Building Forum
    http://www.dreamtone.org/Forum/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •