I suck

PSU_Justin

Newcomer
Joined
Feb 24, 2003
Messages
19
Location
State College, PA
I've been trying to get some functions between multiple forms to work for 2 weeks now (Not non-stop) and have been largely unsucessful.

Here is some new code I am trying out, it doesn't work at all yet and I'm not sure why.

This is for Form 1

Visual Basic:
Public Class Class1
    Dim f1 As New Form1()

    Public Sub main()
        Application.Run()
        f1.Show()

    End Sub
End Class

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2()
        f2.Show()
        Me.Hide()

    End Sub
End Class

This is for form2

Visual Basic:
Public Class Form2
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim n As Single

        n = TextBox1.Text
        Class1.f1.textbox1.text = n
        Me.Hide()

    End Sub
End Class

Right now I'm getting an error saying that Class1.f1... in the second form is not accessible b/c it is private. This is alo one of my first attempts at using classes and I don't know if I am using them right or if I am using the application.run command in the proper context (that command isn't even in my VB.net book, I got it from a suggestion here).

Is I suck a bad way to get people to look at my post??

Any help is greatly appreciated.

Justin
 
I wouldnt use sub main. I would start directly with the Form1 and pass that instance to the second form.
Creative post title btw. :)
 
No use classes, thats the whole point of object oriented programming :D
What I meant is just create a form and set it as startup form, without the application.run and sub main, so the form class is started in the beginning. Then when you want to create a new instance of form2 you pass in the instance of the Form1 that started the application and which contains the textbox you want to edit. You can do that by overloading a constructor.
Type something like this into your Form2:
Visual Basic:
dim somevariabletoholdforminstance as Form1
    Public Sub New(ByVal form as Form1)
        MyBase.New()
        InitializeComponent()
        somevariabletoholdforminstance = form
'now you can access that instance of the Form1 through that variable.
    End Sub
 
OR

If you want to do it your way dim the form1 instance in your class1 like this:
Visual Basic:
Public f1 as new Form1()

:D
 
Back
Top