VBScript Help

Discussion in 'OT Technology' started by z06, Oct 2, 2004.

  1. z06

    z06 New Member

    May 27, 2003
    Likes Received:
    <head><title>Algorithm VBScript</title>

    <script language="vbscript" type="text/vbscript">

    sub count

    a = document.theform.textareaform.value

    msgbox "You have " + cstr(len(a)) + " number of characters"

    end sub

    sub countchars

    dim count
    count = 0
    a = document.theform.textareaform.value
    b = document.theform.textboxform.value

    for c = 0 to len(a) step 1
    if mid(a, c, 1) = b then
    count = count + 1
    end if

    if count = 0 then
    msgbox "The letter " + b + " does not appear in the text above"
    msgbox "The letter " + b + " appears " + count + " times in the text above"
    end if

    end sub



    <form action="" method="post" name="theform">

    <textarea cols=40 name="textareaform" rows=10 wrap="hard"></textarea><br/>
    <input type="submit" onclick="count" value="How many characters?">
    <input type="reset" value="Clear Form"><br/><br/>

    Type a letter: <input maxlength=1 name="textboxform" size=3 type="text"><br/>
    <input type="submit" onclick="countchars" value="How many of each character?">
    <input type="reset" value="Clear Form">



    Why isn't my code working...? :wtc: I think i messed up in the for loop in the sub countchars...
  2. Dummy2529

    Dummy2529 Guest

    If I were you I wouldn't call a sub and a variable by the same name. Right now there is a sub called count and a variable called count. Try changing one and then give it another shot :)

Share This Page