Results 1 to 4 of 4

Thread: Sub Main

  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sub Main

    Here's the Entire module from the Word97SR2 template:

    <pre> Sub main()
    Call MYOLDDOC
    End Sub
    </pre>


    Here's my code to iterate through each line of the module:

    <pre>Public Function LoadProcedureToListbox(oitem As Object, _
    strProcedure As String, lb As ListBox, strtextBox As String)
    ' Given the item (module) locate the procedure and load its lines to the listbox
    Dim intline As Integer
    intline = oitem.CodeModule.ProcBodyLine(strProcedure, vbext_pk_Proc)
    lb.Clear
    Do While oitem.CodeModule.ProcOfLine(intline, vbext_pk_Proc) = strProcedure
    Dim strLine As String
    strLine = oitem.CodeModule.Lines(intline, 1)
    lb.AddItem (strLine)
    Dim intFound As Integer
    If intCaseSensitive = 0 Then
    intFound = InStr(1, strLine, strtextBox)
    Else
    intFound = InStr(1, UCase(strLine), UCase(strtextBox))
    End If
    If intFound > 0 Then
    lb.Selected(lb.ListCount - 1) = True
    frmProcClip.Repaint
    Else
    End If
    intline = intline + 1
    Loop
    End Function
    </pre>


    By the time I Ctrl-Break the loop, intline is up around 5,300 somewhere.

    It's *as if* the test "oitem.CodeModule.ProcOfLine(intline, vbext_pk_Proc) = strProcedure" doesn't work with a Sub Main!

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Sub Main

    If I bring a code module that contains a Sub MAIN() to the foreground, then do this in the immediate window:

    Debug.Print Application.VBE.ActiveCodePane.CodeModule.ProcOfLi ne(5, vbext_pk_Proc)

    I get:

    MAIN

    Next theory?

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sub Main

    I get "mismatch" until I add a reference to the Extensibility library (without which nothing simple seems to work, mutter, mutter, mutter) but then I get MAIN, just like you.

    I wrote "as if" because I'd checked the name (breakpoint on the loop and a debug.print meself).


    As I hit these little nuts I drag the offending templates off to a pig-pen where they will be examined at leisure.

    I'm already upset at the Wordbasic converter not letting me trap its errors. Sub Main is a relic of WordBasic, and I never did understand why "main" was never a macro name. It seems that "Main" in a module means "My REAL name is that of my host module" and real soon now I'm going to get another of those errors where I'm not allowed to have a macro with the same name as a module or a template.

    I'm sounding flustered, I know .....

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sub Main

    Actually, Sub Main is what you usually call the startup routine in a VB project too, so don't blame it on WordBasic.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •