Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help reading this file

Status
Not open for further replies.

ATHUEL

Technical User
Sep 23, 2002
29
US
Hi everyone,
I need to read this text from a file.

Max Print Job File Øê @ ˆ  I7lˆ Dl@  ´ë\165x Dläê dë B-@lÿÿÿÿ Æ7l bjpm  ) C:\DOCUME~1\all users\LOCALS~1\Temp\1624.mjd , ,  PMGC Print Job

All this is in one line. I'm using "open ifile for input as.." but I only can read "Max Print Job File" I assume that the "box caracter" behind is a kind of separator, but I don't realize how to read the entire text. My aim is, actually, to can read the "c:\Docume~1\all users\locals~1\ temp\1624.mjd" text.

I really appreciate if any of you could help me with this.
Thanks in advance,
leo.
 
Leo,

Couple of questions:

What are you defining as text?

Why are you trying to read text from a Binary File?

-Sean
 
SeanGriffin,
Ok,
that is what I thougth, then, how can I read a bin file and convert it to a text string in order to capture the path to the file that I need
 
Leo,

Here's some quick code that is in the ball park of what you want.

Code:
    Dim lFile As Long
    Dim lFileLenghth As Long
    Dim i As Long
    
    Dim lCount As Long
    
    Dim bArray() As Byte
    
    Dim sPossibleAnswers() As String
    Dim sAcceptableCharacters As String
    
    sAcceptableCharacters = _
                "abcdefghijklmnopqrstuvwxyz" & _
                "ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
                "1234567890" & _
                "\:~"
    
    lFile = FreeFile
    Open sPath For Binary Access Read As lFile
        lFileLenghth = FileLen(sPath)
        ReDim bArray(lFileLenghth)
        
        bArray = Input(lFileLenghth, lFile)
        
    Close lFile
    
    lCount = 0
    
    ReDim sPossibleAnswers(0)
    For i = 0 To UBound(bArray) Step 2
        If InStr(sAcceptableCharacters, Chr(bArray(i))) Then
            sPossibleAnswers(lCount) = sPossibleAnswers(lCount) & Chr(bArray(i))
        Else
            
            If sPossibleAnswers(lCount) <> &quot;&quot; Then
                lCount = lCount + 1
                ReDim Preserve sPossibleAnswers(lCount)
            End If
        End If
    Next i
    
    Erase bArray, sPossibleAnswers
 [CODE]

This won't quite work but hopefully it will point you in the correct direction. If your system only has 1 byte per character you may need to remove the &quot;Step 2&quot;.

-Sean
 
How about this to get you started:
Code:
Dim intI as Integer
Dim intO as Integer
Dim lngP as Long
Dim strX as string * 1

intI = FreeFile
Open &quot;YourBinaryFilename&quot; For Random As intI Len = Len(strX)
intO = FreeFile
Open &quot;MyTextFile.txt&quot; For Output As intO
For lngP = 1 to LOF(intI)
  Get #intI, lngP, strX
  If Asc(strX) < 31 Or Asc(strX) > 127 Then strX = &quot; &quot;
  Print #intO, strX;
Next lngP
Close intI, intO
That should replace any &quot;nasty&quot; characters with a space and write to MyTextFile.txt. You can replace
Code:
Then strX = &quot; &quot;
with
Code:
Then strX = vbNullString
if you don't want to bother with &quot;nasty&quot; characters.

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
 
Ok,
I gonna try these approaches and i'll let you know
Thanks you guys for all.
 
Sean

Just an ickle point: What if the filename/path contains &quot;-&quot; or &quot;.&quot;? [smile]

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
 
Andy,

As I said it wouldn't quite work but it gave the general idea.

There's also an issue with what happens if an acceptable character just happens to be just before or just after the real string. My quick answer don't account for this either.

-Sean
 
> My quick answer don't account for this either.

Mine ducked it entirely! [ducky]

I shouldn't be so quick to point out such a little niggle, but I'm afraid I just couldn't resist with &quot;.&quot;

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
 

>My aim is, actually, to can read the &quot;c:\Docume~1\all users\locals~1\ temp\1624.mjd&quot; text.
[tt]
Option Explicit

Private Sub Form_Load()
Dim S As String, StartPosition As Integer, EndPosition As Integer
Dim FName As String, FNumb As Integer

FName = &quot;D:\a\temp.txt&quot;

FNumb = FreeFile

Open FName For Binary As #FNumb

S = Input(FileLen(FName), #FNumb)

Close #FNumb

EndPosition = InStrRev(S, &quot;.&quot;) + 3
StartPosition = InStrRev(S, &quot;:&quot;) - 1

Debug.Print Mid(S, StartPosition, (EndPosition - StartPosition) + 1)

End Sub
[/tt]

Good Luck

PS. AndyWatt shouldn't Print be Put??? else wouldn't you create a vertical file which couldn't be easy to read back in.

 
vb5prgrmr

There is a semi-colon:
Code:
Print #intO, strX;
So it will print character after character, no vbCrLfs.

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
 
[bigcheeks]

Andy
&quot;Logic is invincible because in order to combat logic it is necessary to use logic.&quot; -- Pierre Boutroux
 
Vb5prgrmr,
thanks for your code it worked just perfect.
the endposition & startposition algoritms are quite clever.
Your are a genius !!

Sorry for delay in my response...( I was traveling around my country).

Bye.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top