VBScript Help

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

  1. z06

    z06 New Member

    Joined:
    May 27, 2003
    Messages:
    141
    Likes Received:
    0
    <html>
    <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
    next

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

    end sub

    -->
    </script>

    </head>
    <body>

    <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">

    </form>

    </body>
    </html>



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

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    please format with
    Code:
     tags. then i can help ;)
     
  3. 127.0.0.1

    127.0.0.1 New Member

    Joined:
    Sep 7, 2003
    Messages:
    9,310
    Likes Received:
    0
    Location:
    Fort Worth, Texas
    have you tried making each sub public? pretty much all the code i write has to be designated between public and private
     
  4. z06

    z06 New Member

    Joined:
    May 27, 2003
    Messages:
    141
    Likes Received:
    0
    Code:
    <html>
    <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 = 1
    a = document.theform.textareaform.value
    b = document.theform.textboxform.value
    
    for c = 1 to len(a) step 1
    if mid(a, c, 1) = b then
    count = count + 1
    end if
    next
    
    if count = 1 then
    msgbox "The letter " + b + " does not appear in the text above"
    else
    msgbox "The letter " + b + " appears " + count + " times in the text above"
    end if
    
    end sub
    
    -->
    </script>
    
    </head>
    <body>
    
    <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">
    
    </form>
    
    </body>
    </html>
    
    Can't get it to display the number of characters that are in the textarea box when you enter something in...please help =D
     
  5. 5Gen_Prelude

    5Gen_Prelude There might not be an "I" in the word "Team", but

    Joined:
    Mar 14, 2000
    Messages:
    14,519
    Likes Received:
    1
    Location:
    Vancouver, BC, CANADA
    Aren't you supposed to use & instead + when concatenating strings? Also you haven't dim'd and b.
     

Share This Page