Simple question regarding modules

R

RSH

Hi,

i have a situation where I have a VB .Net Module built that contains all of
the functions I need. I now need to add a form to the project and i need
the form to sdisplay and the module code to write to the form. I am having
trouble figuring out how to do this.

Basically, I have Form1 which contains a button and a TextBox. Module1
contains a function called Function1. I want to attach an event to the
button which will call Function1 in the Module1 which in turn will display a
simple line of text to the TextBox on Form1

This is the code I have:

Sub in Module1...

Public Sub initialTest()

MessageBox.Show("hi")

Dim oForm = New Form1

oForm.RTB1.text = "Hi"

System.Windows.Forms.Application.DoEvents()

End Sub





Button Click in Form1

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

Module1.initialTest()

End Sub



The event is getting to Module1 and displaying the messagebox, but I get an
error "Public member 'TextBox' on type Form1 Not Found"



What needs to be done?



Thanks,

RSH
 
C

Chris

RSH said:
Hi,

i have a situation where I have a VB .Net Module built that contains all of
the functions I need. I now need to add a form to the project and i need
the form to sdisplay and the module code to write to the form. I am having
trouble figuring out how to do this.

Basically, I have Form1 which contains a button and a TextBox. Module1
contains a function called Function1. I want to attach an event to the
button which will call Function1 in the Module1 which in turn will display a
simple line of text to the TextBox on Form1

This is the code I have:

Sub in Module1...

Public Sub initialTest()

MessageBox.Show("hi")

Dim oForm = New Form1

oForm.RTB1.text = "Hi"

System.Windows.Forms.Application.DoEvents()

End Sub





Button Click in Form1

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

Module1.initialTest()

End Sub



The event is getting to Module1 and displaying the messagebox, but I get an
error "Public member 'TextBox' on type Form1 Not Found"



What needs to be done?



Thanks,

RSH

To do this you need to make a public property on form1 that will accept
a string. In that property assign the RTB1.text property.

Public Property RTB1Text() as String
Get
return RTB1.Text
End Get
Set(ByVal Value as String)
RTB1.Text = Value
End Set
End Property

The problem you are having the way you are doing it is that RTB1 is
private on Form1 and therefor cannot be accessed by anything outside of
Class Form1

Hope it helps
Chris
 
R

RSH

Okay another silly question...now that i set that up how do i access it? I
get an error "Reference to a non-shared member requires an object reference.

Form1.RTB1Text = "TESTING"



Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top