×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Adding a counter to a macro
2

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
'****************************************************************************



RE: Adding a counter to a macro

Hi,

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

(OP)
Thanks ferdo thats what I was looking for.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources