VB Script

Author Message
ishah

  • Total Posts : 6
  • Scores: 0
  • Reward points : 0
  • Joined: 5/11/2005
  • Location:
  • Status: offline
VB Script Saturday, May 14, 2005 3:57 PM (permalink)
0
I am Basic user of VB.

Please correct my below code. tks

Sub cmdSubmit_Onclick()

Dim Total, item1price, item2price, item3price, item4price, item5price, item6price, item7price, item8price, item9price, item10price, item11price, item12price, item13price, item14price, item15price

item1price = 40
item2price = 30
item3price = 20
item4price = 10
item5price = 6
item6price = 5
item7price = 4
item8price = 3
item9price = 2
item10price = 1
item11price = 5
item12price = 4
item13price = 3
item14price = 2
item15price = 1

If document.calc.item1.checked Then itemprice = 40 Else
If document.calc.item2.checked Then itemprice = 30 Else
if document.calc.item3.checked Then itemprice = 20 Else
if document.calc.item4.checked Then itemprice = 10 Else
if document.calc.item5.checked Then itemprice = 6 Else
if document.calc.item6.checked Then itemprice = 5 Else
if document.calc.item7.checked Then itemprice = 4 Else
if document.calc.item8.checked Then itemprice = 3 Else
if document.calc.item9.checked Then itemprice = 2 Else
if document.calc.item10.checked Then itemprice = 1 Else
if document.calc.item11.checked Then itemprice = 5 Else
if document.calc.item12.checked Then itemprice = 4 Else
if document.calc.item13.checked Then itemprice = 3 Else
if document.calc.item14.checked Then itemprice = 2 Else
if document.calc.item15.checked Then itemprice = 1

End if

document.Write.calc.total= item1price+ item2price+ item3price+item4price+item5price+item6price+ item7price+ item8price+item9price+ item10price+ item11price+item12price+item13price+item14price+item15price
 
