Results 1 to 28 of 28

Thread: Why are the variables not downloaded?

Threaded View

  1. #22
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,700

    Re: Why are the variables not downloaded?

    Quote Originally Posted by wqweto View Post
    Always use separate new form instances. Global Form1 predeclared instances are a left-over from MS Access times, where you can write a query w/ something like WHERE MyColumn = Form1!MyTextBox which is awful on so many levels.
    I've always thought that the predeclared feature of the forms was in the sake of RADness, I mean to make VB simpler for the programmers.
    I agree that it can lead to problems sometimes.

    And I agree that in general, it is preferable to use "custom" instances, because you have more clear control over the life cycle.

    But what would someone have to do it he needs a global instance of some form, and only needs to use this global instance and no others?

    He would have to declare in a module:

    Code:
     Public MyForm1 as New Form1
    But... VB already offers that option... by default.

    This brings to mind another one: never declare objects "As New".

    And regarding instantiation, when you instantiate an object like:

    Code:
    Dim F as Form1
        Set F = New Form1
        F.Show vbModal
    there is another one: "always set the object variables to Nothing after using them".

    They are in general good advices for good practice and to avoid errors, like other ones like "never use Goto" or some other rules that are good rules, but that IMO don't have to be enforced as hard rules, there is some place for those practices as long as you take care.

    Quote Originally Posted by wqweto View Post
    When you use Dim f As Form1 : Set f = New Form1 : f.Mostrar it's not possible to set f variable to Nothing in Form_Unload, can you? Just don't use global predeclared instances so that you never have to set the global Form1 references to Nothing too.
    That's sometimes necessary if you use a global variable for the form (and it would be the same if you used the predeclared variable Form1 or another one added by you like MyForm1) to set the form variable to Nothing when it closes in the case that the form is shown not modally.
    I don't see many others ways to do it.

    Quote Originally Posted by wqweto View Post
    I cannot think of *any* modern language (not just .Net ones) that promotes global state so blatantly as global predeclared form instances as implemented in VB6. And those predeclared classes are next to eradicate, just don't :-))

    cheers,
    </wqw>
    May be in the next version.

    EDit: Eh, no, it must be backward compatible.

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