Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
# I want to add .hl7 extension to the file name and am using timestamp for file name, I have no idea how to proceed

VB
Private Sub HL_Click(sender As Object, e As EventArgs) Handles HL.Click

        Dim file As System.IO.StreamWriter
        Dim fileDateTime As String = DateTime.Now.ToString("yyyyMMdd") & "" & DateTime.Now.ToString("HHmmss")
        file = My.Computer.FileSystem.OpenTextFileWriter(fileDateTime, True)

            file.WriteLine("MSH|^~\&|||||" & TxtExamtime.Text & "||ORM^O01||P|2.3.1")
            file.WriteLine("PID|||" & TxtId.Text & "||" & TxtFamilyname.Text & "^" & TxtGivenname.Text & "||" & TxtDob.Text & "||" & TxtGender.Text & "|||" & TxtStreet.Text & " " & TxtHouse.Text & "^^" & TxtCity.Text & "^^" & TxtPostcode.Text)
            file.WriteLine("PV1||O|||||||||||||||||" & TxtId.Text & "|||||||||||||||||||||||||" & TxtExamdate.Text)
            file.WriteLine("ORC|NW|" & TxtId.Text & "|||||^^^" & TxtExamdate.Text & "||" & TxtExamdate.Text)
            file.WriteLine("OBR||" & TxtExamdate.Text & TxtExamdate.Text & "||CT|||" & TxtExamtime.Text & "|" & TxtExamtime.Text)
            file.WriteLine()

        file.Close()
        MessageBox.Show("Textsaved to " & fileDateTime)
    End Sub
Posted
Comments
Andy Lanng 27-May-15 4:37am    
From your question RE: renaming the file, the above code is not relevant. Is that correct?
It looks like the file exists. Then you open it to write to it. Renaming the file is not part of this process.
After you close the file you should use "My.Computer.FileSystem.RenameFile"
Leo Chapiro 27-May-15 4:48am    
No, Andy: IMHO the OpenTextFileWriter() gets the name of the file as parameter. We need to add the extension before we call this method !
Andy Lanng 27-May-15 4:51am    
You're saying that OpenTextFileWriter() can dictate the name of the file? Ok. I was not aware of that. Fair cop, guv ^_^

1 solution

Try this:

VB
' ...
Dim fileDateTime As String = DateTime.Now.ToString("yyyyMMdd") & DateTime.Now.ToString("HHmmss") & ".hl7"
' ...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900