hexagon logo

Writing/Reading a .txt file

This is very much a VB question not related to PC-DMIS. There is so much information out there for VB that I find it very hard to locate a good example of what I want to do.

I have a script at the beginning and end of my part program. I would like to get the total runtime of the program. I have a way to get systemtime in each and put it into seconds and such, thanks to this message board.

I do not want to write the beginning time to a variable and have it go through the part program. What I wanted was a temporary .txt file or something similar that I could write the begintime value (in seconds) to. The second script would grab this value and use it. The .txt file either needs to be cleared or overwritten by the new begintime number every execution. How do I code this?

My goal is to take these values and use them to calculate CMM run time for the day in Excel. Can I export the Total Runtime number I get in the second script to Excel? It will probably be easier to google information for this; I will update this post if I find what I am looking for.

Thanks!
Parents
  • I was having trouble getting any of these to work for me, so I wrote this up yesterday:


    Sub Main()
    
    Dim Beforetime As String
    Beforetime = Timer
    Beforetime = CInt(Beforetime)
    
    Open "I:\CMM_MASTER_PROGRAMS\Scripts\TIMEVARIABLE.TXT" For Output As #1
    Print #1, Beforetime
    Close #1
    
    End Sub


    The Timer object grabs the number of seconds since midnight. Simpler than grabbing system time in 3 different ways and converting it. CInt() rounds the time, because it goes to 2 decimal places in the value it puts out. Opening and writing to the .txt file in this method overwrites the file contents every time, so second problem solved.

    So now I have a simple way of getting program run time. I can grab date, and program name easy enough. Somehow I now have to get all these values into an excel file and make some pretty charts and graphs out of it. I have the Excel help files open now.....
Reply
  • I was having trouble getting any of these to work for me, so I wrote this up yesterday:


    Sub Main()
    
    Dim Beforetime As String
    Beforetime = Timer
    Beforetime = CInt(Beforetime)
    
    Open "I:\CMM_MASTER_PROGRAMS\Scripts\TIMEVARIABLE.TXT" For Output As #1
    Print #1, Beforetime
    Close #1
    
    End Sub


    The Timer object grabs the number of seconds since midnight. Simpler than grabbing system time in 3 different ways and converting it. CInt() rounds the time, because it goes to 2 decimal places in the value it puts out. Opening and writing to the .txt file in this method overwrites the file contents every time, so second problem solved.

    So now I have a simple way of getting program run time. I can grab date, and program name easy enough. Somehow I now have to get all these values into an excel file and make some pretty charts and graphs out of it. I have the Excel help files open now.....
Children
No Data