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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output without linefeed 1

Status
Not open for further replies.

Bong

Programmer
Dec 22, 1999
2,063
US
Greeting.
I am working on an application to build a dataset that represents a memory image (from a satellite dump, but that's not important). Using Excel, I specify the order, size, and calibration of the various fields I want in the dumped data. Then a macro builds the buffer according to the spreadsheet. That's working fine. What I have now outputs an ASCII HEX file representation of the buffer. I would also like to output the actual binary file. The problem is I don't know how to output without linefeeds and it's impractical to put the entire buffer in a single print statement.

Without posting needless code (although I will if anyone thinks it might not be needless), here's what I have:
Code:
    Open hmdir & "lhb.bin" For Random As #2 Len = 1
followed later by:
Code:
        wrdlen = Len(wrd)
        For bix = 1 To wrdlen - 1 Step 2
            bnum = Mid(wrd, bix, 2)
            bnum2 = b2d(h2b(bnum))
            Print #2, Chr(bnum2)
        Next
where wrd is an ASCII hex string, and b2d and h2b are functions I wrote to convert binary to decimal and hex to binary (they seem to be working fine).

I'm getting an abend on the Print statement to the effect of
Run-time error '54'
Bad file mode

The whole Chr() seems to be working like I want but just opening for output and printing normally throws in linefeeds all over the place. And obviously, if there's a way to use open and print to do what I want, I don't know what it is. Any suggestions?

_________________
Bob Rashkin
 
Perhaps the PUT statement will work better for you. This example is from Excel VBA help (though I added the .txt extension). I tried it and all records were written without linefeeds, although it's unreadable in Notepad.
Code:
Type Record    ' Define user-defined type.
    ID As Integer
    Name As String * 20
End Type

Private Sub main()
    Dim MyRecord As Record, RecordNumber
    ' Open file for random access.
    Open "c:\testfile.txt" For Random As #1 Len = Len(MyRecord)
    For RecordNumber = 1 To 5    ' Loop 5 times.
        MyRecord.ID = RecordNumber    ' Define ID.
        MyRecord.Name = "My Name" & RecordNumber    ' Create a string.
        Put #1, RecordNumber, MyRecord    ' Write record to file.
    Next RecordNumber
    Close #1    ' Close file.
End Sub
 
Great. Thanks a lot. I didn't know about put.

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top