Recursively access subfolder files inside a folder

This is actually a well-solved problem. Recursion means that you create a self-referencing function (a function that calls itself). In your case you’d make the function call itself for each subfolder of the current folder. TraverseFolders objFso.GetFolder(strPath) Function TraverseFolders(fldr) ‘ do stuff with the files in fldr here, or … For Each sf In fldr.SubFolders … Read more

VBScript — Using error handling

VBScript has no notion of throwing or catching exceptions, but the runtime provides a global Err object that contains the results of the last operation performed. You have to explicitly check whether the Err.Number property is non-zero after each operation. On Error Resume Next DoStep1 If Err.Number <> 0 Then WScript.Echo “Error in DoStep1: ” … Read more

About using Double quotes in Vbscript

In VBScript, string literals are surrounded by double quotes (“). This is what your first example shows: Msgbox “This is myName” ‘ This works fine However, if you want to include a double quote character inside of your string literal, you’ve got a problem, because VBScript is going to interpret the second double quote character … Read more

VB6 pass by value and pass by reference

This is a classic gotcha in VB6. It is explained in the VB6 manual. In this code below, VB6 treats the argument as an expression (Test) rather than a variable reference TestFunction (Test) In order to pass a reference to the variable either omit the brackets or use the legacy Call statement (which requires brackets) … Read more

Is there a need to set Objects to Nothing

VB uses a so-called “reference counting” garbage collector. Basically, the moment a variable goes out of scope, the reference counter on the referenced object is decremented. When you assign the object reference to another variable, the reference counter is incremented. When the counter reaches zero, the object is ready for garbage collection. The object resources … Read more

Run Excel Macro from Outside Excel Using VBScript From Command Line

Ok, it’s actually simple. Assuming that your macro is in a module,not in one of the sheets, you use: objExcel.Application.Run “test.xls!dog” ‘notice the format of ‘workbook name’!macro For a filename with spaces, encase the filename with quotes. If you’ve placed the macro under a sheet, say sheet1, just assume sheet1 owns the function, which it … Read more

Any good libraries for parsing JSON in Classic ASP? [closed]

Keep in mind that Classic ASP includes JScript as well as VBScript. Interestingly, you can parse JSON using JScript and use the resulting objects directly in VBScript. Therefore, it is possible to use the canonical https://github.com/douglascrockford/JSON-js/blob/master/json2.js in server-side code with zero modifications. Of course, if your JSON includes any arrays, these will remain JScript arrays … Read more

Error ASP 0177: 8007007e CreateObject fails for COM DLL

The advice below relates to both Server.CreateObject and CreateObject use in vbscript jscript vba The Web Server sections are specific to asp-classic but still worth reading. What Causes This error? Server.CreateObject Failed is caused most commonly when Web Applications are moved from one Web Server to another without an understanding of external COM components that … Read more