VB6: I Can’t Figure Out Why This Code Works

VB6/A uses implicit two-way UTF16-ASCII translation when reading / writing files using built-in operators. Line Input treats the file as being in ASCII (a series of bytes, each represents a character), using the current system codepage for non-Unicode programs. The read characters are converted to UTF-16. When you read a UTF-8 file in this way, … Read more

Download File – VB6

If you want to do it with code only (no Internet Transfer Control), VBNet.mvps.org has a really good how-to article that uses the URLDownloadToFile API call. From the article: The URLDownloadToFile API is available on all versions of the Windows operating system (except Win3, WinNT3.x). By passing the remote file name and the local file … Read more

VB6 IDE cannot load MSCOMCTL.OCX after update KB 2687323

After hours of effort, system restore, register, unregister cycles and a night’s sleep I have managed to pinpoint the problem. It turns out that the project file contains the below line: Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX The version information “2.0” it seems was the reason of not loading. Changing it to “2.1” in notepad solved the problem: Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0; … Read more

How can I pretty-print XML source using VB6 and MSXML?

After months of research I’ve come up with this. Public Function PrettyPrintXML(XML As String) As String Dim Reader As New SAXXMLReader60 Dim Writer As New MXXMLWriter60 Writer.indent = True Writer.standalone = False Writer.omitXMLDeclaration = False Writer.encoding = “utf-8” Set Reader.contentHandler = Writer Set Reader.dtdHandler = Writer Set Reader.errorHandler = Writer Call Reader.putProperty(“http://xml.org/sax/properties/declaration-handler”, _ Writer) Call … Read more

what is the better way to handle errors in VB6

First of all, go get MZTools for Visual Basic 6, its free and invaluable. Second add a custom error handler on every function (yes, every function). The error handler we use looks something like this: On Error GoTo {PROCEDURE_NAME}_Error {PROCEDURE_BODY} On Error GoTo 0 Exit {PROCEDURE_TYPE} {PROCEDURE_NAME}_Error: LogError “Error ” & Err.Number & ” (” … Read more

Self Inspection of VB6 UDTs

Contrary to what others have said, it IS possible to get run-time type information for UDT’s in VB6 (although it is not a built-in language feature). Microsoft’s TypeLib Information Object Library (tlbinf32.dll) allows you to programmatically inspect COM type information at run-time. You should already have this component if you have Visual Studio installed: to … Read more