Results 1 to 19 of 19

Thread: * RESOLVED * Notepad vs. Wordpad

  1. #1

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186

    * RESOLVED * Notepad vs. Wordpad

    You know how you can open a file in Notepad and it will display those square characters that are supposed to be carriage returns? Well Wordpad properly formats these characters. However, when I try to open this type of file as Input in Visual Basic, it doesn't recognize those characters just like Notepad. I'd like my Input statement to act like Wordpad does and recognize those special characters. Anyone know how to do that?
    Here's the code:
    VB Code:
    1. Open .FileName For Input As #1
    2. Do While Not EOF(1)
    3. Input #1, lineArray(i)
    4.    i = i + 1
    5. Loop
    Last edited by run_GMoney; Mar 2nd, 2004 at 05:03 PM.
    Place Your VBForums Ad Here

  2. #2
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    First try using the Asc function to check what those 'boxes' actually are

  3. #3

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    The boxes are carriage returns. I know this because Wordpad properly recognizes them.
    Place Your VBForums Ad Here

  4. #4
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    So what is your problem?
    What happens during your Input loop?

  5. #5

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    See the screenie for the problem. I'd like to store each line of the text file into an array. But visual basic is seeing one line the same way that Notepad sees one line. I need VB to understand 1 line the way that Wordpad does. Is that a bit more clear as to what my problem is?
    Place Your VBForums Ad Here

  6. #6

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Forgot to attach. Here it is
    Attached Images Attached Images  
    Place Your VBForums Ad Here

  7. #7
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    How about using the split function
    VB Code:
    1. strOutput = Split(strNotepad, vbCrLf)
    Then reading back from the array?

  8. #8
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Try:

    Line Input#1, linearray(i)

    or better yet

    Open .... as #1
    Data = Input(Lof(1),1)

    Lines = Split(Data,vbCrLf)

    if that does not work...using Asc like suggested above...check see if maybe its just Cr or Lf (Usually a vbCrLF is 2 Boxes)

    so either split(Data,vbCr) <-Most likely
    or Split(Data,vbLf)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Looks like I am going to have to check the Asc value. How do I go about using that function?
    Place Your VBForums Ad Here

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    You know, if you use Line Input #1 instead of just Input #1, it *might* work....

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    VB Code:
    1. Dim strTest As String
    2.  
    3. strTest = vbCrLf
    4.  
    5. Debug.Print Asc(strTest)

  12. #12

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    But how can that help me determine what the square character is my file? Because that's what I need to find out.
    Place Your VBForums Ad Here

  13. #13
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Try what techgnome said first
    If that doesnt work then try the Asc function.

    What I put above was just an example, I thought you could
    adapt it to your own situation.

    Try
    VB Code:
    1. Open .FileName For Input As #1
    2. Do While Not EOF(1)
    3. Input #1, lineArray(i)
    4. Debug.Print Asc(lineArray(i))
    5. Debug.Print lineArray(i)  
    6. i = i + 1
    7. Loop

  14. #14
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    open it in notepad to see the box..

    Select the box and copy it

    in vb msgbox Asc("Past Box Here")
    then run it

    if its one box..it should be CR (Asc 13)
    if not then its LF (Asc 10)

    if its 2 boxes then its vbCrLf or Chr$(13) & chr$(10)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  15. #15

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Here's the actual file. Maybe that will help. When I copied and pasted that square into VB, it just started a new line. Wouldn't copy the actual character.
    Attached Files Attached Files
    Place Your VBForums Ad Here

  16. #16
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Inbetween "Frontal w/ Revo" and "800.000 -3.261" you have
    the following characters:
    13, 32 (27 times), 13, 10, 32

    13 is Carriage Return
    10 is Line Feed
    32 is Space

  17. #17

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Well, here's my latest code (thanks to Jamie's File I/O Tutorial).
    VB Code:
    1. Dim strArray() As String
    2.  
    3.     With cdlFiles
    4.         .DialogTitle = "Open File"
    5.         .Flags = cdlOFNFileMustExist + cdlOFNPathMustExist
    6.         .ShowOpen
    7.         Open .FileName For Input As #1
    8.             strArray = Split(Input(LOF(1), 1), Chr$(13))
    9.         Close #1
    10.         lblInput.Caption = cdlFiles.FileName
    11.         Text1.Text = strArray(0)
    12.     End With
    It manages to recognize the first carriage return (chr(13)) but nothing after that so I only get 2 elements in my array.
    Place Your VBForums Ad Here

  18. #18
    Addicted Member big_k105's Avatar
    Join Date
    May 2003
    Location
    North Dakota
    Posts
    195
    this is a peice of code that i used in a program of mine to get rid of those squares. i havent modifided it to your situation jst thought i would share it and see if it helps you at all

    VB Code:
    1. startpos = 1
    2. Do While True
    3.             thispos = InStr(startpos, strFileRecord, Chr(10))
    4.             If thispos = 0 Then Exit Do
    5.             strFileRecord = Left(strFileRecord, thispos - 1) & Chr(13) & Chr(10) & Mid(strFileRecord, thispos + 1) ' replace chr(10) with chr(13) & chr(10)
    6.             startpos = thispos + 2
    7.             DoEvents
    8. Loop

  19. #19

    Thread Starter
    Addicted Member run_GMoney's Avatar
    Join Date
    May 2002
    Location
    Detroit
    Posts
    186
    Well, I just replaced the Chr$(13) with Chr$(10) and that seems to have done the trick, good enough anyway. Thanks for everyone's help on this.
    Place Your VBForums Ad Here

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