help a newbee (go to heaven). calculation problem with a textbox.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ikarias
    New Member
    • Jan 2007
    • 4

    help a newbee (go to heaven). calculation problem with a textbox.

    Maybe not the right place to aske this, but a newbee (me) needs help.

    i trying to input a number into a textbox, so i can make a series of calculations. in the old days of basic i just jused nrstring=val(in put) , but life isnt as easy anymore. I brewed something together as a test, but it failes on me.

    Public Class Form1


    Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

    End Sub

    Private Sub TextBox2_TextCh anged(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles output.TextChan ged

    End Sub

    Private Sub Label1_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Text1.Click

    End Sub

    Private Sub Button1_Click_1 (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    Dim volume As Integer
    Dim radius As Integer
    radius = CDbl("TextBox1" )
    volume = (4 / 3) * 3.14 * (radius * radius * radius)
    MsgBox(radius)
    End Sub
    End Class

    this is the code.

    Any help, will get you praised into heaven :-D.

    Tnxx in advance.
  • ikarias
    New Member
    • Jan 2007
    • 4

    #2
    ok, that looked kind of messy.
    The lines that should be the problem are:

    - Private Sub Button1_Click_1 (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
    - Dim volume As Integer
    - Dim radius As Integer
    - radius = Val(TextBox1.Te xt)
    - volume = (4 / 3) * 3.14 * (radius * radius * radius)
    - MsgBox(radius)
    - End Sub

    his is a changed version. I used Val here, doesnt seem to do the trick either. Sorry about the invenience.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by ikarias
      ...I brewed something together as a test, but it failes on me.
      Can you give us some idea of what goes wrong?

      I can point out one error, though...
      Code:
          radius = CDbl([U]"[/U]TextBox1[U]"[/U])
      Pretty sure you need to remove the quotes.

      At the moment you are simply trying to convert the string "TextBox1" to a number, which I believe will always produce zero. You should be using the control name TextBox1, which will return the default property of that control.

      Also, here's a tip. When posting here, please put CODE and /CODE tags around your code (see example above).

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by ikarias
        - volume = (4 / 3) * 3.14 * (radius * radius * radius)
        - MsgBox(radius)

        This is a changed version. I used Val here, doesnt seem to do the trick either. Sorry about the invenience.
        I think that's because you displayed radius instead of volume.

        (Probably not a good idea to use integers, either - you will lose a lot of precision.)

        Comment

        • ikarias
          New Member
          • Jan 2007
          • 4

          #5
          Originally posted by Killer42
          I think that's because you displayed radius instead of volume.

          (Probably not a good idea to use integers, either - you will lose a lot of precision.)
          The Volume calculation is just there as part of a larger whole.It can be ignored. The trouble is, the prog throws up at the Val(TextBox1.Te xt). And i have no idea why.


          One praise for you though.
          Last edited by ikarias; Jan 4 '07, 11:29 PM. Reason: typo's

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by ikarias
            The Volume calculation is just there as part of a larger whole.It can be ignored. The trouble is, the prog throws up at the Val(TextBox1.Te xt). And i have no idea why.
            Can you give us the specific details of how it "throws up"? Remember, in programming the details are everything.

            Comment

            • Ben3eeE
              New Member
              • Dec 2006
              • 8

              #7
              Code:
                  Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                      Dim volume As Decimal
                      Dim radius As Decimal
                      radius = CDbl(TextBox1.Text)
                      volume = (4 / 3) * 3.14 * (radius * radius * radius)
                      Label1.Text = volume
                  End Sub
              Works fine with both Val(textbox1.te xt) and CDbl(Textbox1.t ext).
              changed integer to decimal. And instead of msgbox(radius) i use
              label1.text = volume.

              Comment

              • ikarias
                New Member
                • Jan 2007
                • 4

                #8
                Originally posted by Ben3eeE

                Works fine with both Val(textbox1.te xt) and CDbl(Textbox1.t ext).
                changed integer to decimal. And instead of msgbox(radius) i use
                label1.text = volume.
                Indeed, it works fine now. I started from scratch, and pasted your code in it. I guess something was wrong with the surounding code, or my pc thought it was a monday. thank you thank you thank you a thousand times. You my friend, have a free ticket to heaven.

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  Originally posted by ikarias
                  Indeed, it works fine now. I started from scratch, and pasted your code in it. I guess something was wrong with the surounding code, or my pc thought it was a monday. thank you thank you thank you a thousand times. You my friend, have a free ticket to heaven.
                  That's nice to know. :)

                  Comment

                  Working...