Results 1 to 10 of 10

Thread: Execute subroutine at startup

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Execute subroutine at startup

    I am trying to execute the "Data()" subroutine at startup. This did not work:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call Data()
    End Sub
    Is there a way to call the subroutine at the begining of debug?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Execute subroutine at startup

    What did not work about that call (though you don't ever need to use the Call word, it's a holdover that can be forgotten)? Did it not happen early enough? If that's the issue, then you can move the call earlier in the process, such as to the form constructor (which is not immediately obvious, but can be found in the .designer.vb file associated with the form).
    My usual boring signature: Nothing

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Execute subroutine at startup

    Can you explain what "did not work"? That is, tell us what your expected result is and what the actual outcome you have now.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Re: Execute subroutine at startup

    It should have made the call when the form was loaded.

  5. #5
    Member VB6 to Vb2010's Avatar
    Join Date
    Dec 2010
    Posts
    38

    Re: Execute subroutine at startup

    Put a breakpoint at Call Data()
    Use "Step Into" <F8> , What happens?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Re: Execute subroutine at startup

    I put a breakpoint at Call Data() then <F8>.

    No errors just Highlighted in YELLOW:

    Dim gphFormGraphics as Graphics = Me.CreateGraphics

  7. #7

    Re: Execute subroutine at startup

    Keep pressing F8.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2010
    Posts
    87

    Re: Execute subroutine at startup

    This just highlights the line. What to do next?

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

    Re: Execute subroutine at startup

    That line of code IS being executed. That I can guarantee. What may be happening is that the method you're calling is throwing an exception. In Windows 7, exceptions thrown in the Load event handler of the startup form are swallowed without obvious notification.

    You are obviously doing something wrong because you should basically NEVER be calling CreateGraphics. It's especially useless in the Load event handler because the form hasn't even been displayed yet, so anything you draw will never be seen.

    Please explain what you're actually trying to achieve. Showing us the contents of the is Data method would help also.

    Finally, "Data" is a very poor name for a method. Method names should be verb-based for a start, because they represent behaviour. Something like "GetData" would be more appropriate, but you might be able to come up with a better name still because you know what the method actually does.
    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

  10. #10
    Member VB6 to Vb2010's Avatar
    Join Date
    Dec 2010
    Posts
    38

    Re: Execute subroutine at startup

    Can you "Cut and Paste" us some of your code so we can get an idea of what you are doing?

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