Question

Combine Arrays withLoops in VBScript

Asked by: dschafer77

I want to create a form that has 4 check boxes and an edit button. At least one button has to be checked by the user.  When the user clicks the edit button, a sub procedure named Check_box_onClick will be executed.
The sub will put the value of every button that is checked in an array and ask the user to check at least one check box if the user has not choosen any.

How does the VBSript code for that sub look like?  I am looking for the shortest possibility.



Daniel

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2002-10-15 at 12:56:37ID20374224
Tags

arrays

Topic

Web Languages/Standards

Participating Experts
1
Points
50
Comments
5

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VBScript to JavaScript Arrays
    I load an array in vbscript with items from a db then want to pass the array to a javascript function. Can anyone give me an example of this?
  2. vbScript control array
    Anyone tell me how to create a control array in Interdev/vbScript? Heres my current code, does nothing. private sub cmdSubmit_onclick() dim txtWhen(37), k dim txtWho(37), j dim chk(37), i for i = 1 to 37 step 1 select case chk(i).checked case true txtWhenTitle.style.v...
  3. Get next item from array onClick()
    I have an array set-up that I need to pass the next item when onclick is called. So, when the page is loaded it will call the first item in the array and display it as a link, then when the onclick is called, load either the next item or the previous item of the array. He...
  4. Arrays
    I am trying to get data out of an array using a client-side subroutine in a ASP page. I have tried to access the content of the array 2 different ways. The first way I defined the array with no dimensions between the script tags, which I thought meant the array was accessabl...
  5. JavaScript array to VBscript
    I created an array in Javascipt thru a client-side table. Now I need to access this array is VBscript. I can't seem to figure out how to do this. Any help will be greatly appreciated.
  6. Vbscript and Javascript array data passing
    i'm doing an asp project and i successfully put my data in Vbscript array. But how to pass the Vbscript array to javascript array? this is bcoz i'm going to call the javascript function to retrieve the data to be displayed in a combo box(drop down menu).

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: RamojiPosted on 2002-10-15 at 13:47:44ID: 7335441

Hi,

Here is a sample HTML file with the vbscript code you want.

<html>
<script language=vbscript>
     sub fnCheck()
          dim arr(4)
          dim count
          for i=0 to document.all("chk1").length-1
               if(document.all("chk1")(i).checked = false) then
                    count = count + 1
               else
                    arr(i) = document.all("chk1")(i).value
                    msgbox arr(i)
               end if
          next
          if count = document.all("chk1").length then
               msgbox "Atleast One Country Should be Selected"
          end if          
     end sub
     
</script>
<body >
     India<input type=checkbox id=chk1 name=chk1 value="India">
     America<input type=checkbox id=chk1 name=chk1 value="America">
     England<input type=checkbox id=chk1 name=chk1 value="England">
     Russia<input type=checkbox id=chk1 name=chk1 value="Russia">
     <input type=button value="Edit" onclick="fnCheck()">
</body>
</html>

Best of luck.

Regards,
Ramoji.

 

by: RamojiPosted on 2002-10-16 at 14:25:39ID: 7338954

Did you get a chance to run the HTML file and see?

Ramoji.

 

by: dschafer77Posted on 2002-10-17 at 18:39:49ID: 7342846

I was not able to express the problem correctly.
The following code should give you an idea what I am trying to accomplish.
The code is not working.
I am most concerned about the algorithm of the sub...

<html>
<title>Conquer_Parks_2</title>
<head>
<SCRIPT LANGUAGE="VBScript">
<!---
sub f1_onclick
set fred=window.document.Schweinehund

for i=0 to 5
    if fred.elements(i).checked then
       Radio_Value=fred.elements(i).value
    end if
next  

for i= 6 to 9
    Check_True=0             
    if fred.elements(i).checked=true then
       Check_True=Check_True+1    
    end if
    if Check_True<=1 then
       msgbox"Select at least one value"
    exit sub
    end if
    if fred.elements(i).checked then
       SName=SName + fred.elements(i).name + " "
    end if

next  
    if fred.c1.value="default" then
      msgbox"Select a value other than default"
      exit sub
    end if

