G
Guest
I have alot of event procedures, variables and methods I do in many forms. I thought I'd try to call class functions to do them. I started with an extremely simple example. A start form has two buttons. One opens form1 the other form2. Click a button and it sets an integer in the class and opens the form. In each form 3 public integers are defined. Two have values. In the form1 load event I instantiate class1 and call the add procedure c = cls1.ad
In class1 the add function checks the integer. If 1 it instantiates form1, if 2 form2. Then it attempts to add frm.a + frm.b
Unsurprisingly, the project can't build, telling me that a and b are not members of class1
If I have to pass a and b, or set them as public integers in class1, then how is it possible to build classes that can do complicated things for many forms? There must be a way, because the dataform wizard does something like it
The code is below. Any help would be appreciated
polynomial5
Public Class StartFor
Inherits System.Windows.Forms.For
Dim cls1 As New Class
#Region " Windows Form Designer generated code
Private Sub btnForm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm1.Clic
cls1.iForm =
Dim frm As New Form
frm.Show(
End Su
Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Clic
cls1.iForm =
Dim frm As New Form
frm.Show(
End Su
End Clas
Public Class Form
Inherits System.Windows.Forms.For
Public a As Integer =
Public b As Integer =
Public c As Intege
#Region " Windows Form Designer generated code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim cls1 As New Class
c = cls1.Ad
MsgBox(c.ToString
End Su
End Clas
form 2 is almost identica
Public Class Class
Public iForm As Intege
Public Function Add() As Intege
Dim frm As For
Select Case iFor
Case
frm = New Form
Case
frm = New Form
Case Els
MsgBox("No such form"
End Selec
Add = frm.a + frm.
End Functio
End Class
In class1 the add function checks the integer. If 1 it instantiates form1, if 2 form2. Then it attempts to add frm.a + frm.b
Unsurprisingly, the project can't build, telling me that a and b are not members of class1
If I have to pass a and b, or set them as public integers in class1, then how is it possible to build classes that can do complicated things for many forms? There must be a way, because the dataform wizard does something like it
The code is below. Any help would be appreciated
polynomial5
Public Class StartFor
Inherits System.Windows.Forms.For
Dim cls1 As New Class
#Region " Windows Form Designer generated code
Private Sub btnForm1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm1.Clic
cls1.iForm =
Dim frm As New Form
frm.Show(
End Su
Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Clic
cls1.iForm =
Dim frm As New Form
frm.Show(
End Su
End Clas
Public Class Form
Inherits System.Windows.Forms.For
Public a As Integer =
Public b As Integer =
Public c As Intege
#Region " Windows Form Designer generated code
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim cls1 As New Class
c = cls1.Ad
MsgBox(c.ToString
End Su
End Clas
form 2 is almost identica
Public Class Class
Public iForm As Intege
Public Function Add() As Intege
Dim frm As For
Select Case iFor
Case
frm = New Form
Case
frm = New Form
Case Els
MsgBox("No such form"
End Selec
Add = frm.a + frm.
End Functio
End Class