PC Review


Reply
Thread Tools Rate Thread

Can't access Textbox1.text from a Module

 
 
Ken Soenen
Guest
Posts: n/a
 
      10th Aug 2005
The code below illustrates my problem which is: I'm trying to access the
TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text"
produces the error--Reference to a non-shared member requires an object
reference". Being new to VB.NET, this doesn't say much to me, nor does the
Show Task Help for this particular msg. Just one example would make all the
difference in the world. Can somebody point me in the right direction??

thanks,
ken



Module Module1

Sub test1()

Dim aa As String

aa = Form1.TextBox1.Text

End Sub

End Module



 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      11th Aug 2005
Ken,

One option is to place the test1 subprocedure in the form that contains the
textbox. You could then refer directly to the textbox.

Another option is to have the test1 subprocedure accept a textbox as an
argument:

Sub test1(ByVal myTextbox As Textbox)

aa = myTextbox.Text

Then, when you call the sub, send it the textbox.

Kerry Moorman


"Ken Soenen" wrote:

> The code below illustrates my problem which is: I'm trying to access the
> TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text"
> produces the error--Reference to a non-shared member requires an object
> reference". Being new to VB.NET, this doesn't say much to me, nor does the
> Show Task Help for this particular msg. Just one example would make all the
> difference in the world. Can somebody point me in the right direction??
>
> thanks,
> ken
>
>
>
> Module Module1
>
> Sub test1()
>
> Dim aa As String
>
> aa = Form1.TextBox1.Text
>
> End Sub
>
> End Module
>
>
>
>

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      11th Aug 2005
Ken Soenen wrote:
> The code below illustrates my problem which is: I'm trying to access the
> TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text"
> produces the error--Reference to a non-shared member requires an object
> reference". Being new to VB.NET, this doesn't say much to me, nor does the
> Show Task Help for this particular msg. Just one example would make all the
> difference in the world. Can somebody point me in the right direction??
>
> thanks,
> ken
>
>
>
> Module Module1
>
> Sub test1()
>
> Dim aa As String
>
> aa = Form1.TextBox1.Text
>
> End Sub
>
> End Module
>
>
>


It is telling you that you never instatiated the Form1 object.

Module Module1

Sub test1()

Dim aa As String
dim Frm as new Form1
aa = Frm.TextBox1.Text

End Sub

End Module

This would work but I doubt it is exactly what you are looking to do.
If you give more info about what you are trying to accomplish then we
could help you more.

Chris
 
Reply With Quote
 
Ken Soenen
Guest
Posts: n/a
 
      12th Aug 2005
Kerry,

Thanks for the help. After 40 years of programming in the older languages(C,
Fortran, Basic, Ada, Jovial..), this new stuff is all smoke, mirrors, and
voodoo. I've used Visual Basic quite a bit in Excel. It is pretty straight
forword. But not in VB.NET!!

Anyway, your 1st option works. That is the way I originally had it set up
before I decided to put it in a Module(since it seemed that it was just
cluttering up the Form). The second option, I never would have come up with.
It works also. I'm still wrestling with Chris' response about instantiation.
I have to get back to him. Again thanks for the help.

ken


"Kerry Moorman" <(E-Mail Removed)> wrote in message
news:456CEF3A-A7BC-49D3-BCF5-(E-Mail Removed)...
> Ken,
>
> One option is to place the test1 subprocedure in the form that contains
> the
> textbox. You could then refer directly to the textbox.
>
> Another option is to have the test1 subprocedure accept a textbox as an
> argument:
>
> Sub test1(ByVal myTextbox As Textbox)
>
> aa = myTextbox.Text
>
> Then, when you call the sub, send it the textbox.
>
> Kerry Moorman
>
>
> "Ken Soenen" wrote:
>
>> The code below illustrates my problem which is: I'm trying to access the
>> TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text"
>> produces the error--Reference to a non-shared member requires an object
>> reference". Being new to VB.NET, this doesn't say much to me, nor does
>> the
>> Show Task Help for this particular msg. Just one example would make all
>> the
>> difference in the world. Can somebody point me in the right direction??
>>
>> thanks,
>> ken
>>
>>
>>
>> Module Module1
>>
>> Sub test1()
>>
>> Dim aa As String
>>
>> aa = Form1.TextBox1.Text
>>
>> End Sub
>>
>> End Module
>>
>>
>>
>>



 
Reply With Quote
 
Ken Soenen
Guest
Posts: n/a
 
      12th Aug 2005
Chris,
The above was just a drop back position to try to understand something basic
before I tackled my real problem. Which was:

From a button on the Form, I was calling Test1(endtime). "endtime" is a
string "globally" defined in the Form1. I needed to modify this "endtime" in
test1() and before returning I wanted to set Timer1.Enabled and
Timer1.Interval (as I just wrote this I realized I could have avoided this
whole situation by setting these properties in the Form1 after the return
from Test1. What a BOZO! But then again I wouldn't have learned what I
did.). To get back to the situation. Referencing these 2 properties in Test1
caused the error msg. So, actually I did what you suggested (before I cried
WOLF) as in creating a new instance of Form1 in Test1. So, this made the
compiler happy. NOW the problem was, back in the FORM1, the code was still
using the INITIAL value of the "Global" variable "endtime" instead of the
modified value that I passed back to the Form. It appears that I was
changing "endtime" in the NEW Instance of Form1 and NOT in Form1. To Make a
long story short, in order to make the thing work(that is in the BOZO mode)
was to instantiate the new form in the FORM1: Public Shared fForm1 As New
Form1. Thanks for your input. You gave me enough so I could look in the
right place and I learned tons (I think).

thanks,
ken

"Chris" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Ken Soenen wrote:
>> The code below illustrates my problem which is: I'm trying to access the
>> TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text"
>> produces the error--Reference to a non-shared member requires an object
>> reference". Being new to VB.NET, this doesn't say much to me, nor does
>> the Show Task Help for this particular msg. Just one example would make
>> all the difference in the world. Can somebody point me in the right
>> direction??
>>
>> thanks,
>> ken
>>
>>
>>
>> Module Module1
>>
>> Sub test1()
>>
>> Dim aa As String
>>
>> aa = Form1.TextBox1.Text
>>
>> End Sub
>>
>> End Module
>>
>>
>>

>
> It is telling you that you never instatiated the Form1 object.
>
> Module Module1
>
> Sub test1()
>
> Dim aa As String
> dim Frm as new Form1
> aa = Frm.TextBox1.Text
> End Sub
>
> End Module
>
> This would work but I doubt it is exactly what you are looking to do. If
> you give more info about what you are trying to accomplish then we could
> help you more.
>
> Chris



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Surprise with Textbox1.Text =?Utf-8?B?UmFrZXNoIFBhcmVraA==?= Microsoft Dot NET 3 25th Apr 2006 03:35 PM
select all text when textbox1 is clicked cj Microsoft VB .NET 3 29th Mar 2006 04:05 AM
converting from TextBox1.Text to Byte() Jason Microsoft VB .NET 2 10th Jan 2006 05:40 PM
Set textbox1.enabled = false inside a module? David Eadie Microsoft VB .NET 4 7th Apr 2005 08:57 AM
set textbox1.text from datagrid1 rows =?Utf-8?B?YmFmaWRp?= Microsoft VB .NET 1 26th Mar 2004 11:02 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:53 PM.