Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VB Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2995
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VB Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VB Script - 5/14/2005 2:57:42 PM   
  ishah

 

Posts: 6
Score: 0
Joined: 5/11/2005
From:
Status: offline
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
 
 
Post #: 1
 
 Re: VB Script - 5/14/2005 7:09:51 PM   
  TNO


Posts: 1303
Score: 12
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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>

(in reply to ishah)
 
 
Post #: 2
 
 Re: VB Script - 5/16/2005 10:32:16 AM   
  ishah

 

Posts: 6
Score: 0
Joined: 5/11/2005
From:
Status: offline
This code is not working. Can you honestly help some one?

(in reply to ishah)
 
 
Post #: 3
 
 Re: VB Script - 5/16/2005 9:10:42 PM   
  crazymatt

 

Posts: 296
Score: 0
Joined: 3/4/2005
From:
Status: offline
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

(in reply to ishah)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VB Script Page: [1]
Jump to:





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
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts