Jump to content

Run code on startup?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
Well, this has to be the absolutely dumbest question I've asked anywhere, but here goes.

How do I run a block of code as soon as I startup my application using VB .NET? I read that this would:

Private Sub Form_Load()

<code to be run>

End Sub

But it's most certainly not working. I've tried changing 'Form' to the name of the form, but that didn't work either. I've also Googled and searched through help files, but I'm still without luck.

Thanks for any help,
CheeseBurgerMan

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What are you trying to update on form_load? Are you using VS 2005/2003 or prior?

#3
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
I'm using Visual Studio 2005.

I'm trying to update the URL of my Webbrowser object. Here's the code I have


         'NOT WORKING: Goes to the home page and checks to see if the Navigation buttons are hidden.

    Private Sub Form_Load()

        'Goes to the homepage on startup

        WebBrowser1.Navigate(GetSetting("Googlr", "Settings", "Homepage"))

        'Shows or hides the navigation bar based on their position before the user closed the app.

        If GetSetting("Googlr", "Settings", "NavigationBar") = "hide" Then

            QuickBtns.Hide()

        ElseIf GetSetting("Googlr", "Settings", "NavigationBar") = "show" Then

            QuickBtns.Show()

        End If


    End Sub



#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You have an error in the way you retrieve your settings because this works fine:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 'Goes to the homepage on startup          WebBrowser1.Navigate("http://www.google.com")

        End If
    End Sub


#5
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
Here's the key part that Jordan has, and you don't:

Handles MyBase.Load


You need to subscribe to the event to get your Form_Load eventhandler to run.

#6
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
Thank you both very much. Everything is now working wonderfully. :D

#7
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
How did you get the Form_Load without the rest of the code CheeseBurgerMan?

#8
Guest_CheeseBurgerMan_*

Guest_CheeseBurgerMan_*
  • Guests
It was a web browser tutorial, previously high in the Google search results for 'web browser tutorial visual basic', but apparently not any longer. For now however, I can't seem to find it any longer. :( (and no, it's not in my history :p)