Results 1 to 7 of 7

Thread: go to line of code?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    13

    go to line of code?

    I am still confused about something ? lol as usual,

    at the end of my program/game i have a button that when pressed will inevitably go to a line of code which is my Form1_load private sub. i dont know how to get this to work cheers.

    srry cant provide code
    My VB Code = Very Basic Code

  2. #2
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: go to line of code?

    I hope I understood what you mean. You don't have to go to a line of code, it is enough to call for it.
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.        Form1_load(any,params,you,might,have)
    4.  
    5.     End Sub
    VB 2005, Win Xp Pro sp2

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: go to line of code?

    You should absolutely NOT be directly calling your Load event handler. If you want to execute some code from the Click event handler of this Button then do so. If you want to execute the same code from the Load event handler then put it in a method of its own and call that method from both places. Do NOT call event handlers directly, especially something as specific as the Load event handler.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: go to line of code?

    Never had to do it so far, will keep it in mind, thx.
    VB 2005, Win Xp Pro sp2

  5. #5
    Addicted Member Gameunreal's Avatar
    Join Date
    Jun 2006
    Location
    gone fishing
    Posts
    249

    Re: go to line of code?

    Do NOT call event handlers directly, especially something as specific as the Load event handler.
    Um... but why not?

    cheers
    patrick
    -=PATRICK=-
    Using Visual Basic .NET 2005


    If you found a post useful then please Rate it!



    Hidden DOS secret: add BUGS=OFF to your CONFIG.SYS
    A program is a device used to convert data into error messages.
    Programmer's Drinking Song: 99 programming bugs in the code/99 programing bugs/Fix one bug/compile it again/now there's 100 bugs in the code! (repeat until bugs==0)
    All wiyht. Rho sritched mg kegtops awound?

  6. #6
    Fanatic Member dom_stapleton's Avatar
    Join Date
    Sep 2005
    Location
    Leigh-on-Sea, UK
    Posts
    665

    Re: go to line of code?

    Just out of curiosity, why is it bad practice to directly call an event handler?
    I use Microsoft Visual Basic 2008 Express Edition.

    If my post has been helpful, please rate it, unless you don't believe in Karma... which actually I don't!

    Resources:
    Visual Basic Tutorials (1, 2) | MSDN Library | Google | Krugle | Search Forums

    Free components:
    Windows Forms Components | XP Common Controls Library

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: go to line of code?

    Rather than calling event handlers, put the code into a sub, then call it from the handlers or anywhere else it needs to be called from. THe reason for not calling handlers directly is because of the Law of Unintended Concequences. Let's say you've got an event handler for the change event of a text box. And the event handler does stuff. Then from somewhere else in the code, you call the handler directly. Six months later you have to make a change to the handler for what ever reason, but it's not something you want changin for the code where you called it directly.... only you don't remember that it's called that way.... who knows what kind of reaction you'll get from it.

    -tg

    OG Tay sez, peace out!
    * 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??? *

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