• text file parse (vba)

    • This topic has 16 replies, 3 voices, and was last updated 21 years ago.
    Author
    Topic
    #404030

    Hi,
    I have some textfiles to pick apart, and I could use a little help. After cleaning out the garbage characters, I am inserting a delimiter ( ` ) at the beginning of each string of text I want to read and then write it to a single line in a new text file. The string I want to keep varies in length.

    Essentially, I want to read the file character by character, and when hitting the delimiter, begin writing into a new file until hitting the delimiter again, then do a vbcrlf and write and so on…

    Any help is greatly appreciated.

    Thanks,
    Dave P.

    Viewing 3 reply threads
    Author
    Replies
    • #818910

      Is this file especially large? If it simply needs to be carved up based on a delimer, you could try creating a massive array of strings using the Split() method. (You need VBA 6.0 or higher, e.g., Office 2000 or higher.)

      Regarding the general mechanics of reading and writing files, the old “Basic” methods are okay, but the newer FileSystemObject methods are more full-featured. If you search this board for FileSystemObject you should find numerous snippets for reference, as well as links into the documentation on MSDN.

      • #820281

        Thank you, JS…
        I have used Split(), and some serious string manipulation to accomplish what I needed. (sloppy, but it works)

        Thanks again,
        Dave P.

      • #820282

        Thank you, JS…
        I have used Split(), and some serious string manipulation to accomplish what I needed. (sloppy, but it works)

        Thanks again,
        Dave P.

    • #818911

      Is this file especially large? If it simply needs to be carved up based on a delimer, you could try creating a massive array of strings using the Split() method. (You need VBA 6.0 or higher, e.g., Office 2000 or higher.)

      Regarding the general mechanics of reading and writing files, the old “Basic” methods are okay, but the newer FileSystemObject methods are more full-featured. If you search this board for FileSystemObject you should find numerous snippets for reference, as well as links into the documentation on MSDN.

    • #820389

      > and when hitting the delimiter, begin writing into a new file

      I do a lot of string parsing, and the attached file might give you some ideas. (strSplitAt, strSplitStringAt, strStripRight, strStripEnds)

      Paste the code into a template, drag out the commented TEST macro at the foot of a fucntion, de-comment it, then step through it to watch it work.

      As a programming practice, I try to generate internal delimited strings with the delimiter as the FIRST character, so that I can determine the delimiter character on-the-fly:

      Dim strDelim As String
      strDelim = Left$(strIn, 1)
      
      • #821330

        Thanks Chris,

        I’ll use these ideas to clean things up in the code. these files are as ugly as it gets, of course. Another issue I have is batch faxing with MS SBServer 2000. Have you any experience with this?

        Thanks again,
        Dave P.

        • #821389

          > these files are as ugly as it gets

          Oh! We are working for the same client; let’s meet in the cafeteria (grin!, and I really DO love my clients).

          > batch faxing with MS SBServer
          Not yet!

          I have devised various schemes for batch processing over the years, just not in MS SBS server. I’m keen on anything that reduces work and errors while maintaining the flow of money. I have written code to batch fax data to and from fax packages such as QuickLinkII. What’s the nature of the problem?

          • #821429

            Gotta love clients! If it weren’t for them, I’d have to only work 40 hrs a week….

            Faxing – my current project is 7 local workstations hitting on a server (sbs2000) and 1 remote station doing a VPN over broadband (which works better than I thought). All will be using an access app linked to a tables only access db. Each station needs to fax reports to one or more fax numbers. I’m trying to bypass the wizard so a user can choose one to five names and fax the report they are viewing. This would loop and go into the fax que and then it would send until it is done.

            I’ve been trying the attached code on the server alone and it hangs at the “send” command and does not even initiate the modem. Any thoughts on this?

            Thanks,
            Dave P.

            • #822733

              > hangs at the “send” command and does not even initiate the modem

              I have, as yet, no experience in sending directly to fax. I thought that a solution might be to print-to-fax. Here’s a recorded macro of me printing a page and sending it to the fax-as-printer.

              It’s not enough; obviously I need to communicate a telephone number, name, contact etc, just as I would when using an emailer.

              I do send email from Word documents through Outlook and Eudora; how much more difficult can faxing be?
              I’ll try to take a look at it this week.

              Sub Macro1()
              '
              ' Macro1 Macro
              ' Macro recorded 05/03/04 by Christopher Greaves
              '
                  ActivePrinter = "Quick Link II Fax"
                  Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
                      wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
                      Collate:=True, Background:=True, PrintToFile:=False
              End Sub
              
            • #823092

              I’ve automated emails as well, but this seems to be a new beast. I’m spending a good deal of time on it this week, and will let you know. Thank you,
              Dave P.

            • #823093

              I’ve automated emails as well, but this seems to be a new beast. I’m spending a good deal of time on it this week, and will let you know. Thank you,
              Dave P.

            • #822734

              > hangs at the “send” command and does not even initiate the modem

              I have, as yet, no experience in sending directly to fax. I thought that a solution might be to print-to-fax. Here’s a recorded macro of me printing a page and sending it to the fax-as-printer.

              It’s not enough; obviously I need to communicate a telephone number, name, contact etc, just as I would when using an emailer.

              I do send email from Word documents through Outlook and Eudora; how much more difficult can faxing be?
              I’ll try to take a look at it this week.

              Sub Macro1()
              '
              ' Macro1 Macro
              ' Macro recorded 05/03/04 by Christopher Greaves
              '
                  ActivePrinter = "Quick Link II Fax"
                  Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
                      wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
                      Collate:=True, Background:=True, PrintToFile:=False
              End Sub
              
          • #821430

            Gotta love clients! If it weren’t for them, I’d have to only work 40 hrs a week….

            Faxing – my current project is 7 local workstations hitting on a server (sbs2000) and 1 remote station doing a VPN over broadband (which works better than I thought). All will be using an access app linked to a tables only access db. Each station needs to fax reports to one or more fax numbers. I’m trying to bypass the wizard so a user can choose one to five names and fax the report they are viewing. This would loop and go into the fax que and then it would send until it is done.

            I’ve been trying the attached code on the server alone and it hangs at the “send” command and does not even initiate the modem. Any thoughts on this?

            Thanks,
            Dave P.

        • #821390

          > these files are as ugly as it gets

          Oh! We are working for the same client; let’s meet in the cafeteria (grin!, and I really DO love my clients).

          > batch faxing with MS SBServer
          Not yet!

          I have devised various schemes for batch processing over the years, just not in MS SBS server. I’m keen on anything that reduces work and errors while maintaining the flow of money. I have written code to batch fax data to and from fax packages such as QuickLinkII. What’s the nature of the problem?

      • #821331

        Thanks Chris,

        I’ll use these ideas to clean things up in the code. these files are as ugly as it gets, of course. Another issue I have is batch faxing with MS SBServer 2000. Have you any experience with this?

        Thanks again,
        Dave P.

    • #820390

      > and when hitting the delimiter, begin writing into a new file

      I do a lot of string parsing, and the attached file might give you some ideas. (strSplitAt, strSplitStringAt, strStripRight, strStripEnds)

      Paste the code into a template, drag out the commented TEST macro at the foot of a fucntion, de-comment it, then step through it to watch it work.

      As a programming practice, I try to generate internal delimited strings with the delimiter as the FIRST character, so that I can determine the delimiter character on-the-fly:

      Dim strDelim As String
      strDelim = Left$(strIn, 1)
      
    Viewing 3 reply threads
    Reply To: text file parse (vba)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: