Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
# Am getting an error as FormatException was unhandled in the second line of code
here is my code:
VB
Private Sub HL_Click(sender As Object, e As EventArgs) Handles HL.Click
        TxtDob.Text = Date.Now.ToString("ddMMyyyy")
        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
ZurdoDev 26-May-15 10:26am    
It should be DateTime.Now, not Date.Now, right?
Shaik Izaz 26-May-15 10:30am    
I tried DateTime.Now also its giving the same error
ZurdoDev 26-May-15 10:32am    
DateTime.Now.ToString("ddMMyyyy") is perfectly valid. Are you sure that's the line giving you the error?
Shaik Izaz 26-May-15 10:37am    
yeah,Its on the same line. Is there any other method to save the DATE as 18091989 instead of 18 SEP 1989
ZurdoDev 26-May-15 10:42am    
What version of .net is your project target set to?
Also, what's the full error message?

1 solution

As discussed in the comments, you were able to get it to work with the following code:
VB
TxtDob.Format = DateTimePickerFormat.Custom
TxtDob.CustomFormat = "ddMMyyyy"
 
Share this answer
 

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