# VBScript



## Fatty_McGavins (Apr 4, 2001)

Does anyone know why this doesn't work?


----------



## Rockn (Jul 29, 2001)

Put the URL to the live example on the net. It won't work as an attachment.


----------



## Fatty_McGavins (Apr 4, 2001)

```
Validating a form field

[B][SIZE=14]Enter a string in the textbox[/SIZE][/B]
```


----------



## Rockn (Jul 29, 2001)

Don't post the code like that in the forum because it will generate an error when the page loads here. Use the PHP button when you edit your post and paste the code in there. I just entered the code from your first post and it says soemthing about expected end. You need to add an End Function statement for one thing.


----------



## Mosaic1 (Aug 17, 2001)

Hope this helps:

```
Validating a form field

[B][SIZE=14]Enter a string in the textbox[/SIZE][/B]
```


----------



## Mosaic1 (Aug 17, 2001)

I have a couple of things to add. Although the above code works, it may not be what you want to do. Only the first character in the text box is checked.

a2345 will validate as a string.

2asd will validate as a number.

Also, IE can understand vbs but other Browsers can't according to the Script 5.6 documentation.

You may want to consider using JavaScript as an alternative.


----------



## Rockn (Jul 29, 2001)

Looks like you are trying to intermix VB and java without any distinction between the two. If you want to run both you need to save it as an ASP page because HTML will not process VB Script on it's own. I can give you an example of pure ASP if you want with the java pop up message.


```
<%@ LANGUAGE=VBSCRIPT %>

Validating a form field

[B][SIZE=14]Enter a string in the textbox[/SIZE][/B]

<% 
Dim strString
strString = Request.Form("txtString")
%>
<%
If Request.Form("btnSubmit") <> "" Then
	If IsNumeric(strString) Then
		Response.Write ""
	Else
		Response.Write ""
	End If
 Else
	Response.Write ""
End If 
 %>
```
It is very basic, but will validate what you are looking for. It will not however test for alphanumeric strings. Easy enough to modify for that.


----------



## Mosaic1 (Aug 17, 2001)

I uploaded the corrected code to my web site.

Here's the link.\http://www.geocities.com/backgammon1_2000/preview/validate.html

If you were to have another submit button which was disabled when the wrong type of data was entered into the box, then it could work.

But you need a better way to do this. Only the first character is examined in the code as written.

And I would not use VBscript.


----------



## Mosaic1 (Aug 17, 2001)

The source code on this page should help.

http://www.shiningstar.net/articles/articles/javascript/javascriptvalidations.asp?ID=AW


----------



## brendandonhu (Jul 8, 2002)

> _Originally posted by Mosaic1:_
> *I uploaded the corrected code to my web site.
> 
> Here's the link.\http://www.geocities.com/backgammon1_2000/preview/validate.html
> ...


Its not only the 1st character examined, is it? Granted I don't know any VBScript code.
But doesnt

strString=document.form.txtString.value
if IsNumeric(strString) = True then
window.alert("You have entered a number")
else
window.alert("You have entered a string")

mean that if its Numeric (which means all chars are numeric) it returns number. If you enter a letter, or a combination of letters and numbers, it returns String, which is correct.
So that code works (I think), except that VBScript is basically useless on the web because its only supported in IE.


----------



## Mosaic1 (Aug 17, 2001)

Hi Brendan,

You are not a BRAT!

Go to my web site and test it. It does not test any but the first. 

Mo


----------



## Rockn (Jul 29, 2001)

VB script is supported by many browsers Brendan because it runs on the server. You are correct however about the isnumeric qualifier testing the entire string. If it is anything but an all numeric string an alert for "You have entered a string" will pop up.


----------



## Mosaic1 (Aug 17, 2001)

Why does it not work that way on mine? I went back and tested it and if I entered 
22222a

Now it says it's a string. Isn't the code as written here being tested by the Browser and not the Server?

http://www.geocities.com/backgammon1_2000/preview/validate.html


----------



## Rockn (Jul 29, 2001)

I just tested it on yours....LOL I get errors from it when it loads there as well, unterminated constants, etc. The code is java so it is running at the client and not ther server. ASP runs on the server was what I was saying. Your browser is probably caching the pages if it's coming out wrong.


----------



## Mosaic1 (Aug 17, 2001)

RockN,
I was not talking about your code. I was talking about mine. I corrected the orginal and put it on my site. I get no errors. 

I merely corrected the original code as posted and am trying to ascertain what's going on.

Mo


----------



## Fatty_McGavins (Apr 4, 2001)

Thanks for all the help and input, you guys are great,

Fatty


----------



