472,808 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 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 1308
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.