Mar 2nd, 2004, 10:03 AM
#1
Thread Starter
Addicted Member
* 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:
Open .FileName For Input As #1
Do While Not EOF(1)
Input #1, lineArray(i)
i = i + 1
Loop
Last edited by run_GMoney; Mar 2nd, 2004 at 05:03 PM .
Place Your VBForums Ad Here
Mar 2nd, 2004, 10:10 AM
#2
Frenzied Member
First try using the Asc function to check what those 'boxes' actually are
Mar 2nd, 2004, 10:19 AM
#3
Thread Starter
Addicted Member
The boxes are carriage returns. I know this because Wordpad properly recognizes them.
Place Your VBForums Ad Here
Mar 2nd, 2004, 10:30 AM
#4
Frenzied Member
So what is your problem?
What happens during your Input loop?
Mar 2nd, 2004, 10:43 AM
#5
Thread Starter
Addicted Member
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
Mar 2nd, 2004, 10:45 AM
#6
Thread Starter
Addicted Member
Forgot to attach. Here it is
Attached Images
Place Your VBForums Ad Here
Mar 2nd, 2004, 10:56 AM
#7
Frenzied Member
How about using the split function
VB Code:
strOutput = Split(strNotepad, vbCrLf)
Then reading back from the array?
Mar 2nd, 2004, 11:04 AM
#8
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"
Mar 2nd, 2004, 11:29 AM
#9
Thread Starter
Addicted Member
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
Mar 2nd, 2004, 11:40 AM
#10
You know, if you use Line Input #1 instead of just Input #1, it *might* work....
TG
Mar 2nd, 2004, 11:41 AM
#11
Frenzied Member
VB Code:
Dim strTest As String
strTest = vbCrLf
Debug.Print Asc(strTest)
Mar 2nd, 2004, 11:59 AM
#12
Thread Starter
Addicted Member
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
Mar 2nd, 2004, 12:10 PM
#13
Frenzied Member
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:
Open .FileName For Input As #1
Do While Not EOF(1)
Input #1, lineArray(i)
Debug.Print Asc(lineArray(i))
Debug.Print lineArray(i)
i = i + 1
Loop
Mar 2nd, 2004, 12:19 PM
#14
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"
Mar 2nd, 2004, 12:27 PM
#15
Thread Starter
Addicted Member
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
Place Your VBForums Ad Here
Mar 2nd, 2004, 12:48 PM
#16
Frenzied Member
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
Mar 2nd, 2004, 02:23 PM
#17
Thread Starter
Addicted Member
Well, here's my latest code (thanks to Jamie's File I/O Tutorial).
VB Code:
Dim strArray() As String
With cdlFiles
.DialogTitle = "Open File"
.Flags = cdlOFNFileMustExist + cdlOFNPathMustExist
.ShowOpen
Open .FileName For Input As #1
strArray = Split(Input(LOF(1), 1), Chr$(13))
Close #1
lblInput.Caption = cdlFiles.FileName
Text1.Text = strArray(0)
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
Mar 2nd, 2004, 04:16 PM
#18
Addicted Member
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:
startpos = 1
Do While True
thispos = InStr(startpos, strFileRecord, Chr(10))
If thispos = 0 Then Exit Do
strFileRecord = Left(strFileRecord, thispos - 1) & Chr(13) & Chr(10) & Mid(strFileRecord, thispos + 1) ' replace chr(10) with chr(13) & chr(10)
startpos = thispos + 2
DoEvents
Loop
Mar 2nd, 2004, 05:03 PM
#19
Thread Starter
Addicted Member
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
Forum Rules
Click Here to Expand Forum to Full Width