Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Calling methods and using properties

I have craeted a class which includes  overloaded methods,read -write properties, and methods. I have also created the user interface consisting of text boxs,radio button,datetime picker, and listbox. I can't figure out the proper way to call methods and properties I used in the class. One book says use a dim statement another book says to include RaiseEvent statement in the class and a public event statement in the code of the main form. I really having a hard time figuring waht to do.
0
augie0216
Asked:
augie0216
  • 3
  • 2
  • 2
4 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
It's unclear exactly what you want here...

Is the goal for the user interface to update values inside the class based on changes made in the GUI?

~IM
0
 
augie0216Author Commented:
It is a class module thet simulates aircraft arriving and departing from an airport. the solution calculates charges based on the amount of time the aircraft stays at the airport, what type of aircraft it is, and any fuel that may be purchased for the aircraft. The user enters the the aircraftID, the carriername, type of aircraft (radio buttons) ,arrival time,departing time, dates and fuel used.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So are you using one class where you pass in all that info and you should get back the results from a single function?

...or are you creating mulitple instances of this class where they all co-exist and should raise events simulating real-time events based on timers?

~IM
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
augie0216Author Commented:
I'm not sure how to answer your question. I'm very confused on this whole concept of creating reusable components with classes. The book I'm using isn't good at conveying what you are suppose to do.It gives you examples but then has you do things that are totally different then the excercises you are expected to do. If you can't answer the question I submitted because of vague information I provided you please accept my apology.
0
 
cheliosCommented:
I take it you just mean generally calling a Sub or Function you'e defined in the class, inside the form code. If so then it's quite simple, but there are a few things you must remember classes:

Public Class Form1
  Public Sub Button1_Click(ByVal sender As Object, e as EventArgs) Handles Button1.Click

     ''' When using a method from a class, always "instantiate" the class.
     ''' This means including the "New" modifier in the Dim statement.
     ''' This stops you from getting "Object reference not set to an instance of an Object" exceptions.
     Dim clsYourClass As New clsClass

     ''' Then to call a method (which must be a Public/Friend method in the class to be used outside the class itself)...
     clsYourClass.YourMethod()

  End Sub

Note: If you've added a "Sub New" constructor to your class, when you instatiate it, you must include any constructor arguments
that you specified in the "Sub New".

Hope this helps, if it's what you need :)

Chelios
End Class
0
 
augie0216Author Commented:
When would you use the example you provided versus the raise event statement and With Events statement ?
0
 
cheliosCommented:
A RaiseEvent statement is used to do just that. Using events is useful for when you're writing multi-threaded applications or you want fast and responsive code.

If all you need to do is call a method that does something to some data, but it's defined in a seperate class, you can just use the example.

 If, however, you want to use events to tell your program when to do something, for example, when the user types an invalid character in a text box, you could use RaiseEvent to raise an event called "InvalidCharInputEvent" that you've defined, then you would write a mehtod to "Handle" that event, in this case, you could show a Message Box telling the user that the input is invalid.

I think that's a bit deep though for what you need. Judging by your question, you just need to know how to use a method from a seperate class. One thing worth noting, is that if you write methods in a Module, you can access those methods from anywhere in your program without having to instantiate the module it is in. Modules are always useful if you want to have a method that can be accessed frequently without the need to instantiate it every time.

Hope this clears it up a bit :)

Chelios
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now