Structure
Classes
Class files being called inside a form would look something like this: Dim NewName as ClassFile
NewName would be any name you want and ClassFile is the name of the class file you want the form to interact with.
Inside a class file are properties that are asigned default values of some sort.
Each property contains a value, so if we want to use a value, we can grab it but calling the property we created.
Here's a short example.
I will create a short tutorial that will display Hello World in the window title bar when the form loads.
Create a new Class file and call it FormLoad.vb
Under Public Class FormLoad type in Public __HWorld__ As String = "Hello World"
Drop down a couple lines and here we will create our property
Type in the following code
Public Property __TitleText__ As String
Get
Return __HWorld__
End Get
Set(ByVal value As String)
__HWorld__ = Value
End Set
End Property
Now create a new Form and call it something like Test.vb
Double click on the form to create the Form_Load event
Once inside the form load event type in the following.
Dim WinTitle As New FormLoad
Me.Text = WinTitle.__HWorld__
Make sure to set your startup form to Test.
Now if you run the program (press F5) you will now see the window title say Hello World.
Modules
Modules work a little differently than classes.
The Module files is where alot of the code lives and gets called in just about the same way as classes but still different.
You can create a Public Sub AnyName() and store your code within it.
You can have the form execute that line of code by calling AnyName().
Here's a short example.
Create a new Module.vb file and call it FormLoad.vb
Inside the Module FormLoad type in the following
Public Sub __WindowTitle__()
Test.Text = "This is my first Module!"
End Sub
If you created a form called Test.vb by following the Classes tutorial than open that form, otherwise create a new Form and call it Test.
Double click on the form to create the Form_Load event.
If you forllowed the Classes tutorial you can Comment or remove the previous code as it's not needed.
Type in the following
__WindowTitle__()
Make sure to set your Startup form to Test
Now you can debug your application (F5 on your keyboard)
You will now see the window title displays as This is my first Module!
Something to note about
With Class files you can call the properties in any form you wish provideing you add a new declaration to the file and set it as a new (ClassFileNme).
With Modules, you would have to modify the Module file by adding the forms, so using the example above, if you want another form to display This is my first Module!
you would have to set it in the same Public Sub.
Public Sub __WindowTitle__()
Test.Text = "This is my first Module!"
FormName.Text = "This is my first Module!"
End Sub
You can access all the forms using the My.Forms property.