For Next loop malfunctioning
Hi all,
I have a simple script (part of HTA file) as follows:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\" & strComputerName & "\c$\Windows\System32\CCM\Logs")
Set colSubfolders = objFolder.Files
For Each objSubfolder in colSubfolders
strLogLoc = "\\" & strComputerName & "\c$\Windows\System32\CCM\Logs" & objSubfolder.Name
strHtm = strHtm & "<tr onmouseover=""this.className='tblhover'"" onmouseout=""this.className='tblnorm'""><td width=""500""> " & objSubfolder.Name & "<td>" & fnmemory(objSubfolder.Size) & "</td><td><a href=""#"" onclick=OpenLog(strLogLoc)>test</a></td><td>" & strLogLoc & "</td></tr>"
Next
Sub OpenLog(strLogLoc)
msgbox("OpenLog has been reached with value " & strlogloc)
End Sub
The problem is at strLogLoc:
- the OnClick event generates a "Variable undefined" error
- simply outputting the variable shows a full concatened path in the exact way I would want to see it
If I replace...
Code:
onclick=OpenLog(strLogLoc)
with
Code:
onclick=OpenLog(""Woopsie"")
...then the OpenLog sub is entered and performed nicely (including the passed on variable).
I have no idea what I'm doing wrong and I would really like this to work!
Many many thanks in advance!
Regards
Re: For Next loop malfunctioning
So why no just define the strLogLoc?
Dim strLogLoc As String
Re: For Next loop malfunctioning
Well, if I add the part you gave me, it just starts shouting other vars are suddenly undefined as well. I would really like a structural solution to this. Is there something I did wrong in the code? Is the logic not right?
Re: For Next loop malfunctioning
because that isn't the issue... the issue is that the strLogLoc is defined as a string in the code... but then it's trying to be used as a parameter int the javascripty code, where it has no concept of strLogLoc...
This could get messy... but...
...onclick=OpenLog(strLogLoc)...
should be:
...onclick=OpenLog(" & strLogLoc & ")...
It may take some tweaking... maybe even a lot of tweaking... to get the " all right... but it is what it is...
-tg
Re: For Next loop malfunctioning
Quote:
Originally Posted by
techgnome
because that isn't the issue... the issue is that the strLogLoc is defined as a string in the code... but then it's trying to be used as a parameter int the javascripty code, where it has no concept of strLogLoc...
This could get messy... but...
...onclick=OpenLog(strLogLoc)...
should be:
...onclick=OpenLog(" & strLogLoc & ")...
It may take some tweaking... maybe even a lot of tweaking... to get the " all right... but it is what it is...
-tg
Hi,
Thanks for your reply.
I was afraid of that! Thanks, I'll give it a shot!
Thanks a lot!
Re: For Next loop malfunctioning
If you now have the answer you need, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that by selecting the Mark Thread Resolved item from the Thread Tools menu. Otherwise please insert "[Resolved]" at the start of the Subject and select the green checkmark from the Post Icons. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.
Re: For Next loop malfunctioning
Hi all,
I've gotten the script to work as far as syntax goes.
However, I have 1 last problem. The strCommandLine doesn't update its file name part and every link you click opens the same file (last in folder)
Code:
strComputerName = "mymachinenamegoeshere"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\" & strComputerName & "\c$\Windows\System32\CCM\Logs")
Set colSubfolders = objFolder.Files
strHtm = "<table>"
For Each objSubfolder in colSubfolders
strLogLoc = "\\" & strComputerName & "\c$\Windows\System32\CCM\Logs\" & objSubfolder.Name
strCommandLine = "trace32.exe " & strLogLoc
strHtm = strHtm & "<tr><td width=""500""> " & objSubfolder.Name & "<td>" & objSubfolder.Size & "</td><td><a href=""#"" onclick=RunExternal(strCommandLine) title=""" & strCommandLine & """ >test</a></td><td>" & strLogLoc & "</td></tr>"
Next
strHtm = strHtm & "<table>"
dataarea.innerhtml = strHtm
Function RunExternal(CommandToRun)
Set WshShell = CreateObject("WScript.Shell")
WshShell.run(CommandToRun)
End Function
Any ideas as to why this is? strCommandLine is based on strLogLoc. strLogLoc is updated properly! Tooltipping strCommandLine shows every file individually as expected.
Thanks in advance!
Re: For Next loop malfunctioning
I'm currently trying to get it to work using an array for strCommandLine, because I think it's being overwritten on each iteration. However, I cannot call a function/sub with an array value? It keeps saying "Invalid procedure call or invalid parameter". Any ideas?
Current code:
Code:
strComputerName = "sso603143"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("\\" & strComputerName & "\c$\Windows\System32\CCM\Logs")
Set colSubfolders = objFolder.Files
Dim strCommandLine(80)
strHtm = "<table>"
iCount = 0
For Each objSubfolder in colSubfolders
strLogLoc = "\\" & strComputerName & "\c$\Windows\System32\CCM\Logs\" & objSubfolder.Name
strCommandLine(iCount) = "trace32.exe " & strLogLoc
strHtm = strHtm & "<tr><td width=""500""> " & objSubfolder.Name & "<td>" & objSubfolder.Size & "</td><td><a href=""#"" onclick=RunExternal(strCommandLine(iCount)) title=""" & strCommandLine(iCount) & """>test</a></td><td>iCount: " & iCount & ":" & strCommandLine(iCount) & "</td></tr>"
iCount = iCount + 1
Next
strHtm = strHtm & "<table>"
dataarea.innerhtml = strHtm
Function RunExternal(strCommandToRun)
Set WshShell = CreateObject("WScript.Shell")
WshShell.run(strCommandToRun)
End Function
Thanks!
Re: For Next loop malfunctioning
Is anyone able to help me with this? It's really frustrating not getting this to work! This functionality has to work otherwise this part of the script is rendered useless entirely!
Regards
Re: For Next loop malfunctioning
well you should be able to print strhtm either to the immediate window or file so you can study the output to see what result you are getting (or view the source in browser window)
Quote:
onclick=RunExternal(strCommandLine)
i would think the onclick value should be enclosed in quotes
i am not sure there would be any advantage to using an array for this procedure
Re: For Next loop malfunctioning
Hi,
Thanks for your reply!
I tried outputting the compiled string to a msgbox and it showed no syntax errors whatsoever. However, it kept giving Invalid procedure call or invalid parameter errors. Now, I removed the functioncall and altered the href tag to include file path variable instead. It now shows an IE download popup and upon opening it opens in the associated tool.
Good enough for me atm.
THanks