question on how to check a string?

# Thread: question on how to check a string?

1. Senior Member
Join Date
Dec 1969
Posts
111

## question on how to check a string?

Im using the following string to put data entered in form a text box into A number format. However I am running into a problem if the user enteres in 2 decimals instead of one. Is there an easy way of checking to make sure that the user only enteres in one decimal?<BR><BR>retHours = FormatNumber(Trim(request.form.item("entHours")))

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: question on how to check a string?

I guess without a loop you can do<BR><BR>if instr(str,".") = instrrev(str,".") Then<BR> &#039;only one decimal

3. Senior Member
Join Date
Dec 1969
Posts
111

## RE: question on how to check a string?

thanks desert ghost. I guess that answered my next question about if I should run a loop, because if the user entered 1.23 that would fall that check. <BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## You are converting a string to a string

Request.Form("entHours") is a *STRING*.<BR><BR>The result of FormatNumber() is a *STRING*.<BR><BR>SO you are asking VBS to convert a string into a number so it can then be converted into a string again.<BR><BR>If you want the value converted to a number, convert it to a number! NOT to a string!<BR><BR>retHours = CDBL( Request("entHours") )<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
11,334

## That won't work

bah.... 3 day weekends.<BR><BR>for i = 0 to len(str)<BR> if instr(str,".") &#062; 0 Then<BR> decimal = decimal + 1<BR> end if<BR>next<BR><BR>if decimal &#062; 1 Then<BR> &#039;more than one

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Well, I guess I sure didn't...

...understand the point of your question, did I?<BR><BR>If you want to be sure that, no matter what the user entered, you only get one digit after the decimal point, then just do:<BR><BR>numberWithOneDigitAfterDP = Round ( CDBL( Request("entHrs") ), 1 )<BR><BR>Now if the user enters 1.23818111911112222 you don&#039;t care: You&#039;ll get it as just 1.2<BR><BR>If the user enters 1.2888111 then you&#039;ll get it as just 1.3<BR><BR>

7. Senior Member
Join Date
Dec 1969
Posts
11,334

## Dammit

Last chance... before I completely confuse you even more :)<BR><BR>if instr(i,str,".") &#062; 0 then<BR><BR><BR><BR>probably wrong as well....

8. Senior Member
Join Date
Dec 1969
Posts
111

## RE: You are converting a string to a string

ok but wouldnt I still run into the problem if the user entered 2 decimals instead of one? I have never used CDBL, not sure what command that is?<BR>

9. Senior Member
Join Date
Dec 1969
Posts
111

## RE: Dammit

thats Ok I was confused before I posted so it just blends in with the rest. I will try that, thanks<BR>

10. Senior Member
Join Date
Dec 1969
Posts
96,118

## Why do you give a flyin' feghoot?

What does it matter exactly what the user entered? Just round his/her entry to one digit after the DP and be happy.<BR><BR>And CDBL is *NOT* a "command". It&#039;s a function. Just like FormatNumber and InStr and all those other things that take an argument and return a value.<BR><BR>You can see the list of all the functions in VBS by:<BR><BR>(1) Click on "VBScript Reference" in the left panel on this very page.<BR>(2) Click on "Functions" in the list of topics that appears.<BR><BR>There they all are. Happy reading. (You really should read through each one at least one time. You may not remember the details later, but you might remember "Oh, yeah...I remember there was a function that could round numbers for me.")<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•