Results 1 to 11 of 11

Thread: For Next loop malfunctioning

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    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

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: For Next loop malfunctioning

    So why no just define the strLogLoc?

    Dim strLogLoc As String

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    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?

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    Re: For Next loop malfunctioning

    Quote Originally Posted by techgnome View Post
    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!

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  7. #7

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    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!

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    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!

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    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

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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)

    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
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    7

    Resolved 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width