Results 1 to 12 of 12

Thread: Altering code required by windows ...(Resolved... I Hope!!)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    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.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Click the control, and in the property window I think the property is called Modifier or something like that. You can switch it there.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    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...

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    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.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  9. #9
    New Member blue_rabbit's Avatar
    Join Date
    May 2004
    Location
    Behind enemy lines
    Posts
    9

    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:
    1. 'In Module1.vb:
    2. Friend myForm1 as Form1
    3.  
    4. 'In Form1.vb:
    5. Private Sub Form_Load()
    6.      myForm1=Me
    7. End Sub
    8.  
    9. 'In Form2.vb
    10. Private Sub AccessForm1()
    11.      myForm1.Text="Hello"
    12. End Sub

    Of course it dosen't have to be a Form reference, it could just as easily be a Button or TextBox.
    //END_TRANSMISSION

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  11. #11
    New Member blue_rabbit's Avatar
    Join Date
    May 2004
    Location
    Behind enemy lines
    Posts
    9
    Wouldn't it make sense that you could declare it as a Public Shared reference?
    //END_TRANSMISSION

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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
  •  



Click Here to Expand Forum to Full Width