Results 1 to 2 of 2

Thread: New VB6 IDE prototype with Backporter for use with the upcoming VB6Namespaces release

  1. #1

    Thread Starter
    Hyperactive Member TTn's Avatar
    Join Date
    Jul 2004

    New VB6 IDE prototype with Backporter for use with the upcoming VB6Namespaces release

    In order to back-port VB.NET code to VB6 with the new VB6Namespaces, I needed to create a new IDE.
    At the moment, the VB6 IDE is a just a prototype that can open VB6 projects, edit, save and compile executable files.

    • It has a "New Project" dialog window, that has templates inside to choose from, and the VB6Namespaces template as the default.
    • The VB6 IDE can automatically remove unused classes at compile time, from the VB6Namespaces collection. These classes are included by default, with a New "Standard" project.
    • A class builder is included to help you nest classes efficiently.
    • Also featuring an "Add module"and "Add form" option. References can be added as well.
    • There is also a properties toolbox window for these module level objects. unfortunately, there is no object browser though.
    • Most importantly, it has a back-porter that allows you to import VB.NET project files (or copy/paste code), and convert them as close as possible to VB6. The classes included in the VB6Namespaces template help in the process, since these classes are already available by defaut in a standard exe. Most code can be copied and pasted after back-porting it. Some code will need minor edits though, depending on the scope and various writing styles etc.

    Interestingly, this serves a hybrid between the two variations of the Visual Basic language. For example, the IDE can accept code into the window that normally would not be understood by VB6, but at compilation time that this hybrid can generate the raw code auto-magically to do something new, ie accept new keywords like AndAlso, and OrElse etc., or it can accept and convert python code to vb6 in the newly compiled application etc.

    I have made a lot more progress on the VB6Namespaces collection, and I have included color coded treeview control to show the approximate completion level of the classes.

    Here is a preview of the new VB6 IDE prototype (proof of concept). The prototype is written in VB.NET 2005. I used VB.NET because it allows me to develop this kind of product rapidly. Although once the project is finished, I can use the backporter to help make a clean VB6 version. Still, the VB.NET version may retain certain abilities that can help port additional namespaces in the future. VB6 can't do that without some kind of redundant interop, although it's totally possible.


    If anyone would like to write classes I am trying to map out some standards that I use.
    I will reference MS press whenever I can, but some things learned here are through experience. Here are just a few ideas.

    Practical Standards for Visual Basic.
    Microsoft Press, 2000
    Chapter 3. Page 25.

    "...Modules and procedures are the framework for the code of your application, and building this framework requires careful consideration...and you should use these techniques when developing your project."

    For project templates
    Explicit scope definition
    Always define the scope of your variables, function, subs, and properties etc.

    Strong cohesion
    A class module is not simply a container of a bunch of procedures.
    Class modules should be used to organize sets of related procedures. Generally one should minimize the number of related procedures in a module. If the number of procedures has become cumbersome then simply organize those the procedures into several modules to be more easily maintained and debugged.

    The ability to expose only certain content to the client, and hide the rest of the procedures from external processes.
    C++ 6.0 lacked this ability at the process level, since it's procedures were still exposed to external applications using the "New" keyword.

    Private modules
    Create private modules whenever possible.
    This avoids naming conflicts and executes code faster since the information is not exposed to the whole public scope.
    It also avoids other applications from causing external issues with your code flow. This means that one should stay away from public solutions like ActiveX, DLL, or TLB's. In order to expose your functions to the rest of the application, you would use the Friend keyword. That way it doesn't expose the functions to external applications, and is encapsulated.

    Create self-contained modules whenever possible. A self-contained module means that the module does not rely on other modules
    to function properly. This also avoids dependency issues when the unused modules are to be removed before compilation. It is usually best to have a second copy of the code rather than have a class call another class. That may depend on the size and scope of course.

    Loosely coupled vs Tightly coupled
    Tightly coupled means that the procedure is tightly coupled to the other functions that it relies on to function properly. Just as modules are self-contained, you should try to create procedures that are also self-contained and do not rely on other functions to function. This is not always possible but try to follow the practice.

    Specialized procedures subs/functions
    Create only specialized function procedures in your modules. Avoid creating procedures that perform many different tasks. This will make it easier to maintain and manage over time.

    Always use the correct keywords to pass data ByRef or ByVal explicitly. This makes the code easier to read with blue keyword, but more importantly, it makes the code forward compatible to copy paste into a .NET IDE window. By default, a missing ByRef will be converted to ByVal in .NET, as the default. This will cause the code to fail if the parameter is modified inside the procedure. These keywords need to be written specifically for good compatibility practice.

    Use public properties rather than Public variables.
    Use the Call keyword for procedures.
    Declare only one variable per line.

    There are plenty more, but you get the point.
    Hope this is something useful, and I am always open to suggestions, criticisms, and requests.
    I have set the initial release date of V1 for October 31st of this year. I'm not sure how complete it will be, but I hope to create a stable foundation to start with. Feedback and requests will be welcomed after that.

  2. #2

    Thread Starter
    Hyperactive Member TTn's Avatar
    Join Date
    Jul 2004

    Re: New VB6 IDE prototype with Backporter for use with the upcoming VB6Namespaces rel

    If anyone wants to make their own custom IDE for some reason or another, then you will need to know more about the compilation process.
    Here is some information on the subject to get you started.

    First, the easy way to compile a project file is to call the command line with the WinExec API.
    The following command uses VB6.EXE to automate the compilation process.
    The arguments typically look like this:

    "C:\Program Files (x86)\Microsoft Visual Studio\VB98\VB6.EXE" /make "C:\VBlibrary\Project1.vbp" /out "C:\VBlibrary\errStatus.txt" /outdir "C:\VBlibrary\"
    Just remember that the quotes need to be there, so use Chr(34) to write quotation marks and join them with the strings above.
    For example: Chr(34) & "C:\Program Files (x86)\Microsoft Visual Studio\VB98\VB6.EXE" & Chr(34)

    In order to learn and fully understand the compliation process you will absolutely need to experiment with the following.
    Redirect the compilation process and capture the result into a log, to test the undocumented compiler switches.

    In a nutshell, C2.EXE compiles the object files, then the LINK.EXE links them together for the final output. C++ and Visual basic have nearly identical methods as they did in VS5.
    Advanced Microsoft Visual Basics (second edition)
    Chapter 7. Page 275.
    In a bas module:
    Sub Main()
        On Error GoTo skip
        If 0 = Len(Command) Then Exit Sub
        Dim sRealAppName As String
        sRealAppName = GetSetting(App.EXEName, "Startup", "RealAppName", "")
        If 0 = Len(sRealAppName) Then Exit Sub
        Call Shell(sRealAppName & " " & Command, vbHide)
        Dim nFile As Integer
        nFile = FreeFile
        Open App.EXEName & ".txt" For Append Access Write As nFile
        Print #nFile, "****** Run at " & Format(Date, "Short date") & " " & Format(Time, "Long Time")
        Print #nFile, sRealAppName & " " & Command
        Close nFile
    End Sub
    1. Compile OUTARGS.EXE above.
    2. Rename C2.EXE to C3.EXE. Found inside "C:\Program Files (x86)\Microsoft Visual Studio\VB98"
    3. Rename LINK.EXE to L1NK.EXE.
    4. Copy OUTARGS.EXE to the same folder.
    5. Rename OUTARGS.EXE to C2.EXE
    6. Make a copy of C2.EXE and rename it LINK.EXE.
    7. Import two new keys into the registry. The following reg code to a redirect.reg file:
      	Windows Registry Editor Version 5.00
      	[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\LINK\Startup]
      	[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\C2\Startup]

    Use Visual Basic as normal and it will hook the compilation process. The output file is written to C2.txt and LINK.txt.
    It will capture the params that were passed to invoke the compliation, depending on your project's properties.

    A typical command line compilation for C2 looks like this:
    C2 -il C:\Windows\Temp\VB603389 -f Form1 -W 3 -Gy -G5 -Gs4096 -dos -Z1 -FoC:\Temp\Form1.OBJ -QIfdiv -ML -basic
    Undocumented. Used for a C program to name intermediate language files.
    il C:\Windows\Temp\VB603389
    Temp files generated;VB603389GL,VB603389SY,VB603389EX,VB603389IN,VB603389DB

    The input file to be compiled.
    -f Form1
    Warning level 3
    -W 3
    Enable function level linking See command line: CL.EXE /? for Gx options below
    Optimize for pentium
    Turn off stack probes. When size stack is required for local variables, the stack proble is activated. Probe checks for enough space required for passed params and local variables is available on the stack before allocating it.
    Use for a C program.
    Remove default library name from OBJ file
    Name of output file
    Perform pentium FDIV erratum fix
    Create a single-threaded executable file. Places the library name LIBC.LIB in the object file so that the linker will use LIBC.LIB to resolve external symbols.
    Undocumented a new flag for Visual Basic compilation
    Command line compilation switches for LINk look like this:
    Form OBJ file
    Module OBJ file
    Project OBJ file
    Library of Visual Basic OBJs.
    C:\Program Files (x86)\Microsoft Visual Studio\VB98\VBAEXE6.LIB
    Sets the starting address for an executable file or DLL. This entry point is in your Project1.OBJ file.
    The output file exe
    Sets a base address for the program.
    Tells the OS how to run the .EXE (CONSOLE, WINDOWS, NATIVE, POSIX)
    Tells the linker to put a version number in the header of the executable file or DLL.
    Creates debug info for the exe or DLL, and places it in to the PDB(program database)
    Generates debugging info in one of 3 ways. (Microsoft format, COFF, both) COFF (common object file format)
    Specifies whether incremental linking is required.
    Excludes unreferenced packaged functions(using-Gy) from the exe.
    Combines the first section with the second section,. If the second section does not exist, LINK renames the section "from" as "to". The /MERGE option is most useful for creating VxD's and overriding compiler generated section names.
    Ignores certain warnings (defined in LINK.ERR). 4078 means that LINK found two or more sections that have the same name but different attributes.
    For VB6, there are some really good tools from Codejock, including an IDE starter sample.
    The sample has a form and custom controls needed, but without any code inside to load/run the IDE.

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