Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How can I get the number of words (instead of characters) from a string that's contained inside a textbox in VBScript?
I used len and got 68 char but I have no idea how to get the # of words instead.
I would also need to show the answer in the span block id=answer1.
Please help.
The code is below.
Thanks.
<html>
<head>
<script language="vbscript">
<!--
sub fred
john_val=window.document.alice.john.value
john_len=len(john_val)
msgbox "john_val=" +cstr(john_len)
end sub-->
</script>
</head><body>
<form name="alice">
The string john = <input type="text" size="60" name="john" value="this is a string for the purpose of playing with string coding tools">
</form><ol>
<li><span id="answer1">this is the contents of the span block with id answer1</span>
<li><span id="answer2">this is the contents of the span block with id answer2</span></ol>
<input type="button" value="GO" onClick="fred">
</body>
</html>

I haven't used VBS before, but if it has the function split, then you could use it to find the number of words in a string. Here's a VB6 example:
Dim s As String Dim w As Variant s = "this is a string of words." w = Split(s, Chr(32)) For i = 0 To UBound(w) Me.Print w(i) + vbCrLf Next iI'm not sure how one would go about using VBS to set data. In Javascript, it could be done using something similar to below.
function setTxt(txt) { var d = document.getElementById("answer1"); d.innerHTML = txt; }Not really what you need, but hopefully, it's close enough to get you there. Good luck.

![]() |
batch script to copy/dele...
|
php calculation of dates
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |