Results 1 to 15 of 15

Thread: [RESOLVED] Form Opening

  1. #1

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Resolved [RESOLVED] Form Opening

    How can i know how many times the user open my form and how can i know if the user open it for the first time ??????

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Form Opening

    You have to implement a counter mechanism that will increment each time it is loaded (Load event) but you have to save it somewhere so it remember is when the application is closed. Maybe in the registry or in a file.

  3. #3

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Form Opening

    Quote Originally Posted by baja_yu View Post
    You have to implement a counter mechanism that will increment each time it is loaded (Load event) but you have to save it somewhere so it remember is when the application is closed. Maybe in the registry or in a file.
    How can i save it in registry or a hidden file that is save the value where the program is

  4. #4
    PowerPoster
    Join Date
    Oct 2008
    Location
    Midwest Region, United States
    Posts
    3,574

    Re: Form Opening

    An example:

    Code:
    Option Explicit
    
    Private myCount As Integer
    
    Private Sub Form_Load()
        myCount = myCount + 1
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        SaveSetting appname:="MyApp", section:="TimesLoaded", _
                Key:="MainForm", setting:=myCount
    End Sub
    
    'to retrieve the value:
    
    'GetSetting appname := "MyApp", section := "TimesLoaded", _
                           key := "Mainform", default := 0

  5. #5

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Form Opening

    Quote Originally Posted by vbfbryce View Post
    An example:

    Code:
    Option Explicit
    
    Private myCount As Integer
    
    Private Sub Form_Load()
        myCount = myCount + 1
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        SaveSetting appname:="MyApp", section:="TimesLoaded", _
                Key:="MainForm", setting:=myCount
    End Sub
    
    'to retrieve the value:
    
    GetSetting appname := "MyApp", section := "TimesLoaded", _
                           key := "Mainform", default := 0
    i paste it and it's not work about getsetting where should put it i put it in the form load

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Form Opening

    Take a look at this FAQ/Tutorial regarding the registry
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Form Opening

    it's gonna be better if i have just the code

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Form Opening

    But you'll learn more if you actually do some work yourself.

  9. #9
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Form Opening

    Something to keep in mind when using the registry; Admin and standard users will get different values.
    to hide a file:
    Hide a file
    App.Path & ":myFile.dat"
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  10. #10

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Form Opening

    Quote Originally Posted by isnoend07 View Post
    Something to keep in mind when using the registry; Admin and standard users will get different values.
    to hide a file:
    Hide a file
    App.Path & ":myFile.dat
    i never see something like that btw this code not working
    invalid property assignment
    Last edited by Pc Monk; May 18th, 2010 at 04:32 PM.

  11. #11
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Form Opening

    Quote Originally Posted by Pc Monk View Post
    i never see something like that btw this code not working
    invalid property assignment
    Code:
    Dim fname As String
    Dim uses As Integer
    uses = 1
    fname = App.Path & ":mydata.dat"
     Open fname For Output As #1
            Print #1, uses
            Close #1
    
    
    Open the hidden file
    Dim fname As String
    Dim uses As String
    fname = App.Path & ":mydata.dat"
     Open fname For Input As #1
            Line Input #1, uses
            Close #1
            MsgBox uses
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  12. #12

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Re: Form Opening

    Quote Originally Posted by isnoend07 View Post
    Code:
    Dim fname As String
    Dim uses As Integer
    uses = 1
    fname = App.Path & ":mydata.dat"
     Open fname For Output As #1
            Print #1, uses
            Close #1
    
    
    Open the hidden file
    Dim fname As String
    Dim uses As String
    fname = App.Path & ":mydata.dat"
     Open fname For Input As #1
            Line Input #1, uses
            Close #1
            MsgBox uses
    Thank You for the code
    now how can i hide that file that i make it ???

  13. #13
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Form Opening

    Quote Originally Posted by Pc Monk View Post
    Thank You for the code
    now how can i hide that file that i make it ???
    After you run the code try to find the file
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  14. #14
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Form Opening

    This may help on what you are trying to do;
    Code:
    Const mMaxUses As Integer = 5
    
    
    Private Sub Command1_Click() 'save
    Dim fname As String
    Dim uses As Integer
    uses = 1
    fname = App.Path & ":xp32sys.sys"
     Open fname For Output As #1
            Print #1, uses
            Close #1
    End Sub
    
    Private Sub Command2_Click() 'open
    Dim fname As String
    Dim uses As String
    fname = App.Path & ":xp32sys.sys"
     Open fname For Input As #1
            Line Input #1, uses
            Close #1
            
            If Val(uses) >= mMaxUses Then
             MsgBox "You used the software the maximun times"
             Exit Sub
             End If
            If Val(uses) <> 0 Then
            AddAUse uses
            End If
    End Sub
    Sub AddAUse(uses)
    Dim fname As String
    Dim usesleft As Integer
    uses = uses + 1
    fname = App.Path & ":xp32sys.sys"
     Open fname For Output As #1
            Print #1, uses
            Close #1
            usesleft = mMaxUses - uses
            Me.Caption = "demo and uses left: " & usesleft
            MsgBox uses
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  15. #15

    Thread Starter
    Addicted Member Pc Monk's Avatar
    Join Date
    Feb 2010
    Posts
    188

    Resolved Re: Form Opening

    That's what i need
    thank's alot

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