Wrap "Open" VB6 function with custom function as drop in replacement

Viewed 87

Question

Is there any way to write a custom function that uses the same pattern as the Open function? Including the fluff keywords like For and As?

VB6 Help documentation describing the open statement

Background

I am working on migrating an old VB6 project to use online data via an API, as a first step I'd like to replace all instances of

Open SomeFilename For Binary Access Read As #39

With a custom OpenOnline function

OpenOnline SomeFilename For Binary Access Read As #39

But I do not know how to indicate those keywords are necessary when creating a function, or even if it's possible to do so.

Function openOnline(FileName As String) [For] (Optional Access As AccessType = Binary Access) [As] (Optional FileNumber As Integer) As Boolean
    ' Do the work of connecting to the online data equivalent of FileName with that access type
End Function

Qualifiers

I understand that these keywords are nonsensical in the context of an OpenOnline function. I also understand that I can use regular expressions to find and replace the syntax to remove keywords like "For" and "Read".

There are hundreds of thousands of instances of this Open function, the Put and Get functions and a few other file related functions, I realize that long term the correct solution is changing the mechanisms fundamentally to use online paradigms, and that work is in progress- on schedule to be completed with about 4 months of effort at the rate things are going.

Bonus Question

Secondarily, is there any way for me to pass a "User Defined Type" variable to the new Put/Get replacements in a way that I can access their fields directly without knowing the type beforehand? (I understand that variants are only available for .cls classes or public user defined types in dlls, neither of which apply in this situation)

1 Answers

As for 1), you can get close but you can't exactly replicate the VB Open statement. Which means you won't get around of some search & replace passes for the current Open statement lines with your newly created one.

For 2), can you illustrate that with an example? I'm trying to think of a situation where you know the UDT member's name in advance, but not its type.

That said, perhaps looking at VB's VarType function gives you an idea for solving that.

Related