Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic checkbox selection 2

Status
Not open for further replies.

country73

Technical User
Jan 17, 2003
59
US
I have an HTA that dynamically creates a list of checkboxes depending on what software needs to be installed on a machine.
Everything works fine if there is more than one checkbox to select, but I get the following error message whenever only one checkbox is created:

A Runtime Error has occured.
Do you wish to Debug?
Line: 320
Error: Object doesn't support this propery or method: 'checkNum.lengh'

The checkboxes are created with this layout:
Code:
<input type=""checkbox"" id=""" & strCount & """ name=""checkNum"" value=""" & sSplit(0) & """>" & sSplit(0) & "<br>"

strCount = number created for each checkbox starting at 1
sSplit(0) = name of software split from path to executable

Here is the SUB that is called when you have checked the check box and wish to Install the software:
Code:
SUB Install_List(checkNum)
   uncheckAll.Disabled = TRUE    'uncheck all button
   checkAll.Disabled = TRUE      'check all button
   installChecks.Disabled = TRUE 'install button
   FOR i = 0 to checkNum.length - 1
      IF checkNum(i).checked = TRUE THEN
         MSGBOX checkNum(i).Value
      END IF
   NEXT
END SUB

This code works fine if there are more than one check box created; it only errors out when there is only one check box created.
Can anyone point me in the right direction to correct this problem? Let me know if you need anymore information.
 
Have you tried to play with the IsArray function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
What exactly do you mean?
Use the IsArray inside of the Install_List SUB?
If so, no I haven't tried that.
How exactly should I use that?
 
Typed, untested:
If IsArray(checkNum) Then
For i = 0 To checkNum.length - 1
If checkNum(i).checked = True Then
MsgBox checkNum(i).Value
End If
Next
Else
If checkNum.checked = True Then
MsgBox checkNum.Value
End If
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
SWEET!!!
Sorry for my ignorance on this simple problem. Haven't really used the "IsArray" much in my scripting.
Will add that little bit to my "Helpful" Scripts for future scripting!

Thanks,
 
After further testing this would only work if only one checkbox existed.
I had to switch those subs around so that it would work if there was only one, or there were multiples.
Here is what I finally got to work out no matter how many checkbox's there were:

Code:
SUB Check_M_All(checkNum)
	ON ERROR RESUME NEXT
		checkNum.Checked = TRUE
		IF ERR.Number <> 0 THEN
			FOR i = 0 TO checkNum.length - 1
				checkNum(i).checked = TRUE
			NEXT
		END IF
	ON ERROR GOTO 0
END SUB

SUB UNCheck_M_All(checkNum)
	ON ERROR RESUME NEXT
		checkNum.Checked = FALSE
		IF ERR.Number <> 0 THEN
			FOR i = 0 TO checkNum.Length - 1
				checkNum(i).Checked = FALSE
			NEXT
		END IF
	ON ERROR GOTO 0
END SUB

SUB Install_List(checkNum)
	ON ERROR RESUME NEXT
		IF checkNum.Checked = TRUE THEN
			MSGBOX checkNum.Value
		END IF
		IF ERR.Number <> 0 THEN
			FOR i = 0 TO checkNum.Length - 1
				MSGBOX checkNum(i).Value
			NEXT
		END IF
	ON ERROR GOTO 0
END SUB
 
Oops! forgot these two lines in the "SUB Install_List(checkNum)

SUB Install_List(checkNum)
ON ERROR RESUME NEXT
IF checkNum.Checked = TRUE THEN
MSGBOX checkNum.Value
END IF
IF ERR.Number <> 0 THEN
FOR i = 0 TO checkNum.Length - 1
IF checkNum(i).Checked = TRUE THEN
MSGBOX checkNum(i).Value
END IF
NEXT
END IF
ON ERROR GOTO 0
END SUB

Now the problem is solved!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top