Results 1 to 2 of 2

Thread: VB Dynamic streamwriter name from a file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2011
    Posts
    27

    VB Dynamic streamwriter name from a file

    building another command-line app and I need to generate a log file and write to it throughout the app's run, but the log needs to be named <work_order>_<device>.log - both of those are held in a text file and will change frequently.

    I can extract them no problem, and use them in the log file, but can't get the log file to use them in the name.

    so I have:

    Code:
                Using strDATA As New StreamReader(DATA_FILE)
                    Do While Not strDATA.EndOfStream
                        Dim eng As String() = Split(strDATA.ReadLine, "=")
    
                        Select Case eng(0)
                            Case "DEV" : DEVICE = eng(1)
                            Case "WOID" : WORK_ORDER = eng(1)
                            Case(...lots of other junk...)
                            Case Else
                        End Select
                    Loop
    
                    LOG = PATH & WORK_ORDER & "_" & DEVICE & ".log"
                    TMP = PATH & WORK_ORDER & "_" & DEVICE & ".tmp"
                    CSV = PATH & WORK_ORDER & "_" & DEVICE & ".csv"
    
                    Static swMergeLog As StreamWriter = New StreamWriter(LOG)
    
                    ' WRITE LOG FILE HEADERS INTO NEW LOG: 
                    swMergeLog.WriteLine(vbCrLf & _
                                         "=====================================" & vbCrLf & _
                                         "WORK ORDER:  " & WORK_ORDER & vbCrLf & _
                                         "DEVICE NO:   " & DEVICE & vbCrLf & _
                                         "=====================================" & vbCrLf)
    
                End Using
    PATH and WORK_ORDER are declared as Public earlier on as are PATH, LOG, TMP and CSV, this sub is also Public. I also need to use the log writer in other subs as well as WORK_ORDER and DEVICE. Using Static doesn't work, so I'm a bit stumped. Can anyone assist?

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jul 2011
    Posts
    27

    Re: VB Dynamic streamwriter name from a file

    I've found a solution but not sure if it's the solution. I'm splitting out PATH & WORK_ORDER & "_" & DEVICE to a separate variable called TARGET then passing that as an argument to the other subs and that seems to work ok, then using a new streamwriter to append to TARGET & ".log" and so on....

    Is this ok or is there a better way?

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