Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript CreateObject method help

$
0
0

Hello,

I've been working on a script that will read the columns of an excel file and store the data into an array. Once I have the arrays I will create checkbox's using the data that they contain. The code I have for this is as follows:

Sub btn0_OnClick
Dim arrNames()
Dim arrValues()
Dim arrPrograms()
Dim arrChkNames()
Dim length
Dim name

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\crizzuti\Desktop\App\test1.xlsx")

i = 1
x = 0
length = 0
y = 0
z = 0
w = 0
n = 0

Do Until objExcel.Cells(i, 1).Value = ""
	ReDim Preserve arrNames(x)
	ReDim Preserve arrValues(y)
	ReDim Preserve arrPrograms(z)
	ReDim Preserve arrChkNames(w)
	arrNames(x) = objExcel.Cells(i, 1).Value
	arrValues(y) = objExcel.Cells(i, 2).Value
	arrPrograms(z) = objExcel.Cells(i, 3).Value
	If InStr (arrNames(x)," ") = 0 Then
		arrChkNames(w) = arrNames(x)
	Else
		arrChkNames(w) = Replace(arrNames(x)," ","")
	End If

    HTAFile.WriteLine "   <tr>"
    HTAFile.WriteLine "       <td>"
    HTAFile.WriteLine "           <div class=squaredTwo>"   
    HTAFile.WriteLine "               <input type=checkbox class=" & arrPrograms(z) & " id=checkbox" & length & " value=" & arrValues(y) & " name=" & arrChkNames(w) & ">"
    HTAFile.WriteLine "               <label id=label for=checkbox" & length & ">"
    HTAFile.WriteLine "           </div>"
    HTAFile.WriteLine "       </td>"
    HTAFile.WriteLine "       <td>" & arrNames(x) & "</td>"
    HTAFile.WriteLine "       <td>"
    HTAFile.WriteLine "   </tr>"

	i = i + 1
    x = x + 1
    y = y + 1
    z = z + 1
    w = w + 1
	length = length + 1
Loop
objExcel.Quit

End Sub


The problem I am having is that I want to use the data stored in the arrChkNames() array to test if the checkbox is checked once the buttonbtn0 is clicked. Each checkbox's name attribute will have the names given to it from thearrChkNames() array. So I am trying to do something like this:

For n = 0 To length
        If arrChkNames(n).Checked Then
	    MsgBox arrValues(n) & "/" & arrPrograms(n)
        End If
Next

The error message I get when I run this code is "Object Required arrChkNames(...)." I understand that I am going to have to use the CreateObject method to retrieve the name from each checkbox to run through the loop. (Or maybe there is another way to do it I am open to anything).

Please advise how I can do this using the CreateObject method or if there is a better method to do this.

Thank you.



Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>