|
-
May 5th, 2004, 08:15 PM
#1
Thread Starter
PowerPoster
Altering code required by windows ...(Resolved... I Hope!!)
Hi.
In the thread
http://www.vbforums.com/showthread.p...hreadid=288791
no one has suggested altering the declaration of the textbox in form1 to Public Shared. If you do this, then it is fully accessible from form2.
However, In the region of code involved, it clearly states that code should only be modified by using the Form Designer. I have had no problem in altering it with the Code Editor, but how can you alter the declaration by using the Form Designer?
Last edited by taxes; May 10th, 2004 at 11:28 AM.
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.
-
May 6th, 2004, 12:13 AM
#2
PowerPoster
Click the control, and in the property window I think the property is called Modifier or something like that. You can switch it there.
-
May 6th, 2004, 06:20 AM
#3
Thread Starter
PowerPoster
Hi hellswraith,
Thanks. There is no "Shared" declaration available in the Modifiers Property drop-down. None of the listed Modifiers allow reference from frmB to an object in frmA, unless frmA was instanced from formB.
However, such a reference IS allowed if the declaration in the prohibited region of the code window is amended to "Public Shared" If you amend the declaration to "Shared" then you get a build error message but if you select 'Continue' access IS permitted.
I can find no reference in any documentation to the sharing of objects on a Windows form (as opposed to a Web Form).
Is it possible that VB.NET is not intended to allow sharing of objects (other than through the chain of instantiation) and that the behaviour listed above is an unintended (and possibly unreliable) quirk?
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.
-
May 8th, 2004, 05:20 AM
#4
Thread Starter
PowerPoster
Hi,
Anyone got any knowledgable input on this, please?
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.
-
May 8th, 2004, 04:16 PM
#5
Hi.
As far as I know, there's really nothing wrong with altering the code yourself. I think they just write that you shouldn't, because when you do, you have the power to screw everything up.
I think MS is just covering their asses, so they can't be blamed if you accidently ruin several days or weeks of programming.
Also, depending on what you change, you face the risk of it being changed back, the next time the designer updates the code.
But then again...I could be wrong...
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
May 10th, 2004, 09:04 AM
#6
Frenzied Member
trust me...you CAN screw something up if you don't know what you're doing lol I learned the hard way. I believe it's perfectly fine, though, to alter the code manually if you are willing to.
-
May 10th, 2004, 09:24 AM
#7
I do it all the time. Heck, I didn't even know that warning was even there until the other day. As long as you don't try to do anything too screwy in there, there shouldn't be any harm.
TG
-
May 10th, 2004, 11:27 AM
#8
Thread Starter
PowerPoster
Hi,
Thanks guys. I will now proceed with (misplaced???) confidence
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.
-
May 11th, 2004, 04:57 AM
#9
New Member
Declare a Refrence
All you have to do to gain access to a control on a form (or the entire form for that matter) is to declare a reference variable of whatever scope you want it to have from a separate module.
I.E.
VB Code:
'In Module1.vb:
Friend myForm1 as Form1
'In Form1.vb:
Private Sub Form_Load()
myForm1=Me
End Sub
'In Form2.vb
Private Sub AccessForm1()
myForm1.Text="Hello"
End Sub
Of course it dosen't have to be a Form reference, it could just as easily be a Button or TextBox.
-
May 11th, 2004, 05:06 AM
#10
Thread Starter
PowerPoster
Hi,
"All you have to do to gain access to a control on a form (or the entire form for that matter) is to declare a reference variable of whatever scope you want it to have from a separate module."
How does that help me declare the object as Public Shared???? Or are you posting this as an answer to http://www.vbforums.com/showthread....threadid=288791?
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.
-
May 12th, 2004, 07:31 AM
#11
New Member
Wouldn't it make sense that you could declare it as a Public Shared reference?
-
May 12th, 2004, 07:50 PM
#12
Thread Starter
PowerPoster
Hi blue_rabbit,
Have a look at my first post in this thread. In the other thread to which I referred several ways of accessing an object in another form were discussed, including using reference variables but no one mentioned declaring the object as public shared. The only way to do this is in the prohibited coding section of the form and all I wanted to know is whether or not that particular approach would cause problems. The only problem I have come accross is that you get a build error the first time you run the project after you make the amendment but not thereafter. There are many ways to access objects in other forms, each one having advantages and disadvantages. In the end, it is down to our own personal preferences.
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
|