Adding a counter to a macro
Adding a counter to a macro
(OP)
Adding a counter to a macro is a easy way to find out how useful
your macro is to others. You can even put in hidden comments like
owing you a coffee after so many uses.
I also like to be able to find out what users use it.
Can you tell me how to get the users id name.
'****************************************************************************
Dim path As String
Dim filename As String
Dim scrpt As String
Dim objFSO, objReadFile, contents
Dim ccontents As String
On Error Resume Next
path = "c:\temp\" 'location of file
filename = "test.txt" 'add text name
scrpt = "test" 'name of macro
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile(path & filename, 1, False)
ccontents = objReadFile.ReadAll
If ccontents = "" Then
ccontents = 0
End If
ccontents = ccontents + 1
mut = Round(ccontents / 25)
If ccontents = 100 Then
MsgBox "You have use " & scrpt & " " & ccontents & "times you must really like this program."
ElseIf ccontents = 1 Then
MsgBox "Thank you for trying " & scrpt & " I hope you enjoy this program."
ElseIf ccontents = 25 * mut Then
MsgBox "You have use " & scrpt & " " & ccontents & "times. I think you owe me a coffee"
End If
Set Datos = CATIA.fileSystem.CreateFile(path & filename, True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
ostream.Write ccontents & Chr(10)
ostream.Close
'****************************************************************************
your macro is to others. You can even put in hidden comments like
owing you a coffee after so many uses.
I also like to be able to find out what users use it.
Can you tell me how to get the users id name.
'****************************************************************************
Dim path As String
Dim filename As String
Dim scrpt As String
Dim objFSO, objReadFile, contents
Dim ccontents As String
On Error Resume Next
path = "c:\temp\" 'location of file
filename = "test.txt" 'add text name
scrpt = "test" 'name of macro
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile(path & filename, 1, False)
ccontents = objReadFile.ReadAll
If ccontents = "" Then
ccontents = 0
End If
ccontents = ccontents + 1
mut = Round(ccontents / 25)
If ccontents = 100 Then
MsgBox "You have use " & scrpt & " " & ccontents & "times you must really like this program."
ElseIf ccontents = 1 Then
MsgBox "Thank you for trying " & scrpt & " I hope you enjoy this program."
ElseIf ccontents = 25 * mut Then
MsgBox "You have use " & scrpt & " " & ccontents & "times. I think you owe me a coffee"
End If
Set Datos = CATIA.fileSystem.CreateFile(path & filename, True)
Set ostream = Datos.OpenAsTextStream("ForAppending")
ostream.Write ccontents & Chr(10)
ostream.Close
'****************************************************************************





RE: Adding a counter to a macro
You can get few additional data using Set objNet = CreateObject("WScript.NetWork") . Bellow is just an example how it can be used, I'm sure you can adapt code to your needs.
' ======================================================
' Purpose: CATScript will create Date, Time and User parameters in an active CATPart
' Usage: 1 - A CATPart must be active
' 2 - Run macro
' Author: ferdo (Disclaimer: You use this code at your own risk)
' ======================================================
Sub CATMain()
Dim oParams As Parameters
Set oParams = CATIA.ActiveDocument.Part.Parameters
Set objNet = CreateObject("WScript.NetWork")
oParams.CreateString "Date",Day(Date)&"/"&Month(Date)&"/"&Year(Date)
oParams.CreateString "Time",Time
oParams.CreateString "User", objNet.UserName
End Sub
or (just another example)
Sub CATMain()
Dim objNet
Set objNet = CreateObject("WScript.NetWork")
MsgBox objNet.UserName ' User
MsgBox objNet.UserDomain 'Domain
MsgBox objNet.ComputerName 'Computer
End Sub
Regards
Fernando
https://picasaweb.google.com/102257836106335725208
RE: Adding a counter to a macro
RE: Adding a counter to a macro
Regards
Fernando
https://picasaweb.google.com/102257836106335725208