Results 1 to 5 of 5

Thread: [RESOLVED] Better way to code this as String?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    113

    Resolved [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

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Last edited by LaVolpe; Sep 13th, 2009 at 09:05 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    113

    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!

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: [RESOLVED] Better way to code this as String?

    vbNewLine is faster than vbCrLf

    http://www.aivosto.com/vbtips/stringopt.html

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2009
    Posts
    113

    Re: [RESOLVED] Better way to code this as String?

    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!

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