CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Posts
    91

    VBIDE & Functions & Parameters

    Hi out there,

    I'm having some problems with the following:

    After being sick and tired with all those weird and bad Addins for VB to implement a more advanced errorhandling, I've decided to write my own.
    The concept is this:
    - if an error is generated, a form pops up, the error-description, project, Module and procedure is listed, and the User can send a mail (smtp) with an errorprotocoll to the admin of the project.
    - While no error is generated, a second class "collects" events, procs etc that are called. This is needed for the error-protocoll, to supply the developer with the information he needs (usually the user is not able to verify that).

    Overall that works, but I have a problem concerning tha automation of that:
    I need a possibility to automatically generate code with the following information:

    Which arguments are passed to the method / sub / function?

    I wrote an VB-Addin that automatically delivers the name and type of the method / sub / function to the collection class mentioned above.

    But I'm just not able to find how to automatically specify the arguments passed

    Isn't there - in the VBIDE a collection that contains the passed arguments?

    something like

    for each arg in args
    debug.print arg.name & " " & arg.value
    next

    Does anyone have a clue?
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  2. #2
    Join Date
    Sep 2006
    Posts
    635

    Re: VBIDE & Functions & Parameters

    i think that you want this.

    Code:
    Private Sub FunctionVarArgs(ParamArray Args() As Variant)
    Dim v_x As Variant
    For Each v_x In Args
       Debug.Print v_x
    Next
    End Sub
    Private Sub Command1_Click()
    FunctionVarArgs "SSS", 55, "Str", 798, "00"
    FunctionVarArgs 789, 55, "Str", X1X798, "00"
    End Sub

  3. #3
    Join Date
    May 2001
    Posts
    91

    Re: VBIDE & Functions & Parameters

    Hi Hensa,

    I thought that my english may be too bad to make me clear ...

    What I need is a possiblility to auto-generate code via the VB-IDE.

    Lets assume I am in a collection, in the add-method. 3 arguments are needed to add an element to the collection.
    Current Code looks like this.

    Code:
     
    Public function add (a, b, c) as myclass
        Dim objNewMember As myclass
       
        Set objNewMember = New myclass
        
        objNewMember.a = a
        objNewMember.b= b
        objNewMember.c= c
       
        mCol.Add objNewMember
        Set Add = objNewMember
        Set objNewMember = Nothing
    end sub
    I want to automatically add Code, that at the end the sub looks like this (the autogenerated lines are needed for the error protocoll):

    Code:
     
    public function add (a, b, c) as myclass
    on error goto myerrhandler_Err
        errobject.addparam(a, "variant") ' this line was autogenerated
        errobject.addparam(b, "variant") ' this line was autogenerated
        errobject.addparam(a, "variant") ' this line was autogenerated
    
        Dim objNewMember As myclass
       
        Set objNewMember = New myclass
        
        objNewMember.a = a
        objNewMember.b= b
        objNewMember.c= c
       
        mCol.Add objNewMember
        Set Add = objNewMember
    exit_: ' To Kill the objects if error ...
        Set objNewMember = Nothing
    
    myerrhandler_Err
        errobject.onerror(err) ' Errorhandler to enable User to send mail etc.
        resume exit
    
    end sub
    The point is that I have more than 300 classes in my main project, maybe the same number in several dll's that I created. It is just impossible to add the lines every method for every class in time.
    From VBIDE I Can autogenerate the code for all of them (inside a single project) in one step.


    All this should be generated inside a VB-Addin
    Last edited by Patzer; December 19th, 2006 at 03:32 AM.
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

  4. #4
    Join Date
    Sep 2006
    Posts
    635

    Re: VBIDE & Functions & Parameters

    this add in called mztolls has a searcher
    then you can search Public function add (a, b, c) as myclass an after
    replace it with:

    Code:
    public function add (a, b, c) as myclasson 
    error goto myerrhandler_Err    
    errobject.addparam(a, "variant") ' this line was autogenerated    errobject.addparam(b, "variant") ' this line was autogenerated    errobject.addparam(a, "variant") ' this line was autogenerated
    mz tools

    it's a idea that I have.
    good luck

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: VBIDE & Functions & Parameters

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    May 2001
    Posts
    91

    Re: VBIDE & Functions & Parameters (solution, not tested)

    Hi,

    ok guess I found the solution. If anyone is interested:
    Inside a VB-Addin, this should be the principal way to deal with autogenerated lines. There has to be some more work concerning controls etc. to be done, but still these are the necessary collections.

    Code:
     
    
    private sub Autogenerate()
    Dim VBProj As VBProject 'Project-Objekt
        Dim VBRef As Reference 'Reference-Objekt
        Dim VBComp As VBComponent 'Component-Object
        Dim VBCtrl As VBControl  'Control-Object
        Dim VBMember As Member 'Member-Object
    
        Dim strline As String
        Dim lngstart As Long
        Dim strProcStartLine As String
    
    
        ' VBInstance is global var in Addins
        For Each VBProj In VBInstance.VBProjects 
            For Each VBRef In VBProj.References
                For Each VBComp In VBProj.VBComponents
                    For Each VBMember In VBComp.CodeModule.Members
                        ' get startline of procedure
                        lngstart = VBComp.CodeModule.ProcStartLine(VBMember.Name, VBMember.Type)
                        
                        strProcStartLine = VBComp.CodeModule.Lines(lngstart)
                        ' now I can split etc ...
                        
                        VBComp.CodeModule.InsertLines lngstart + 1, "this is my string"
                    Next
                Next
            Next
        Next
    end sub
    have a nice day

    Patzer
    _____________________________
    Philo will never be forgotten

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

Featured