## brendandonhu (Jul 8, 2002)

VBScript is server-side? OK I didn't know that.
Mosaic1-it definitely tests the whole string.
Heres my tests.
A=String
1=Number
A1=String
1A=String
See?

22222a IS a string. IsNumeric requires every character be numeric. So, by the "definition" of string, in that Script, a string is any text that is not completely numeric. And I think that is the correct definition.


----------



## Mosaic1 (Aug 17, 2001)

Thanks Brendan.

I believe the general idea of the test was to be sure the string was all numbers or all letters. Which is why I feel he needs to go about this in a different manner.


----------



## Mosaic1 (Aug 17, 2001)

I opened my page in the CS Browser, not IE. The script didn't run.


----------



## Fatty_McGavins (Apr 4, 2001)

Here is another thing I might pick your brains about ;D

```
Calculating with Variables

[B][SIZE=14]Calculate the Tax[/SIZE][/B]

 Product Price

 Percent Tax(0.085)

 Total Tax in Dollars

 Total Cost of the Product
```
If I am getting annoying, I will stop posting. You guys might be enjoying this for all I know lol. I have tons of little projects that don't work ;D


----------



## brendandonhu (Jul 8, 2002)

No you aren't annoying, its a nice debate here, and motivated me to read a VBScript tutorial. Which mentioned that it is client-side scripting, and only runs on IE as of now.

I doubt it will be picked up by other browsers though, a lot of its functions are covered in Javascript.

Mosaic- Thanks for posting that script to fill in a form in another thread. My mom finds the whole .net sign in thing complicated, so i added the script as a bookmarklet and it will sign her in automatically when she chooses the bookmark.


----------



## Mosaic1 (Aug 17, 2001)

Brendan,
Yes. I have the 5.6 Script Documentation and it said it is the Browser which reads the code. So vbs is for IE only. That's a quote. 

Also, here at Tech Guys, the script is a bit different. After the Name is entered, I need two Tabs and then enter. Mike has the page set up so the next control is not the password box. I don't need to enter my Password here. You'll have to test it on various sites to see exactly what keystrokes you need. 

Mo


----------



## brendandonhu (Jul 8, 2002)

It worked fine for me on the MLXchange site. I needed to enter an email, tab, password, 2 tabs, enter and it worked.
I can take out the Sleep, but it looks really cool as you watch the computer type in each letter. Actually, I think I might change the Sleep to 15 .

Set WshShell = WScript.CreateObject("WScript.Shell") 

WshShell.SendKeys "M" 
WScript.Sleep 10 
WshShell.Sendkeys "r" 
WScript.Sleep 10 
WshShell.Sendkeys "e" 
WScript.Sleep 10 
WshShell.Sendkeys "a" 
WScript.Sleep 10 
WshShell.SendKeys "1" 
WScript.Sleep 10 
WshShell.Sendkeys "@" 
WScript.Sleep 10 
WshShell.Sendkeys "c" 
WScript.Sleep 10 
WshShell.Sendkeys "o" 
WScript.Sleep 10 
WshShell.Sendkeys "m" 
WScript.Sleep 10 
WshShell.Sendkeys "c" 
WScript.Sleep 10 
WshShell.Sendkeys "a" 
WScript.Sleep 10 
WshShell.Sendkeys "s" 
WScript.Sleep 10 
WshShell.Sendkeys "t" 
WScript.Sleep 10 
WshShell.Sendkeys "." 
WScript.Sleep 10 
WshShell.Sendkeys "n" 
WScript.Sleep 10 
WshShell.Sendkeys "e" 
WScript.Sleep 10 
WshShell.Sendkeys "t" 
WScript.Sleep 10 
WshShell.Sendkeys "{tab}"
WScript.Sleep 10 
WshShell.Sendkeys "p"
WScript.Sleep 10 
WshShell.Sendkeys "a"
WScript.Sleep 10 
WshShell.Sendkeys "s" 
WScript.Sleep 10 
WshShell.Sendkeys "s" 
WScript.Sleep 10 
WshShell.Sendkeys "w" 
WScript.Sleep 10 
WshShell.Sendkeys "o" 
WScript.Sleep 10 
WshShell.Sendkeys "r"
WScript.Sleep 10 
WshShell.Sendkeys "{tab}" 
WScript.Sleep 10 
WshShell.Sendkeys "{tab}"
WScript.Sleep 10 
WshShell.Sendkeys "{enter}"
WScript.Sleep 10


----------



## Rockn (Jul 29, 2001)

My bad, VB script is something entirely different than what I was thinking about. And Windows scriptin host is even more different. I have only used WSH to automate some things on one of my servers. You are correct about the browser capabilities as well.


