Results 1 to 6 of 6

Thread: Unloading a Module before calling it again.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Unloading a Module before calling it again.

    In the Code examples below I call a module called Compile with a function called Compile. In that module you will see that I define a new form called Errorfrm as new Form3. If I click the meun button once and the errorfrm pops up and displays an error. I then close the newly displayed form and click the menu item again and I get an error in the module compile in the function compile when I try to display the errorfrm. So my question is, Do I have to unload the module or something so I do not get an error?

    [code]
    Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
    Compile.Compile(Code)
    End Sub
    [\code]

    [code]
    Module Compile
    Dim Errorfrm As New Form3

    Public Function Compile(ByVal Code As RichTextBox


    ' SHOW THE ERROR FORM INCASE THERE IS AN ERROR
    Errorfrm.Show() ' THE SECOND TIME I RUN THIS FUNCTION THIS IS WHERE I GET THE ERROR. THE FIRST TIME EVERYTHING RUNS FINE

    ' CHECK TO SEE IF THERE ARE ANY LINES IN THE CODE
    ' IF NOT REPORT A MAJOR ERROR AND EXIT
    If (Code_Length = 0) Then
    ' ADD THE ERROR TO THE LIST
    Errorfrm.Errorlst.Items.Add("Line 0 - Error Code 1 - Major error, no code to be compiled")
    ' SINCE IT IS A MAJOR ERROR, NOTHING TO COMPILE
    ' EXIT THE FUNCTION AND RETURN CONTROL BACK TO THE CALLING FUNCTION
    Exit Function
    End If

    End Function
    End Module
    [\code]

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why use a module at all? I would switch it to a shared class instead but either way there is no reason to have the instance of form3 to be created at that scope. You can have the compile function create the instance and solve the problem.
    VB Code:
    1. Module Compile
    2.  
    3.  
    4. Public Function Compile(ByVal Code As RichTextBox
    5.  
    6. [b]Dim Errorfrm As New Form3[/b] 'inside the method call
    7. ' SHOW THE ERROR FORM INCASE THERE IS AN ERROR
    8. Errorfrm.Show() ' THE SECOND TIME I RUN THIS FUNCTION THIS IS WHERE I GET THE ERROR. THE FIRST TIME EVERYTHING RUNS FINE
    9.  
    10. ' CHECK TO SEE IF THERE ARE ANY LINES IN THE CODE
    11. ' IF NOT REPORT A MAJOR ERROR AND EXIT
    12. If (Code_Length = 0) Then
    13. ' ADD THE ERROR TO THE LIST
    14. Errorfrm.Errorlst.Items.Add("Line 0 - Error Code 1 - Major error, no code to be compiled")
    15. ' SINCE IT IS A MAJOR ERROR, NOTHING TO COMPILE
    16. ' EXIT THE FUNCTION AND RETURN CONTROL BACK TO THE CALLING FUNCTION
    17. Exit Function
    18. End If
    19.  
    20. End Function
    21. End Module

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313
    I was going to do that but when my code hits the exit function statment, it will or should (I think) close the errorfrm that was created inside the compile function. And I need the errorfrm to stay open so the user can see his mistakes and fix them.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should read up on OOP Object Oriented Programming. I started to convert your function for you but there are values that must come from some global values elsewhere because it doesn't make sense. Or maybe you just didn't post all of the code. Try using Showdialog instead of show to keep the form active.

    For instance where is CODE_LENGTH declared or where does the value come from?

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try this:
    VB Code:
    1. Class Compile
    2.  
    3. Public Shared Sub Compile(ByVal Code As RichTextBox)
    4.  
    5. If Code.Text.Length=0 then
    6.    Dim Errorfrm As New Form3
    7.    Errorfrm.Errorlst.Items.Add("Line 0 - Error Code 1 - Major error, no code to be compiled")
    8.    Errorfrm.ShowDialog()
    9. End if
    10.  
    11. End Sub
    12.  
    13. End Class

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313
    Thanks, oop in c++ is easy, so this should be a snap, just never cared to use it. Mostly because all of my books are on vb6 and none talk about oop, so i did't know how. But I see what you are talking about. and Code_Length is a value that holds the length of a line of text in my rich text box, so i used a varible insted of doing len(code.line(X)) since a var is faster to access then a function. But thank you for your help.

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