all groups > dotnet general > september 2003 >
You're in the

dotnet general

group:

Using the Value Function



Using the Value Function Shanan Worley
9/30/2003 4:59:59 PM
dotnet general: This is my first course in VB using the Visual Studio.NET
2003. Here is my question.
I have a text box that I want a user to enter a dollar
value in. I want to use the value in that box and this
is the line I have to type

intAmount = Val(txtInput.text)

This works, but if my user puts a "$" sign in that
command will return a value of 0. What can I do to get
that value and ignore the way the number is formatted
(the $)? My instructor is a C++ programmer and did not
Using the Value Function Solomon
10/1/2003 7:36:32 AM
You can achieve this in different ways. One of them is by
using the RIGHT command. It takes to paramenters.

Syntax: Right(string, length)

Replace the statement
intAmount = Val(txtInput.text)
with the following
intAmount =val(Right(txtInput.Text, Len(txtInput.Text)-1))

----------------------------------------------------------
Demo Example:
txtInput.Text = "$123.99"
Len(txtInput.Text) = 7 ; lenth of string
Len(txtInput.Text)-1 = 6 ; without the $ sign
Right(txtInput.Text,6)= 123.99 ; the last 6 characters.
----------------------------------------------------------

Refer to string manipulation on the microsoft msdn help
that comes with VS.Net or the online msdn documentation
for detailed help.


[quoted text, click to view]
AddThis Social Bookmark Button