select_d1=fred.d1.value
select_index=fred.d1.selectedindex

oldchar_a=fred.d1.value
newchar_a=replace("oldchar_a","/","")
newchar_a=replace("newchar_a","\","")
newchar_a=replace("newchar_a","*","")
oldcharlen_a=len("oldchar_a")
newcharlen_a=len("newcharlen_a")

oldchar_b=fred.e1.value
newchar_b=replace("oldchar_b","","+")
newchar_b=replace("newchar_b",chr(13),"")
newchar_b=replace("newchar_b",chr(10),"")
oldcharlen_b=len("oldchar_b")
newcharlen_b=len("newcharlen_b")      

document.clear
document.open
document.write"<html><body bgcolor='#ffffc0'>"+chr(10)+chr(13)
document.write"<table width='80%' bgcolor='#ffffc0' border='1'><tr><td colspan='4'>" +chr(10)+chr(13)
document.write"<center><b><h1>Output Report</h1></b></center></td></tr><tr><td colspan='4'>&nbsp;</td></tr>"+chr(10)+chr(13)
document.write"<tr><td colspan='4' align='center'><b><h3>Radio Buttons</h3></b></td>"+chr(10)+chr(13)
document.write"<tr><td>Name of Radio Button: a1</td><td>Value of each radio button: Radio 1, Radio 2, Radio 3, Radio 4, Radio 5, Radio 6</td>"+chr(10)+chr(13)
document.write"<td>Radio button checked at load time: Radio 1</td><td>Radio button checked by user: "&Radio_Value+chr(10)+chr(13)
document.write"</td</tr><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Checkboxes</h3></b></td></tr>"+chr(10)+chr(13)
document.write"<tr><td colspan='2'>Name of each checkbox: B1, B2, B3, B4</td><td colspan='2'>Selected Value: " &SName
document.write"</td></tr><tr><td colspan='4'>&nbsp;</td></tr>" +chr(10)+chr(13)<tr><td colspan='4' align='center'><b><h3>Selectbox</h3></b></td></tr>"+chr(10)+chr(13)
document.write"<tr><td>Name of the select box: c1</td><td>Options and associated values: <ul><li>First one, First one<li>Second optiom, Second option<li>" +chr(10)+chr(13)
document.write"Third option, Third option<li> Fourth option, Fourth option<li>Fifth option, Fifth option<li>Sixth option, Sixth option</ul></td>" +chr(10)+chr(13)
document.write"<td>Index of the initial selection and its value: O, First one</td>"+chr(10)+chr(13)
document.write"<td>Index and value of initial selected by user: " &select_index" " &select_d1 +chr(10)+chr(13)
document.write"</td><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Textbox</h3></b></td></tr>"+chr(10)+chr(13)
document.write"<tr><td>Name of the Textbox: d1</td><td>Original contents and length: Null, 0</td>"+chr(10)+chr(13)
document.write"<td>User's entry and length of entry before editing: " &oldchar_a "and " &oldcharlen_a+chr(10)+chr(13)
document.write"</td><td>User's entry and length of entry after editing: " &newchar_a "and " &newcharlen_a+chr(10)+chr(13)
document.write"</td></tr><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Textarea</h3></b></td></tr>"+chr(10)+chr(13)
document.write"<tr><td>Name of textarea: e1</td><td>Original Contents and length: default value, 13</td>"+chr(10)+chr(13)      
document.write"<td>User's entry and length of entry before editing: "&oldchar_b "and "&oldcharlen_b+chr(10)+chr(13)  
document.write"</td><td>User's entry and length of entry after editing: "&newchar_b "and "&newcharlen_b+chr(10)+chr(13)
document.write"</td></tr></table></body></html>      

end sub      


--->
</script>
</head>
<body bgcolor="ffffc0">
<Form name="Schweinehund">
<center><b><h2>Assignment 2</h2></b></center><p><br>
<center><table border="0" width="80%" bgcolor="ffffc0">
<tr>
    <td>RI<input type="radio" name="a1" checked value="Radio 1"></td>
    <td>R2<input type="radio" name="a1" value="Radio 2"></td>
    <td>R3<input type="radio" name="a1" value="Radio 3"></td>
    <td>R4<input type="radio" name="a1" value="Radio 4"></td>
    <td>R5<input type="radio" name="a1" value="Radio 5"></td>
    <td>R6<input type="radio" name="a1" value="Radio 6"></td>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr><td colspan="6"><table border="0" width="100%" bgcolor="ffffc0"><tr>
    <td>B1<input type="checkbox"  name="b1 value="b1" ></td>
    <td>B2<input type="checkbox"  name="b2 value="b2" ></td>
    <td>B3<input type="checkbox"  name="b3 value="b3" ></td>
    <td>B4<input type="checkbox"  name="b4 value="b4" ></td></table></td></tr>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr>
    <td colspan="6">
    <center><select name="c1">
            <option value="default" selected>First Option
            <option value="Second option">Second Option
            <option value="Third option">Third Option
            <option value="Fourth option">Fourth Option
            <option value="Fifth option">Fifth Option
            <option value="Sixth option">Sixth Option
    </center>  
    </select></td>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr>
    <td colspan="6"><center><INPUT TYPE="text" NAME="d1" maxlength="30"></center></td>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr>
    <td colspan="6"><center><textarea name="e1" rows="5" cols="40"></textarea>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr>
    <td colspan="6"><center><input type="button" value="Edit and Report" name="f1"></td>
</tr>
</table></center>
</form>
</body>
</html>

 

by: RamojiPosted on 2002-10-18 at 12:10:22ID: 7345779

Hi,

There are so many coding mistakes (Syntax) in your code. I have corrected all of them. You just need to paste the following code as it is into a HTML file and run it in a browser.

<html>
<title>Conquer_Parks_2</title>
<head>
<SCRIPT LANGUAGE="VBScript">

sub f1_onclick
      Check_True=0
      for i=0 to document.all("a1").length-1
         if Schweinehund.a1(i).checked = true then
            Radio_Value=Schweinehund.elements(i).value
         end if
      next  

      for i= 0 to document.all("b1").length-1
         if Schweinehund.b1(i).checked=true then
            Check_True=Check_True+1    
            SName=SName + Schweinehund.b1(i).name + " "
         end if
      next  
      if Check_True=0 then
            msgbox"Select at least one value"
            exit sub
      end if
      if Schweinehund.c1.value="default" then
            msgbox"Select a value other than default"
            exit sub
      end if
      c1_value=Schweinehund.c1.options(Schweinehund.c1.selectedIndex).text
      oldchar_a=Schweinehund.d1.value
      if oldchar_a="" then
            oldchar_a = "Blank"
            newchar_a = "Blank"
      else
            newchar_a=replace("oldchar_a","/","")
            newchar_a=replace("newchar_a","\","")
            newchar_a=replace("newchar_a","*","")
      end if
      oldcharlen_a=len(oldchar_a)
      newcharlen_a=len(newchar_a)      
      
      oldchar_b=Schweinehund.e1.value
      if oldchar_b="" then
            oldchar_b = "Blank"
            newchar_b = "Blank"
      else
            newchar_b=replace("oldchar_b","","+")
            newchar_b=replace("newchar_b",chr(13),"")
            newchar_b=replace("newchar_b",chr(10),"")
      end if
      oldcharlen_b=len(oldchar_b)
      newcharlen_b=len(newchar_b)    
      
      document.clear
      document.open
      document.write"<html><body bgcolor='#ffffc0'>"
      document.write"<table width='80%' bgcolor='#ffffc0' border='1'><tr><td colspan='4'>"
      document.write"<center><b><h1>Output Report</h1></b></center></td></tr><tr><td colspan='4'>&nbsp;</td></tr>"
      document.write"<tr><td colspan='4' align='center'><b><h3>Radio Buttons</h3></b></td>"
      document.write"<tr><td>Name of Radio Button: a1</td><td>Value of each radio button: Radio 1, Radio 2, Radio 3, Radio 4, Radio 5, Radio 6</td>"
      document.write"<td>Radio button checked at load time: Radio 1</td><td>Radio button checked by user: " & Radio_Value
      document.write"</td</tr><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Checkboxes</h3></b></td></tr>"
      document.write"<tr><td colspan='2'>Name of each checkbox: B1, B2, B3, B4</td><td colspan='2'>Selected Value: " & SName
      document.write"</td></tr><tr><td colspan='4'>&nbsp;</td></tr>" +chr(10)+chr(13) + "<tr><td colspan='4' align='center'><b><h3>Selectbox</h3></b></td></tr>"
      document.write"<tr><td>Name of the select box: c1</td><td>Options and associated values: <ul><li>First one, First one<li>Second optiom, Second option<li>"
      document.write"Third option, Third option<li> Fourth option, Fourth option<li>Fifth option, Fifth option<li>Sixth option, Sixth option</ul></td>"
      document.write"<td>Index of the initial selection and its value: O, First one</td>"
      document.write"<td>Index and value of initial selected by user: " & c1_value
      document.write"</td><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Textbox</h3></b></td></tr>"
      document.write"<tr><td>Name of the Textbox: d1</td><td>Original contents and length: Null, 0</td>"
      document.write"<td>Users entry and length of entry before editing: " & oldchar_a & " and " & oldcharlen_a & "</td>"
      document.write"</td><td>User's entry and length of entry after editing: " & newchar_a & " and " & newcharlen_a
      document.write"</td></tr><tr><td colspan='4'>&nbsp;</td></tr><tr><td colspan='4' align='center'><b><h3>Textarea</h3></b></td></tr>"
      document.write"<tr><td>Name of textarea: e1</td><td>Original Contents and length: default value, 13</td>"    
      document.write"<td>User's entry and length of entry before editing: " & oldchar_b & " and " & oldcharlen_b
      document.write"</td><td>User's entry and length of entry after editing: " & newchar_b & " and " & newcharlen_b
      document.write"</td></tr></table></body></html>"    

end sub      



</script>
</head>
<body bgcolor="ffffc0">
<Form name="Schweinehund" id="Schweinehund">
<center><b><h2>Assignment 2</h2></b></center>
<p><br>
<center><table border="0" width="80%" bgcolor="ffffc0">
<tr>
   <td>RI<input type="radio" name="a1" checked value="Radio 1"></td>
   <td>R2<input type="radio" name="a1" value="Radio 2"></td>
   <td>R3<input type="radio" name="a1" value="Radio 3"></td>
   <td>R4<input type="radio" name="a1" value="Radio 4"></td>
   <td>R5<input type="radio" name="a1" value="Radio 5"></td>
   <td>R6<input type="radio" name="a1" value="Radio 6"></td>
</tr>
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
   <td colspan="6">
            <table border="0" width="100%" bgcolor="ffffc0">
            <tr>
                  <td>B1<input type="checkbox"  name="b1" value="b1"></td>
                  <td>B2<input type="checkbox"  name="b1" value="b2"></td>
                  <td>B3<input type="checkbox"  name="b1" value="b3"></td>
                  <td>B4<input type="checkbox"  name="b1" value="b4"></td>
            </tr>      
            </table>
   </td>
</tr>
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
   <td colspan="6">
   <center>
   <select name="c1">
           <option value="default" selected>First Option
           <option value="Second option">Second Option
           <option value="Third option">Third Option
           <option value="Fourth option">Fourth Option
           <option value="Fifth option">Fifth Option
           <option value="Sixth option">Sixth Option
      </select>
      </center>
   </td>
</tr>
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
   <td colspan="6"><center><INPUT TYPE="text" NAME="d1" maxlength="30"></center></td>
</tr>
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
   <td colspan="6"><center><textarea name="e1" rows="5" cols="40"></textarea>
</tr><tr><td colspan="6">&nbsp;</td>
</tr><tr>
   <td colspan="6">
   <center>
            <input type="button" value="Edit and Report" name="f1" >
   </td>
</tr>
</table></center>
</form>
</body>
</html>

Best of luck.

Regards,
Ramoji.

 

by: dschafer77Posted on 2002-10-18 at 12:53:35ID: 7345911

Thank you so much.  
I guess I have a long way to go to master that language.
I will be asking for your expertise again.

Daniel

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...