How to manage / call methods, procedures, forms in multiple Modules, classes, ect.?

Hello and thank for the help. I am such an amature. Can't find the right books either.

I have created a windows form, and a lable array class and a sub main in a module

 

BeamCalculation is a form

Label Array is a class

Calculate is a Module

 

I am trying to run my program from the Module, I din BC as New BeamCalculation withthe hope that I can use BC throughout the module to perfor data and controlminipulation, A Dynamic Form that I change according to the calculation tye. I am getting 2 errors at line 15.

1. An unhandled exception of type 'System.NullReferenceException' occurred in Beam Calculations.exe

Additional information: Object reference not set to an instance of an object

2. An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.

Additional information: The type initializer for "Beam_Calculations.Calculate" threw an exception.

What and how do I reference the form and am I heading in the wrong direction

 

1. Module Calculate

2. Public BC As New BeamCalc

3. Sub main()

4. 'BC.Show()

5. Application.Run(BC)

6. End Sub

 

7. Sub Calc()

8. 'Elastic Constant

9. Dim E As Double = 1600000

10. 'Material Size

11. Dim b As Double = 1.5

12. Dim d As Double = 3.25

13. 'Define Formulas for beam calculations

14' Dim myString As String = BC.txbDL.Text

15. Dim DL As Double = Val(BC.txbDL.Text)

16. Dim LL As Double = Val(BC.txbLL.Text)




Answer this question

How to manage / call methods, procedures, forms in multiple Modules, classes, ect.?

  • wildabeast

    That's not too complex.

    Make each form... like beamcalc as a new form and file. You can create a windows app nomally, add form classes at will and you will have what you want. One way or the other it has to be compiled. One thing to consider may be to make a dll (DYnamic linked library) with all these libraries.



  • Aeneas117

    Yes these classes and modules are all in the same Application. I am trying to orginize my code for reuse. Like calculate should be a general module onf calculations for engineering. Won't need to be compiled when entering time card information, ect. I am trying to learn how to minuplate class, modules, ect. all from 1 application. I want to be able to open windows forms from other applications and use procedures from other modules in other applications. Pretty complex!

  • smoker

     

    Ok,

    If in your example, Form1 is a class, Project1 is a namespace.

     

    Namespace Project1

    Public Class Form1

    friend withevents textbox1 as textbox

    Public Function GetTextbox1() as string

    return textbox1.text

    end function

    End Class

    End NameSpace

     

    Namespace Project2

    Public Class Form1

    friend withevents textbox1 as textbox

    Public Function GetTextbox1() as String

    return textbox1.text

    end function

    End Class

    End NameSpace

     

    BUT... you dont want to mess with controls from one project or class from another.

    You want to call a Public property to do that for you to maintain a standard interface. The whole idea of classes is that they not know about the insides of each other. They may know to call a property of another class which constitutes a public interface.

    If Project1.form1.Gettextbox = Project2.form1.Gettextbox then Calculate

    In any case, whatever it is that you come up with it's going to have to be compiled.

    DLL's know about Namespaces and classess.

     



  • daWiki

     

    I think we have some nomenclatural problems.

    You haven't started another application. You are attemtping to execute an

    uninstantiated class called BeamCalc in the same application.

    How am I supposer to instantiated something and where. How do I reference it.

    Certainly objects must be instantiated before they are used. How to instantiate them depends upon the object itself. Many objects are instantiated just by saying

    Dim Diction as New Dictionary(of mumble)

    My inference is that you have an non instantiated variable in BeamCalc itself. I'm also confused about why you are starting beamcalc for a module. What functionality are you trying to achieve What version of  VS are are you running

    The difference is often forgetting to use NEW. You can get debugging help in a couple of ways. Your exception message will have a stack trace. That will help you.

    What will help us is for you to post the stack trace and BeamCalc.

     

     



  • bengchuan

     The code is the sam as above.

    I have started a windows application called BeamCalculation, added a label array control from a class I built called lblarray, and I am trying to put the code for running the program in the calculate module. I planned to add more forms and modules until This is the progrm from hell.

     

    I would attach the file if I new how to.

    How am I supposer to instantiated something and where. How do I reference it.



  • JKMax

    I tried what you have suggested and I get only 1 error

     This error is crashing on the line 15 as before

    An unhandled exception of type 'System.NullReferenceException' occurred in Beam Calculations.exe

    Additional information: Object reference not set to an instance of an object.

    What does this mean Do I need to reference it some how



  • Siggy2006

    So you understand what I want!

     

    For me it get more confusing. If I creat forms and modules, and class in seperate projects and or within the same project, how can I minuplate the controls and data within References Initializers

     

    For instance

    IF project1.form1.textbox1 = project2.form2.textbox2 THEN

        CALCULATE()

    ELSE

        'DO Nothing

    END IF

    How do I work with other forms and projects



  • Sjoert

     

    Modules have really different properties and behaviors than do Classes and a form is a class.

    Let's look at what you have here....

    1. Module Calculate

    2. Public BC As New BeamCalc

    3. Sub main()

    4. 'BC.Show()

    5. Application.Run(BC)

    6. End Sub

     

    I see where you have declared bc as a bew BeamCalc. If that were a class, class instantantiation woulf have instantiated BeamCalc but I don't think it's being instantiated in a module. I assume this is a console task

    What I believe happens here is that you come into Main and attempt to use BeamCalc which has never really been instantiated.

    Just out of curiosity sakes what happens if you did this

    2. Public BC As BeamCalc  ' note the new has been removed here

    3. Sub main()

    BC = new BeamCalc

    4. BC.Show()

    '5. Application.Run(BC)

    6. End Sub

     

     

     

     

     



  • Kitty Butler

     

    First of all,

    Is this a windows form app, or is it a console app I'm not trying to be obtuse, I'm just wondering what factors went into your decision to structure this in that fashion

     

    Line 15 of what

    The error you are referring to suggests that you haven't instantiated the object referenced at the crash.

    Could we see what you are trying to excute and also the code around this line 15 and how those objects are instantiated



  • How to manage / call methods, procedures, forms in multiple Modules, classes, ect.?