Results 1 to 5 of 5

Thread: my. and sub main

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    3

    my. and sub main

    I am looking for information on disabling the “enable application framework” check box so my project can start from the main() sub. From what I have read unchecking that box disables being able to use my.whatever in your code. Most of the code I find has my.whatever in it (I get it makes things easier). My specifics are I am trying to learn vb2010 and have always used the getusername function in the sub main. I know I could probably put it in the form load, but I am trying to learn. When I uncheck the enable application framework check box - what do I have to do to reference things if I can't use my. ?

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

    Re: my. and sub main

    It's kind of a good idea to try things for yourself. If you had, you would have found that you could still use the My namespace with the the application framework disabled. Maybe there are specific features that are not available but, if so, I don't know what they are. if you do encounter something, ask about that specifically. I'm not sure what GetUserName function you're talking about. Is that a VB6 thing? What do you actually want to use the user name for? You can use Environment.UserName wherever you like. If you want to do something when the application starts up then you can simply leave the application framework enabled and handle the Startup event of the application. That is the intention. Disabling the application framework may be worthwhile in some cases but not usually.
    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

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

    Re: my. and sub main

    I would emphasize the suggestion that you not disable the application framework. What do you feel that will buy you? You can always use the Sub New of the startup form, or the Load event of the startup form, to perform any task that could otherwise be performed in a Sub Main(). Since leaving 2003, I have yet to find a situation where a Sub Main without the application framework was a superior solution for any forms project.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2012
    Posts
    3

    Re: my. and sub main

    OK, thanks. I am moving from 6 to 2010 and have been testing this for a week. I have always used sub main in 6 along with the getusername, which also works in 2005, 2008, as well as 2010 to get the logged in user name. It works fine with the application framework enabled, but disabling the application framework craps it out. I have not tried the sub new. I am using the form load of the startup form now. Guess it is one more thing I have to get used to in this version. Its not a show stopper.

    Thanks

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

    Re: my. and sub main

    Um, that's not "the" GetUserName function. That function is not part of the .NET Framework. That is an example of a function that you can write yourself that uses My.User internally. That GetUserName function couldn't possibly have worked in VB6, so it must have been a different GetUserName function. I don't know whether My.User doesn't work without the application framework enabled but, as I said, you can just use Environment.UserName to get the name of the logged on user. If your app is using custom authentication then I'm not sure that that will work, but I'm guessing that you're not using custom authentication.
    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

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