|
-
Feb 23rd, 2004, 10:02 AM
#1
Thread Starter
Lively Member
How To Reference A Control On A Form From A Module?
How can I reference a control on a form from a module? For instance, I am trying to port some VB6 code to VB.NET and I have this in VB6:
Code:
lA = Split(frmMain.txtSB.Text, vbCrLf)
lB = Split(frmMain.txtRC.Text, vbCrLf)
where frmMain is the form and txtSB and txtRC are text boxes.
When I put that code in VB.NET 2003, it says:
Reference to a non-shared member requires an object reference.
I have looked in MSDN and I have not been able to find anything that sufficiently explains how to do it (if it did, it was too complicated, I am not an expert). Could anyone help me with how to do this? Thanks.
-
Feb 23rd, 2004, 10:26 AM
#2
PowerPoster
HI,
How have you started your project? From a sub Main in the Module?
If so, make sure you have declared the instance of frmMain as public in the general section of the module. i.e
Public frmMain as New XXXX
(XXX being the name of the form class from which frmMain is instanced)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 23rd, 2004, 10:32 AM
#3
Thread Starter
Lively Member
If I do that Public frmMain as New formNameHere wouldnt that make it not carry over the properties that were on the form at the time (ie what was filled in the text boxes, etc)? If so, wouldnt this not work because that is the data I am referencing?
-
Feb 23rd, 2004, 10:33 AM
#4
PowerPoster
HI,
I just noticed that you say you are using VB6. Is this a VB6 or a .NET question?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 23rd, 2004, 10:46 AM
#5
PowerPoster
"If I do that Public frmMain as New formNameHere wouldnt that make it not carry over the properties that were on the form at the time (ie what was filled in the text boxes, etc)? If so, wouldnt this not work because that is the data I am referencing?"
I'm not sure I understand your meaning (too many double negatives)
Suppose you designed a form named fclsMain, complete with text boxes, code etc.
You create a module named Mod1 and set the startup object as Sub Main
In the general section of Mod1 enter:
Public frmMain as new fclsMain
In Mod1 create the sub;
Public Sub Main()
Application.Run(frmMain)
End Sub
Now, any other sub you write in Mod1 will be accessable from any event in frmMain and will be able to access any object or public sub contained in frmMain.
I hope I covered whatever you asked in your last post!!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 23rd, 2004, 11:29 AM
#6
Thread Starter
Lively Member
Thanks a ton for the help with this Taxes. Your suggestion with "Sub Main()" did work for me, so my problem is solved. Thanks again.
Just to rant at Microsoft, I really dislike how I have to do this because that means that all the things I want to do have to be started from that module, which I think is really really bad. There has to be a better way to go about doing that.
-
Feb 23rd, 2004, 12:20 PM
#7
PowerPoster
Hi,
When you get used to it, you will find using the Module is the easiest way. What you want to do is put all your processing code in subs in the module and leave the forms for coding involving the objects on those forms.
You CAN start your application directly from a form but you have to be careful how you present it, or you will run in to other problems.
If you have just moved on from VB6, you will find that Inheritance and Classes are the two subjects you need to be completely au fait on and there are several threads in this forum if you search those headings. Also, don't forget MSDN help, it is very good.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|