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 ??????
Printable View
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 ??????
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.
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
Take a look at this FAQ/Tutorial regarding the registry
it's gonna be better if i have just the code :D
But you'll learn more if you actually do some work yourself.
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"
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
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
That's what i need
thank's alot