[vb6] help with the basics.

Discussion in 'Code Snippets and Tutorials' started by Kaito, Apr 25, 2010.

  1. Kaito

    Kaito Level IV

    Joined:
    Jun 29, 2007
    Messages:
    2,692
    Likes Received:
    15
    [​IMG]


    If i wanted my program to calculate the period difference between two dates, how can i utilize what's shown below, to write the code?






    what does this statement mean?

    Call SaveSetting("Name Of Your Program", "Neopets Login", "Neopets Username", txtUsername.Text)

    if you're just saving the settings of the username (txtUsername.Text), why would you need the first part, i.e. "Name Of Your Program", "Neopets Login", "Neopets Username",







    Private Sub Form_Load()
    chkSave.Value = GetSetting("Name Of Your Program", "Neopets Login", "Save Login Information", Checked)

    If chkSave.Value = Checked Then
    txtUsername.Text = GetSetting("Name Of Your Program", "Neopets Login", "Neopets Username")
    txtPassword.Text = GetSetting("Name Of Your Program", "Neopets Login", "Neopets Password")
    End If
    End Sub

    why do you need the line in red? Why not when the form loads, just check whether the chkSave.Value is checked, and work from there on?



    thanks.
     
  2. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    using "SaveSetting" will create a registery key with the information you provided.
    That's a good way of saving setting in a program instead of creating an external file that might get lost somewhere. The registery is always at the same place.

    Now, even if you're only saving the username field, you can specify where you want to save it.
    Let's say I have 10 programs that all can remember the username. if you simply put username.text, every programs will show the same value. By specifying the program name, you can assign a registery key for each program.

    So this line "Call SaveSetting("Name Of Your Program", "Neopets Login", "Neopets Username", txtUsername.Text)" will create a key named "Neopets Username", witch will store the content of txtUsername.Text, under the subfolder "Neopets Login", under the folder "Name Of Your Program".

    You can than use the function "GetSettings" to access this key to get the content of it.

    Next, the line in red will check if the checkbox chkValue was check the last time the program was closed.
    If it was checked, it will check it again so the next part of the code will get the content of from "Neopets Username" and "Neopets Password". Since this line is in the Form_Load, it will do so at the opening of the program, thus filling all the needed field at the same time.
     
  3. Kaito

    Kaito Level IV

    Joined:
    Jun 29, 2007
    Messages:
    2,692
    Likes Received:
    15
    thanks alot for the detailed explanation tharoux, will be slowly reading through it, and trying to understand :)
     
  4. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Just google "Call savesettings"
    you should get plenty of web site ;)
     
  5. Kaito

    Kaito Level IV

    Joined:
    Jun 29, 2007
    Messages:
    2,692
    Likes Received:
    15
    hmmm alright thanks ^_^

    do you have any recommended (video) tutorials that i should follow? cause now i've two sources of tutorials, and might be looking for more (more never hurt right?)
     
  6. tharoux

    tharoux Level IV

    Joined:
    Dec 30, 2006
    Messages:
    2,733
    Likes Received:
    126
    Location:
    In front of my PC, Montreal
    Nope sorry. Trial/errors + google search does it for me.
     
  7. Lightning

    Lightning Administrator
    Staff Member

    Joined:
    Nov 8, 2008
    Messages:
    3,021
    Likes Received:
    195
    Gender:
    Male
    Location:
    Florida, USA
  8. Kaito

    Kaito Level IV

    Joined:
    Jun 29, 2007
    Messages:
    2,692
    Likes Received:
    15
    Code (Text):
    1. Private Sub cmdLogin_Click()
    2. cmdLogin.Enabled = False
    3.  
    4. If chkSave.Value = Checked Then
    5.     Call SaveSetting("Name Of Your Program", "Neopets Login", "Neopets Username", txtUsername.Text)
    6.     Call SaveSetting("Name Of Your Program", "Neopets Login", "Neopets Password",  txtPassword.Text )
    7.     Call SaveSetting("Name Of Your Program", "Neopets Login", "Save Login Information", chkSave.Value)
    8.  Else
    9. Call SaveSetting("Name Of Your Program", "Neopets Login", "Save Login Information", chkSave.Value)

    If box is not checked, what happens? why is there this line present, which is the same as the 3rd line from above.
    Code (Text):
    1.  
    2. End If
    3.  
    4. cmdLogin.Enabled = True
    why is the above so strangely located? It’s just below cmdLogin.Enabled = False, how will the program know when to enable login and disable login?
    Code (Text):
    1. End Sub

    questions are in reference to the line directly above it.