Results 1 to 4 of 4
  1. #1
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108

    [TUT] SaveSettings/My.Settings - Program Starts

    This is basically what y'all know. However since someone asked this question I'm going to do a quick tutorial about it.

    We want to get the number of times our program has been started.

    Like on 1st program startup you get a messagebox and on further program startups you won't.

    There are a lot of differernt ways, but I'm going to show you two ways:

    My.Settings and SaveSettings(Registry)

    Let us start =D

    Start a new project as usually...



    My.Settings

    Go into your Solution-Explorer > Righ***1ck on your project > Properties



    Now, click on "Settings" and simply edit the first line and use an Integer, hit enter afterwards. Name it to whatever you want, I named it "starts"



    Now, we can actually use this integer.

    Doubleclick on your Form so you will see the source code:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    On program startup(Form1_Load) we want to read the current starts and add 1 since it recently has been started.

    We declare an Integer adove form_load to read the setting.

    Code:
    Public Class Form1
    
      Dim i as integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    Moving on, we will now read the setting.

    Code:
    i = My.Settings.starts
    Now, i contains the current program startups.

    Code:
    i += 1
    Adding 1 to the current startups.

    Saving the settings

    Code:
    My.Settings.starts = i
    My.Settings.Save
    My.Settings.Reload
    Obviously self-explaining.

    What you can do is:

    Code:
    If i = 1 Then
    Msgbox("This is the first time you started this program")
    End if
    All in all it is..

    Code:
    Public Class Form1
    
      Dim i as integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           i = my.settings.starts
       If i = 1 Then
       Msgbox("This is the first time you started this program")
       End if
    
    
           i += 1
    
    My.Settings.starts = i
    My.Settings.Save
    My.Settings.Reload
           
        End Sub
    End Class
    However, if you know move your .exe to another path the settings will reset. To avoid this, we can use the registry.

    SaveSettings(Registry)

    Code:
    GetSetting(appname as string, section as string, key as string, settings as string )
    
    SaveSetting(appname as string, section as string, key as string, settings as string )
    ->

    Code:
    Public Class Form1
    
      Dim i as integer
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    i = GetSetting(Application.ProductName, "Settings", "Startups", i)
    
    If i = 1 Then
    Msgbox("whatever")
    End if
    
    i += 1
    
    SaveSetting(Application.ProductName, "Settings", "Startups", i)
    
    End Sub
    End Class
    You may also use a streamwriter/reader but this is the worst way IMO

    Enjoy =D
    Last edited by Blubb1337; 05-05-2010 at 07:21 AM.



  2. The Following User Says Thank You to Blubb1337 For This Useful Post:

    MvRouC12 (05-05-2010)

  3. #2
    MvRouC12's Avatar
    Join Date
    Feb 2010
    Gender
    male
    Location
    Stalking Choobs
    Posts
    1,690
    Reputation
    13
    Thanks
    246
    My Mood
    Amused
    Thanks lol (Your the 4th one to get one from me.)

    I wasn't expecting you to write a full tut on how to do it. ^_^

    [IMG]https://i986.photobucke*****m/albums/ae345/TripleSixPf/Okami-MvRouC12.jpg[/IMG]
    Quote Originally Posted by m_t_h View Post


    By stop playing AVA untill brasilian server comes.

    Do you guys really need to ruin EVERY game?
    [IMG]https://i175.photobucke*****m/albums/w148/Guitarman1157/dontforget.gif[/IMG]

  4. #3
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    =D Your welcome.



  5. #4
    NextGen1's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    Not sure really.
    Posts
    6,312
    Reputation
    382
    Thanks
    3,019
    My Mood
    Amazed
    Yay, another one

    Just kidding, Looks good thanks


     


     


     



    The Most complete application MPGH will ever offer - 68%




Similar Threads

  1. [TuT] Save/Retrieve settings from .ini [Need critiques]
    By Jason in forum Visual Basic Programming
    Replies: 5
    Last Post: 07-01-2010, 01:25 AM
  2. [TUT] Save Custom Settings
    By Ugleh in forum Visual Basic Programming
    Replies: 4
    Last Post: 01-13-2010, 03:09 PM
  3. Tut How To Set Up Mpgh.Net Publics
    By Cheesesong in forum CrossFire Hacks & Cheats
    Replies: 10
    Last Post: 07-28-2009, 10:12 AM
  4. [TUT] How to set ddd555 Aimbot if you don't have chams!
    By joi121 in forum Combat Arms Europe Hacks
    Replies: 30
    Last Post: 07-10-2009, 06:00 AM
  5. [Tut] How to set your own chams
    By Diisasta in forum CrossFire Hacks & Cheats
    Replies: 53
    Last Post: 06-20-2009, 07:46 AM