473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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(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
8 1331
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
Killer42
8,435 Expert 8TB
...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
Killer42
8,435 Expert 8TB
- 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
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
Killer42
8,435 Expert 8TB
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
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

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
Killer42
8,435 Expert 8TB
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

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

Similar topics

7
by: Wilfried | last post by:
I have a form with four numeric fields. In a textbox on the form I want to calculate the sum of the three highest numbers of the four fields. This calculated textbox must then be ordered from high...
2
by: Miguel Morales | last post by:
Hello: Currently, I am trying to solve a problem that requires the calculation of Airy functions for big arguments. Because Airy functions diverge rapidly for positive values, the results of the...
0
by: Renee | last post by:
Hi there, does any one know how to create context sensitive help for Groupbox control with HelpProvider class? I can create context sensitive help for any control easily except for Groupbox. ...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
0
by: Limpor | last post by:
Hello, I am new to learning java, and i am trying to build the class for a calculation card game, unfortunately i can't get the public Card top() and Card takeTop() method in the Stock class. Can...
7
by: vinay2110 | last post by:
i m new to .net programing and dont know how to apply mathematic calculation on the text box. i has the idea to do this thing using auto post back but i dont know what is the exact syntax which will...
1
by: mirasol | last post by:
i am new here,i just want to ask question about uploading file with textbox using mysql and php, i used the codes given by some member and my problem is i dont know how to add textbox and i want it...
4
by: neelsfer | last post by:
I have an option group with 2 checkboxes : MtbAge - option value = 1 RoadAge - option value = 2 The textbox where to display MtbAge/RoadAge is called = currentage if you select MtbAge it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.