CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Re: send some code please

    Originally posted by Colt_777
    what is the 'me' part for in vb? i've seen this alot but i don't have a clue what it's about.
    Me ?

    it references the form or object you are currently in...
    if you have Form1 and you write code in Form_load (for example)
    you can say : Form1.DoSomthing or Me.DoSomething

    Me works much like this pointer in C++ if this can help..

  2. #17
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Me keyword

    Originally posted by Colt_777
    what is the 'me' part for in vb?
    Explain a bit better...Are you referring t o the "Me" keyword?
    If so, the Me is a way to refer to the instance of the object inside
    the object.
    Ie:
    in a form, named Form1,

    Me -inside code of Form1 -is near equivalent of Form1
    thus
    Me.Cls is = to Form1.Cls

    but that is not all:
    if you load the form this way:
    dim frmX as Form1
    set frmX = new Form1

    if inside Form1 you write:
    Me.Cls, this will work on FrmX (=that particular instance of Form1)
    while if you write Form1.Cls, inside that instance it will not clear
    the graphics in frmX instance, it will ...Load Form1!
    ...

    Thus:
    Code:
    If frmX.Hwnd<> Me.Hwnd then
    will work both if you called the form, or if you create an instance
    of it....

    in conclusion:
    when writing code inside a form for that form and you need to
    refer to taht for itself, take the habit to use "Me" instead of using
    the form name...
    Last edited by Cimperiali; April 27th, 2004 at 03:03 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #18
    Join Date
    Aug 2003
    Location
    London
    Posts
    515
    Have a look at this thread, there is example code & instruction on where to place & how to call...

  4. #19
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    forgot to mention this

    I forgot to tell you that i'm using the "End" command only when i want to close the main form and exit the program. The other forms are still using the "Unload Me" command to close. Is this less dangerous for my program?

  5. #20
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    Put code I gave you in the query_unload (or, if you really do not
    find it, in the unload) event of your main form. Where you
    coded "End" code instead: "Unload Me"
    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        'if you have any timers, disable
        'them here
        'If you have any loop with a Doevents
        'you need to set a boolean to true here
        'and check the value in loop to know you're
        'quitting and thus exit the loop there 
    
        'Put here the code I wrote
    End Sub
    Private Sub Command1_Click()
        
        'instead of End code:
        Unload me
    End Sub
    About less dangerous:
    all depends on what is not closing
    Using End will terminate abruptly. Like if you, to turn off yout Pc,
    simply cut off energy instead of using the "Shut down" option via
    code. As long as your program does not have file or connections
    opened, and as long as called components could close in any
    case when caller disappear (but this may not be in your hands),
    you could survive. But remember: it is really a bad practice...
    Last edited by Cimperiali; April 27th, 2004 at 08:37 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  6. #21
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    it's working

    Thanks a million Cimperiali I've done what u said and it's working now.
    Also i've tried the code Dmorley mentioned and that too is working. It's more like Cimperiali 's code, but more simple.

    So anyway, my program is closing like is supposed to close...normally.

    Thanks for helping us "little guys"


  7. #22
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Cool

    Thanks for feedback


    Have happy coding,
    Cesare I.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Page 2 of 2 FirstFirst 12

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

Featured