#1
    TNO

    • Total Posts : 2094
    • Scores: 36
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    Re: VB Script Saturday, May 14, 2005 8:09 PM (permalink)
    0
    Your sending me an email twice wasn't necessary. Its also a violation of web etiquette to send one without being asked. But as I've probably said before, this can be done in javascript and already has been done here: http://javascript.internet.com/calculators/checkbox-calculator.html

    But you said it has to be in vbscript so this is probably a homework project or something. Regardless, here is a 2 minute rough translation of the Javascript code. Its untested and most likely buggy. Its a place for you to start at though.

    <html>
    <head>
    <title>TNO's nasty little remake</title>

    <script language="vbscript">
    Function count()
    Dim item1price = 100
    Dim item2price = 100
    Dim item3price = 100
    Dim item4price = 100
    If calc.item1.checked Then
    Dim witem1 = document.calc.item1.value = item1price;
    else
    Dim witem1 = document.calc.item1.value = 0;
    End If
    If calc.item2.checked Then
    Dim witem2 = document.calc.item2.value = item2price;
    else
    Dim witem2 = document.calc.item2.value = 0;
    End If
    If calc.item3.checked Then
    Dim witem3 = document.calc.item3.value = item3price;
    else
    Dim witem3 = document.calc.item3.value = 0;
    End If
    If calc.item4.checked Then
    Dim witem4 = document.calc.item4.value = item4price;
    else
    Dim witem4 = document.calc.item4.value = 0;
    End If
    document.calc.pay.value = witem1 + witem2 + witem3 + witem4;
    End Function
    </script>

    </head>

    <BODY>
    <center>
    <form name="calc" method="POST">
    <table width="450" border="0" cellpadding="3">
    <tr>
    <td colspan="2"><span class="normalText"><h4>Checkbox calculator</h4></span></td>
    </tr>
    <tr>
    <th bgcolor="#333333" width="50%" align="left"><span class="whiteText">Item</span></th>
    <th bgcolor="#333333" width="50%" align="right"><span class="whiteText">Select</span></th>
    </tr>
    <tr>
    <td bgcolor="#cccccc" colspan="2"><span class="normalText"><b>Item group 1</b></span></td>
    </tr>
    <tr>
    <td bgcolor="#eeeeee"><span class="normalText">Item 1.1</span></td>
    <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item1" size="10"></td>
    </tr>
    <tr>
    <td bgcolor="#eeeeee"><span class="normalText">Item 1.2</span></td>
    <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item2" size="10"></td>
    </tr>
    <tr>
    <td bgcolor="#cccccc" colspan="2"><span class="normalText"><b>Item group 2</b></span></td>
    </tr>
    <tr>
    <td bgcolor="#eeeeee"><span class="normalText">Item 2.1</span></td>
    <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item3" size="10"></td>
    </tr>
    <tr>
    <td bgcolor="#eeeeee"><span class="normalText">Item 2.2</span></td>
    <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item4" size="10"></td>
    </tr>
    <tr>
    <td bgcolor="#cccccc" colspan="2" align="right"><span class="normalText">Price $</span><input type="text" name="pay" size="10" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"></td>
    </tr>
    <tr>
    <td bgcolor="#eeeeee" align="center"></td>
    <td bgcolor="#eeeeee" align="right"><input type="button" onClick="count()" value="Calculate" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"> <input type="reset" value="Reset" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
     
    #2
      ishah

      • Total Posts : 6
      • Scores: 0
      • Reward points : 0
      • Joined: 5/11/2005
      • Location:
      • Status: offline
      Re: VB Script Monday, May 16, 2005 11:32 AM (permalink)
      0
      This code is not working. Can you honestly help some one?
       
      #3
        crazymatt

        • Total Posts : 310
        • Scores: 0
        • Reward points : 0
        • Joined: 3/4/2005
        • Location:
        • Status: offline
        Re: VB Script Monday, May 16, 2005 10:10 PM (permalink)
        0
        Try this:

        ---------
        <html>
        <head>
        <title>Calculator</title>
        <%@ Language=VBScript %>
        <script language="vbscript">
        Dim item1price, item2price, item3price, item4price, witem1, witem2, witem3, witem4, pricetot

        item1price = 100
        item2price = 100
        item3price = 100
        item4price = 100

        Function count()
        If calc.item1.checked Then
        witem1 = item1price
        else
        witem1 = 0
        End If
        If calc.item2.checked Then
        witem2 = item2price
        else
        witem2 = 0
        End If
        If calc.item3.checked Then
        witem3 = item3price
        else
        witem3 = 0
        End If
        If calc.item4.checked Then

        witem4 = item4price
        else
        witem4 = 0
        End If
        pricetot = witem1+witem2+witem3+witem4
        document.calc.pay.value = pricetot
        End Function
        </script>

        </head>

        <BODY>
        <center>
        <form name="calc" method="POST">
        <table width="450" border="0" cellpadding="3">
        <tr>
        <td colspan="2"><span class="normalText"><h4>Checkbox calculator</h4></span></td>
        </tr>
        <tr>
        <th bgcolor="#333333" width="50%" align="left"><span class="whiteText">Item</span></th>
        <th bgcolor="#333333" width="50%" align="right"><span class="whiteText">Select</span></th>
        </tr>
        <tr>
        <td bgcolor="#cccccc" colspan="2"><span class="normalText"><b>Item group 1</b></span></td>
        </tr>
        <tr>
        <td bgcolor="#eeeeee"><span class="normalText">Item 1.1</span></td>
        <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item1" size="10"></td>
        </tr>
        <tr>
        <td bgcolor="#eeeeee"><span class="normalText">Item 1.2</span></td>
        <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item2" size="10"></td>
        </tr>
        <tr>
        <td bgcolor="#cccccc" colspan="2"><span class="normalText"><b>Item group 2</b></span></td>
        </tr>
        <tr>
        <td bgcolor="#eeeeee"><span class="normalText">Item 2.1</span></td>
        <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item3" size="10"></td>
        </tr>
        <tr>
        <td bgcolor="#eeeeee"><span class="normalText">Item 2.2</span></td>
        <td bgcolor="#eeeeee" align="right"><input type="checkbox" name="item4" size="10"></td>
        </tr>
        <tr>
        <td bgcolor="#cccccc" colspan="2" align="right"><span class="normalText">Price $</span><input type="text" name="pay" size="10" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"></td>
        </tr>
        <tr>
        <td bgcolor="#eeeeee" align="center"></td>
        <td bgcolor="#eeeeee" align="right"><input type="button" onClick="count()" value="Calculate" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"> <input type="reset" value="Reset" style="background-color:#ffffff; color:#000000; border:1px solid #000000; font-family:tahoma; font-size:8pt; letter-spacing=1px"></td>
        </tr>
        </table>
        </form>
        </center>
        </body>
        </html>
        ----------

        /Matt
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9