By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,728 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,728 IT Pros & Developers. It's quick & easy.

Simple question regarding modules

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
RSH wrote:
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
Nov 21 '05 #2

P: n/a
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!
"Chris" <no@spam.com> wrote in message
news:O0**************@TK2MSFTNGP09.phx.gbl...
RSH wrote:
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.