----------



## Mosaic1 (Aug 17, 2001)

Brendan,

See. You're very smart. You picked it up right away. To tell the truth, I like to watch Defrag too. LOL


Mo

EDIT:


Sorry Rock,

I didn't see you there. How can anyone ever possibly keep up with everything there is to know? I have only just really started to play with various codes and it's mind boggling.


----------



## brendandonhu (Jul 8, 2002)

Yes, in defrag Show Details and watch the colored blocks change. Unfortunately, it takes a few minutes to watch the colors change so you don't get the instant gratification of seeing letters typed onto your screen.
Great idea for a prank too, LOL.

Rockn-I got confused about this too. You have WSH, VBA, VBScript, JS, Javascript, JS 1.2, DHTML, XML, XHTMl, HTML.
i was reading a tutorial about VBS and they said create a folder called "JS Examples" to store your tutorial sample files!


----------



## Mosaic1 (Aug 17, 2001)

Hey Fatty,
If you're still there. I do not speak JS. But I took your second code as a challenge and did a little research. I wrote something which has a big Glitch. LOL

JScript doesn't have all the Formatting functions which VBS has. I saw some Format Currency Functions on the Web, but they all seemed to format data already in the input boxes. That didn't help. I wrote a little something myself. But it is by no means perfect. Far from it.

I know of no way to run a script and then change the values in the input boxes. Or even if that's possible. Someone else will have to answer that one.

At any rate, this runs bumpy. If you enter 1000 or 2000 (1001 is fine) for example, it cuts off the final result after 2 characters. But if you change that to 1000.04 it works. Also, no commas in the input box. That cuts off the number at the comma.

This is really not usuable. But it was a frustrating experience.
I think looking for an online calculator might be better.

To retrieve the number from the input box you need to use 
parseFloat

Here's the link to it. I changed the form since the other input boxes couldn't be used. LOL

http://www.geocities.com/backgammon1_2000/textfile/final.html


----------



## Mosaic1 (Aug 17, 2001)

I think I have the Glitch figured out. It stems from this:


```
FinalCost = FinalCost+'';
foo =FinalCost;
      finalResult = foo.indexOf(".");
  Y=parseFloat(finalResult);
foo =FinalCost;
    finalResult = foo.substring(0,(Y+3));
```
 If I do not use that, then the prices which end in Three 0's or more total correctly. But the Final Total is not always rounded off.

So, if I were to test the Price as a string for three 0's at the end, and have a conditional statement to calculate the total cost, that would resolve that glitch. When I do not use the above, that works for those numbers. I have to leave, But later, I'll try it.

I found another problem too. I opened the page in Compuserve, which uses Netscape, No Alert Boxes. I wonder if Inner HTML would work there. That would put the results right on the same page instead of using an alert box to show.

Anyway, this is kind of fun. If you like holding your breath until you turn blue. LOL I look like Papa Smurf right now.


----------



## Mosaic1 (Aug 17, 2001)

Sorry for not getting back. I have a newer version to submit. It is improved. No more Glitch with the numbers ending in 3 0's.
The final Roundoff is not a real round off mathematically. It is a cutoff. The number is cutoff after two decimal places. Not rounded off. But the actual total is the sum of two non "rounded off numbers" so there is only a possibility of a very small (a penny)discrepency.

(Although I did round off the tax for the listing onscreen, the tax I used to calculate the grand total is the full number, no matter how many decimal places it might contain.) 
One other thing is that I haven't gotten around to formatting the numbers using commas. I have the decimal places all set. I have to tell you, doing this in Java Script is a pain. I really miss Format currency. 


I am attaching as a text file. Download and rename it with a html extension. Double click on the html to view it.


----------



## Mosaic1 (Aug 17, 2001)

I guess I should explain what I've done here. It all boils down to the fact that any entry in a text box is a string. So the first step is to retrieve the data and convert it to a Decimal. Not an integer. That's the parseFloat you see. A floating point number. 

Now do all the math. Storing the information in variables.

To work with the final products and convert to currency format, I had to reconvert the numbers to strings. I used some functions to get information on the length of the strings and where the decimal points were.
Then I used a series of conditional statements to add .00 0r just one more 0 if missing etc. 87 becomes 87.00
87.0 becomes 87.00
I also cut off the decimals after two places. 87.889 becomes 87.88 . There's an example of cutting it off. If rounded off correctly, that would show as 87.89. That's something to do antoher day. 



Finally, I used innerHTML to write the results to the Window. 

If you have any questions on how this works, let me know. I'll try to explain in more detail.


----------

