Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Sub Main()

Sub Main()

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    OldDog Net
    wrote on last edited by
    #1

    Hi, I'm a C# type that just landed a VB.Net assignment and I'm having trouble getting a handle on Sub Main in VB.Net. The folks at the new place don't use Main while all the examples in documentation seem to. Evidently it's optional and not very VB6. Where does control get passed to if there isn't one? Also, every example that I've seen places Main() in a Module, not a Class. Is that important or does it just default it to Public? Thanks in advance.

    J 1 Reply Last reply
    0
    • O OldDog Net

      Hi, I'm a C# type that just landed a VB.Net assignment and I'm having trouble getting a handle on Sub Main in VB.Net. The folks at the new place don't use Main while all the examples in documentation seem to. Evidently it's optional and not very VB6. Where does control get passed to if there isn't one? Also, every example that I've seen places Main() in a Module, not a Class. Is that important or does it just default it to Public? Thanks in advance.

      J Offline
      J Offline
      Joshua Quick
      wrote on last edited by
      #2

      You're right. The Main() function is optional in VB. You can set the app's "startup object" via Project Properties. 1) Go to the Solution Explorer. 2) Right click the project and select Properties. 3) Select CommonProperties\General in the tree. 4) Select the Startup Object and click OK. (Choose "Sub Main" if you want it to call your Main() function.) You can place the Main() anywhere you want. In a Module or in a Class. It must be defined as Public and Shared (ie: static), just like how you would do it in C#.

      Public Class Main
      Public Shared Sub Main(ByVal CmdArgs() As String)
      End Sub
      End Class

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups