Using the Value Function

  • Thread starter Thread starter Shanan Worley
  • Start date Start date
S

Shanan Worley

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
know the answer.
 
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.
 
Back
Top