Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Visual Basic Help

  1. Aug 13, 2008 #1
    Ok I'm just starting to teach myself and I thought I could have at least gotten this part but I'm getting a Conversion from string "" to type 'Double' is not valid. error message.

    Code (Text):

    Private Sub StockPricetxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StockPricetxt.TextChanged
            Dim StockPricetxt As Double
            StockPricetxt = ""
        End Sub
     
    What's happening when I test it is the second you put anything in the text box it freezes and return the error message above. The larger code will be to take this value and another and divide them. I'm assuming it has to do with the use of double but i'm lost. I would appreciate any help you all could give me. Using VB 2008 btw.


    Also, great forum I've been surfing it for a little while now and it's a lot of good info to be had.
     
  2. jcsd
  3. Aug 13, 2008 #2
    Ok that problem is solved now I got a new one.

    Code (Text):

        Private Sub StockPricetxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StockPricetxt.TextChanged
            Dim StockPricetxt As Double
            StockPricetxt = CDbl(StockPricetxt)

        End Sub

        Private Sub EPStxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EPStxt.TextChanged
            Dim EPStxt As Double
            EPStxt = CDbl(EPStxt)
        End Sub

        [B]Private Sub PEtxt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PEtxt.TextChanged
            Dim PEtxt As Double
            PEtxt = StockPricetxt / EPStxt[/B]

        End Sub
     
    I'm trying to divide these values and the last sub bolded I'm having trouble with. It's telling me "Operator '/' is not defined for types 'System.Windows.Forms.TextBox'". Any ideas? I am searching this stuff on the web and can't come up with exact results to give me what I need.

    TIA
     
  4. Aug 18, 2008 #3
    Are you attempting to do arithmetic on text? (i.e. a string?).

    Convert the text to a double before attempting the divide.
     
  5. Aug 18, 2008 #4
    Thanks for the reply. I got it figured out, I used C# instead. I'm trying to teach myself quite a bit of this and I'm doing as much of it "example" based as possible. I couldn't find any good examples in VB but found a lot in C#. Thanks again.
     
  6. Aug 18, 2008 #5

    CRGreathouse

    User Avatar
    Science Advisor
    Homework Helper

    C# is better than Visual Basic, to be sure. Just be sure to do math on numbers, not strings or UI elements.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Visual Basic Help
  1. Visual Basic Help (Replies: 1)

  2. Visual Basic 5.0 help. (Replies: 12)

  3. Visual Basic Help (Replies: 2)

  4. Visual Basic Help (Replies: 1)

Loading...