By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

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

P: 4
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(input) , 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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles output.TextChanged

End Sub

Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text1.Click

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) 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.
Jan 4 '07 #1
Share this Question
Share on Google+
8 Replies


P: 4
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.EventArgs) Handles Button1.Click
- Dim volume As Integer
- Dim radius As Integer
- radius = Val(TextBox1.Text)
- 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.
Jan 4 '07 #2

Expert 5K+
P: 8,434
...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...
Expand|Select|Wrap|Line Numbers
  1.     radius = CDbl("TextBox1")
  2.  
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).
Jan 4 '07 #3

Expert 5K+
P: 8,434
- 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.)
Jan 4 '07 #4

P: 4
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.Text). And i have no idea why.


One praise for you though.
Jan 4 '07 #5

Expert 5K+
P: 8,434
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.Text). 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.
Jan 4 '07 #6

P: 8
Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim volume As Decimal
  3.         Dim radius As Decimal
  4.         radius = CDbl(TextBox1.Text)
  5.         volume = (4 / 3) * 3.14 * (radius * radius * radius)
  6.         Label1.Text = volume
  7.     End Sub
  8.  
  9.  
Works fine with both Val(textbox1.text) and CDbl(Textbox1.text).
changed integer to decimal. And instead of msgbox(radius) i use
label1.text = volume.
Jan 5 '07 #7

P: 4

Works fine with both Val(textbox1.text) and CDbl(Textbox1.text).
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.
Jan 5 '07 #8

Expert 5K+
P: 8,434
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. :)
Jan 5 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.