[RESOLVED] Better way to code this as String?
Is there a better way to code this?
Code:
strLog = strLog & "Date/Time: " & Format$(Now, "hh:mm:ss d-mmm-yyyy") & vbCrLf
strLog = strLog & "App: " & MainApp.Title & vbCrLf
strLog = strLog & "Version: " & MainApp.Major & "." & Format$(MainApp.Minor, "00") & "." & Format$(MainApp.Revision, "000") & vbCrLf
strLog = strLog & "Error Number: " & lngNumber & vbCrLf
strLog = strLog & "Error Desc: " & strDescription & vbCrLf
Re: Better way to code this as String?
First, there is nothing incorrect or improper with the way you have coded and built your string.
The following can be used. But don't get carried away with line continuations as I used below. There is a max per string (I forget how many), and you don't want to overload them with a bunch of complicated calculations as that may actually make it harder for you to read:
Code:
strLog = strLog & "Date/Time: " & Format$(Now, "hh:mm:ss d-mmm-yyyy") & vbCrLf & _
"App: " & MainApp.Title & vbCrLf & _
"Version: " & MainApp.Major & "." & Format$(MainApp.Minor, "00") & "." & Format$(MainApp.Revision, "000") & vbCrLf & _
"Error Number: " & lngNumber & vbCrLf & _
"Error Desc: " & strDescription & vbCrLf
Edited: If this string is actually going to be printed to a file within the same routine, it would be more proper to print each line vs building the string and printing it later:
Code:
Print #FileNr, "Date/Time: " & Format$(Now, "hh:mm:ss d-mmm-yyyy")
Print #FileNr, "App: " & MainApp.Title
Print #FileNr, "Version: " & MainApp.Major & "." & Format$(MainApp.Minor, "00") & "." & Format$(MainApp.Revision, "000")
Print #FileNr, "Error Number: " & lngNumber
Print #FileNr, "Error Desc: " & strDescription
Re: Better way to code this as String?
Ah I see, that's exactly what I was planning to do! Thanks for the help and advice!
Re: [RESOLVED] Better way to code this as String?
Re: [RESOLVED] Better way to code this as String?
Quote:
vbNewLine is faster than vbCrLf
Thanks that's nice to know although i'm using LaVolpes advice and printing it all out to a file separately i still used vbCrLf in other parts on my code so have changed this now!