EDN Admin
Well-known member
VBscript question; Code is at end of this question.<br/>
<br/>
Instead of creating an entirely new Sub with hard-coded values for Case, I want to pass different variables, and different numbers of variables to the Sub for the Case to look for.<br/>
<br/>
Instead of creating 3 unique Subs each with its own Case variables to look for:<br/>
<br/>
Case "c","e","s" <br/>
Case "a","b" <br/>
Case "a","z","b","e","j","f"<br/>
<br/>
I want to make the Sub generic, and instead pass to the Case, whatever number of variables I please:<br/>
<br/>
Dim lstrLook4Me
lstrLook4Me = "c","e","s"<br/>
Call sTester( "File", "d:tempNew Text Document.vbs", "c:users", "desktop",
lstrLook4Me )<br/>
... snip ...<br/>
Case lstrLook4<br/>
<br/>
=-=-=-=-=-=-=-=-=-=-<br/>
Option Explicit
Dim objShell : Set objShell = Wscript.CreateObject( "Wscript.Shell" )<br/>
Dim objFSO : Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Dim lstrLook4Me
lstrLook4Me = "c","e","s"<br/>
Call sTester( "File", "d:tempNew Text Document.vbs", "c:users", "desktop",
lstrLook4Me )
lstrLook4Me = "a","b"<br/>
Call sTester( "File", "d:tempNew Text Document2.vbs", "c:users", "desktop",
lstrLook4Me )
lstrLook4Me = "a","z","b","e","j","f"<br/>
Call sTester( "File", "d:tempNew Text Document3.vbs", "c:users", "desktop",
lstrLook4Me )
Sub sTester( bCopyType, lstrSrcObject, lstrDestProfilePath, lstrDestPath,
lstrLook4 )<br/>
Dim objSubFolder<br/>
If objFSO.FolderExists( lstrDestProfilePath ) Then<br/>
For Each objSubFolder in objFSO.GetFolder( lstrDestProfilePath ).Subfolders<br/>
Select Case Left( LCase( objSubFolder.Name ),1 )<br/>
Case lstrLook4<br/>
Case "c","e","s" <br/>
Case "a","b" <br/>
Case "a","z","b","e","j","f"<br/>
wscript.echo "Found: " & objSubfolder.Name<br/>
objFSO.CopyFile lstrSrcObject , objSubfolder.Path & lstrDestPath , TRUE<br/>
End Select<br/>
Next<br/>
End If<br/>
Set objSubFolder = Nothing<br/>
End Sub
wscript.quit<br/>
eof
View the full article
<br/>
Instead of creating an entirely new Sub with hard-coded values for Case, I want to pass different variables, and different numbers of variables to the Sub for the Case to look for.<br/>
<br/>
Instead of creating 3 unique Subs each with its own Case variables to look for:<br/>
<br/>
Case "c","e","s" <br/>
Case "a","b" <br/>
Case "a","z","b","e","j","f"<br/>
<br/>
I want to make the Sub generic, and instead pass to the Case, whatever number of variables I please:<br/>
<br/>
Dim lstrLook4Me
lstrLook4Me = "c","e","s"<br/>
Call sTester( "File", "d:tempNew Text Document.vbs", "c:users", "desktop",
lstrLook4Me )<br/>
... snip ...<br/>
Case lstrLook4<br/>
<br/>
=-=-=-=-=-=-=-=-=-=-<br/>
Option Explicit
Dim objShell : Set objShell = Wscript.CreateObject( "Wscript.Shell" )<br/>
Dim objFSO : Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Dim lstrLook4Me
lstrLook4Me = "c","e","s"<br/>
Call sTester( "File", "d:tempNew Text Document.vbs", "c:users", "desktop",
lstrLook4Me )
lstrLook4Me = "a","b"<br/>
Call sTester( "File", "d:tempNew Text Document2.vbs", "c:users", "desktop",
lstrLook4Me )
lstrLook4Me = "a","z","b","e","j","f"<br/>
Call sTester( "File", "d:tempNew Text Document3.vbs", "c:users", "desktop",
lstrLook4Me )
Sub sTester( bCopyType, lstrSrcObject, lstrDestProfilePath, lstrDestPath,
lstrLook4 )<br/>
Dim objSubFolder<br/>
If objFSO.FolderExists( lstrDestProfilePath ) Then<br/>
For Each objSubFolder in objFSO.GetFolder( lstrDestProfilePath ).Subfolders<br/>
Select Case Left( LCase( objSubFolder.Name ),1 )<br/>
Case lstrLook4<br/>
Case "c","e","s" <br/>
Case "a","b" <br/>
Case "a","z","b","e","j","f"<br/>
wscript.echo "Found: " & objSubfolder.Name<br/>
objFSO.CopyFile lstrSrcObject , objSubfolder.Path & lstrDestPath , TRUE<br/>
End Select<br/>
Next<br/>
End If<br/>
Set objSubFolder = Nothing<br/>
End Sub
wscript.quit<br/>
eof
View the full article