473,498 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrong value using val(textbox.text)

I get the value that doesn't add up correct.

I have 2 textboxes where I enter numbers, I then calculate them and present
them as a reslut in a 3rd
textbox, however when the result is calculated it won't calculate the
correct value.
For instance when the value is 75,25 the code interprets it as 75.

The code:
lblSumma2.Text = Val(lblSumma2.Text) + ((txtAntal.Text) * myMinutNetto) +
myFastNetto

The problem is the val(lblsumma2.text), it skips the decimals, how can I
change this to use the actual number?
(lblSumma2.text will show the correct value, the problem is just when using
the val()-option)

Regards
/Drygast
Nov 20 '05 #1
4 8104
* "Drygast" <dr*****@hotmail.com> scripsit:
I have 2 textboxes where I enter numbers, I then calculate them and present
them as a reslut in a 3rd
textbox, however when the result is calculated it won't calculate the
correct value.
For instance when the value is 75,25 the code interprets it as 75.

The code:
lblSumma2.Text = Val(lblSumma2.Text) + ((txtAntal.Text) * myMinutNetto) +
myFastNetto

The problem is the val(lblsumma2.text), it skips the decimals, how can I
change this to use the actual number?
(lblSumma2.text will show the correct value, the problem is just when using
the val()-option)


<msdn>
Note The Val function recognizes only the period (.) as a valid decimal separator. When different decimal separators are used, as in international applications, use CDbl or CInt instead to convert a string to a number.
</msdn>

You can use 'Double.Parse' to parse the value of the string.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Lightning fast repsonse!

Thanks I'll try yout suggestion.

I also tried a "short-cut" using
val(lblSumma2.text.Replace(",", "."))

and that worked for me.

Regards

/Drygast

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bm************@ID-208219.news.uni-berlin.de...
* "Drygast" <dr*****@hotmail.com> scripsit:
I have 2 textboxes where I enter numbers, I then calculate them and present them as a reslut in a 3rd
textbox, however when the result is calculated it won't calculate the
correct value.
For instance when the value is 75,25 the code interprets it as 75.

The code:
lblSumma2.Text = Val(lblSumma2.Text) + ((txtAntal.Text) * myMinutNetto) + myFastNetto

The problem is the val(lblsumma2.text), it skips the decimals, how can I
change this to use the actual number?
(lblSumma2.text will show the correct value, the problem is just when using the val()-option)
<msdn>
Note The Val function recognizes only the period (.) as a valid decimal

separator. When different decimal separators are used, as in international
applications, use CDbl or CInt instead to convert a string to a number. </msdn>

You can use 'Double.Parse' to parse the value of the string.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Nov 20 '05 #3
* "Drygast" <dr*****@hotmail.com> scripsit:
Lightning fast repsonse!

Thanks I'll try yout suggestion.

I also tried a "short-cut" using
val(lblSumma2.text.Replace(",", "."))

and that worked for me.


Notice that this will not work on every systems as expected because
different languages/cultures use different characters as decimal comma.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"Drygast" <dr*****@hotmail.com> schrieb
I get the value that doesn't add up correct.

I have 2 textboxes where I enter numbers, I then calculate them and
present them as a reslut in a 3rd
textbox, however when the result is calculated it won't calculate
the correct value.
For instance when the value is 75,25 the code interprets it as 75.

The code:
lblSumma2.Text = Val(lblSumma2.Text) + ((txtAntal.Text) *
myMinutNetto) + myFastNetto

The problem is the val(lblsumma2.text), it skips the decimals, how
can I change this to use the actual number?
Don't use Val. It expects the "." as decimal separator. Use Decimal.Parse,
Double.Parse, CSng, CDec, CDbl, ...
(lblSumma2.text will show the correct value, the problem is just when
using the val()-option)

--
Armin

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8561
by: Paul M. Frazier, Ph.D. | last post by:
I am writing a user information update page and I populate the form on Page_Load with the current values of the user's name, etc. When I change the text in one of the textbox controls (e.g.,...
5
2462
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
1
6684
by: Martin | last post by:
Dear Group Sorry for bothering you again but I need expert advice on this. I have placed a HTML textbox on my aspx form and converted it to run as a server control. At some point in my code I...
4
2028
by: David Kyle | last post by:
Hello there, I'm having some problems setting the TextBox.Text Property in my code and having it returned to the client in the source when the TextBox.TextMode="Password". I know this is...
3
2227
by: Ruben | last post by:
I have this code, I need see in textbox.text all my information, how I do that Function Consultas(ByVal usuario As String) As System.Data.DataSet Dim connectionString As String =...
5
2353
by: hans.bonefaas | last post by:
Hi all, I hope someone can help me with the following problem in ASP.net. I want to edit the information for a record in a database (MS Access). On the page I placed several textboxes and...
38
11059
by: Keith | last post by:
I've been reading and looking on the internet - but I just can't fin this. Perhaps I'm approaching this the wrong way - code-wise I'm attempting to learn how "things" work in VBNET by creating...
0
2593
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
0
2451
by: mervyn | last post by:
Hi There, I am very new to .NET and VB so this may be a really simple thing to solve but here is my issue I have a a textbox with a value in it. I know what the length of the text in the text...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.