Home All Groups Group Topic Archive Search About

Have a problem that is stumping me.

Author
25 Feb 2007 1:23 AM
Kardon Coupé
Dear All,

I've written a simple custom app that converts a file, by reading bytes,
into a text file, but I'm getting confused with my carriage returns and/or
line feeds...

I get my .txt file output, but if I load the text file into notepad, it is
ok, until I press a key, return, or something, and it all goes askew, if I
load it into wordpad, or MS Word, the whole text file goes on the very first
line?

I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return' and
10 is Line Feed?

What am I doing wrong, hope someone can help me..

Regards
Paul.

Author
25 Feb 2007 2:11 AM
Larry Serflaten
Show quote Hide quote
"Kardon Coupé" <prefer.to@readon.newsgroups> wrote
> Dear All,
>
> I've written a simple custom app that converts a file, by reading bytes,
> into a text file, but I'm getting confused with my carriage returns and/or
> line feeds...
>
> I get my .txt file output, but if I load the text file into notepad, it is
> ok, until I press a key, return, or something, and it all goes askew, if I
> load it into wordpad, or MS Word, the whole text file goes on the very first
> line?
>
> I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return' and
> 10 is Line Feed?
>
> What am I doing wrong, hope someone can help me..

It is very difficult to know where the error is in your code, if you post no code to look at.
Work up a small example that has the same problem, and post that....

LFS
Author
25 Feb 2007 4:16 PM
Kardon Coupé
Guys, sorry, I thought posting lots of code b4 it was asked for was frowned
upon, so many different rules for so many newsgroups....

See below the basic code I use, I'm not bothered about speed, the code
itself apart from the the line feeds works....but any input would be
appreciated.. :)

Regards
Paul.

;**************************************************

Private Sub Command4_Click()
position = 0
Dim mychar As Byte
Dim opcode As Variant
opcode = Array("ORA ", "AND ", "EOR ", "ADC ", "STA ", "LDA ", "CMP ", "SBC
", _
"ASL ", "ROL ", "LSR ", "ROR ", "STX ", "LDX ", "DEC ", "INC ", "BIT ", "STY
", _
"LDY ", "CPY ", "CPX ", "JMP ", "JSR ", "BRK ", "PHP ", "CLC ", "PLP ", "SEC
", _
"RTI ", "PHA ", "CLI ", "RTS ", "PLA ", "SEI ", "DEY ", "TXA ", "TYA ", "TXS
", _
"TAY ", "TAX ", "CLV ", "TSX ", "INY ", "DEX ", "CLD ", "INX ", "NOP ", "SED
", _
"BPL ", "BMI ", "BVC ", "BVS ", "BCC ", "BCS ", "BNE ", "BEQ ", "*= ",
".byte (sort) ", _
".byte ", ".word ", ".scrl ", "> ", "Displace{needtosort} ", "ENT ", "=",
".scrl", "< ", "CLC " & Chr$(13) & "ADC ", _
"SEC " & Chr$(13) & "SBC ", ".byte ", ".text ")

Dim extras As Variant
extras = Array(",X)", "),Y", ",X", ",Y", "%", "OR ", "XOR ", "/ ", "& ")

Open Text1.Text For Binary As #1    ' Open file for Read
Open Text2.Text For Output As #2    ' Open File for Write
tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
While mychar <> 255
    Get #1, , mychar                ' Get one character.
    Select Case mychar
    Case 1                          ' Just to get rid of first
        text_to_print$ = text_to_print$ & "00"

    Case 4                          ' Two bytes, can be delete in editor
        text_to_print$ = text_to_print$ & "04" & Chr$(13) & Chr$(10)

    Case 46
        text_to_print$ = text_to_print$ & "_"

    Case 35                         ' Low Byte
        text_to_print$ = text_to_print$ & " #<"

    Case 94                         ' High Byte
        text_to_print$ = text_to_print$ & " #>"

    Case 16 To 93                   ' Normal Chars
        text_to_print$ = text_to_print$ & Chr$(mychar)
        amount_of_chars = amount_of_chars + 1
        If amount_of_chars <= 4 Then
        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) &
Chr$(9)
        End If
        If amount_of_chars >= 5 And amount_of_chars <= 8 Then
        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
        End If
        If amount_of_chars >= 9 And amount_of_chars <= 16 Then
        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
        End If

    Case 0                          'End of Line
        text_to_print$ = text_to_print$ & Chr$(13)
        Print #2, text_to_print$
        text_to_print$ = ""
        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) &
Chr$(9)
        amount_of_chars = 0

    Case 255                        ' End of File
        a = MsgBox("Convertion Done", vbOKOnly, "Success")
        GoTo skip

    Case 126
        text_to_print$ = text_to_print$ & "~"

    Case 128 To 198                 ' Main Op Codes
        text_to_print$ = text_to_print$ & tab_amount$ & " " &
opcode(mychar - 128)

    Case 224 To 232                 ' extenders
        text_to_print$ = text_to_print$ + extras(mychar - 224)

    Case Else
        text_to_print$ = text_to_print$ & Chr$(mychar)

    End Select
position = position + 1
Wend
skip:
Close #1   ' Close file.
Close #2   ' Close file.
End Sub
Show quoteHide quote
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:eHwlIJIWHHA.4964@TK2MSFTNGP06.phx.gbl...
>
> "Kardon Coupé" <prefer.to@readon.newsgroups> wrote
>> Dear All,
>>
>> I've written a simple custom app that converts a file, by reading bytes,
>> into a text file, but I'm getting confused with my carriage returns
>> and/or
>> line feeds...
>>
>> I get my .txt file output, but if I load the text file into notepad, it
>> is
>> ok, until I press a key, return, or something, and it all goes askew, if
>> I
>> load it into wordpad, or MS Word, the whole text file goes on the very
>> first
>> line?
>>
>> I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return'
>> and
>> 10 is Line Feed?
>>
>> What am I doing wrong, hope someone can help me..
>
> It is very difficult to know where the error is in your code, if you post
> no code to look at.
> Work up a small example that has the same problem, and post that....
>
> LFS
>
>
Author
25 Feb 2007 5:15 PM
Larry Serflaten
"Kardon Coupé" <prefer.to@readon.newsgroups> wrote
> Guys, sorry, I thought posting lots of code b4 it was asked for was frowned
> upon, so many different rules for so many newsgroups....

It helps if the code you post actually works.  That's why I mentioned to
build a smaller project that had the same problem, so we could test in
on our own systems.  It just makes for easier debugging because we can
see if a suggested change actually works.

At first glance, I'd suggest you change two of the Case statements:

    Case 4                          ' Two bytes, can be delete in editor
        text_to_print$ = text_to_print$ & "04" & vbCrLf

And

    Case 0                          'End of Line
        ' text_to_print$ = text_to_print$ & Chr$(13)
        Print #2, text_to_print$


The first change simply uses VB's constant for what you had.
The second change removes that Chr(13) you added.  It is not
needed, the Print command (as shown) will add the end of line
characters.

HTH
LFS
Author
25 Feb 2007 5:58 PM
Robert Morley
What chipset are those opcodes for?  Looks suspiciously similar to the 6500
series of 20+ years ago (which I just brought up in another thread,
coincidentally).


Rob

Show quoteHide quote
"Kardon Coupé" <prefer.to@readon.newsgroups> wrote in message
news:O97sGhPWHHA.4404@TK2MSFTNGP03.phx.gbl...
> Guys, sorry, I thought posting lots of code b4 it was asked for was
> frowned upon, so many different rules for so many newsgroups....
>
> See below the basic code I use, I'm not bothered about speed, the code
> itself apart from the the line feeds works....but any input would be
> appreciated.. :)
>
> Regards
> Paul.
>
> ;**************************************************
>
> Private Sub Command4_Click()
> position = 0
> Dim mychar As Byte
> Dim opcode As Variant
> opcode = Array("ORA ", "AND ", "EOR ", "ADC ", "STA ", "LDA ", "CMP ",
> "SBC ", _
> "ASL ", "ROL ", "LSR ", "ROR ", "STX ", "LDX ", "DEC ", "INC ", "BIT ",
> "STY ", _
> "LDY ", "CPY ", "CPX ", "JMP ", "JSR ", "BRK ", "PHP ", "CLC ", "PLP ",
> "SEC ", _
> "RTI ", "PHA ", "CLI ", "RTS ", "PLA ", "SEI ", "DEY ", "TXA ", "TYA ",
> "TXS ", _
> "TAY ", "TAX ", "CLV ", "TSX ", "INY ", "DEX ", "CLD ", "INX ", "NOP ",
> "SED ", _
> "BPL ", "BMI ", "BVC ", "BVS ", "BCC ", "BCS ", "BNE ", "BEQ ", "*= ",
> ".byte (sort) ", _
> ".byte ", ".word ", ".scrl ", "> ", "Displace{needtosort} ", "ENT ", "=",
> ".scrl", "< ", "CLC " & Chr$(13) & "ADC ", _
> "SEC " & Chr$(13) & "SBC ", ".byte ", ".text ")
>
> Dim extras As Variant
> extras = Array(",X)", "),Y", ",X", ",Y", "%", "OR ", "XOR ", "/ ", "& ")
>
> Open Text1.Text For Binary As #1    ' Open file for Read
> Open Text2.Text For Output As #2    ' Open File for Write
> tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
> While mychar <> 255
>    Get #1, , mychar                ' Get one character.
>    Select Case mychar
>    Case 1                          ' Just to get rid of first
>        text_to_print$ = text_to_print$ & "00"
>
>    Case 4                          ' Two bytes, can be delete in editor
>        text_to_print$ = text_to_print$ & "04" & Chr$(13) & Chr$(10)
>
>    Case 46
>        text_to_print$ = text_to_print$ & "_"
>
>    Case 35                         ' Low Byte
>        text_to_print$ = text_to_print$ & " #<"
>
>    Case 94                         ' High Byte
>        text_to_print$ = text_to_print$ & " #>"
>
>    Case 16 To 93                   ' Normal Chars
>        text_to_print$ = text_to_print$ & Chr$(mychar)
>        amount_of_chars = amount_of_chars + 1
>        If amount_of_chars <= 4 Then
>        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) &
> Chr$(9)
>        End If
>        If amount_of_chars >= 5 And amount_of_chars <= 8 Then
>        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
>        End If
>        If amount_of_chars >= 9 And amount_of_chars <= 16 Then
>        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9)
>        End If
>
>    Case 0                          'End of Line
>        text_to_print$ = text_to_print$ & Chr$(13)
>        Print #2, text_to_print$
>        text_to_print$ = ""
>        tab_amount$ = Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) & Chr$(9) &
> Chr$(9)
>        amount_of_chars = 0
>
>    Case 255                        ' End of File
>        a = MsgBox("Convertion Done", vbOKOnly, "Success")
>        GoTo skip
>
>    Case 126
>        text_to_print$ = text_to_print$ & "~"
>
>    Case 128 To 198                 ' Main Op Codes
>        text_to_print$ = text_to_print$ & tab_amount$ & " " &
> opcode(mychar - 128)
>
>    Case 224 To 232                 ' extenders
>        text_to_print$ = text_to_print$ + extras(mychar - 224)
>
>    Case Else
>        text_to_print$ = text_to_print$ & Chr$(mychar)
>
>    End Select
> position = position + 1
> Wend
> skip:
> Close #1   ' Close file.
> Close #2   ' Close file.
> End Sub
> "Larry Serflaten" <serfla***@usinternet.com> wrote in message
> news:eHwlIJIWHHA.4964@TK2MSFTNGP06.phx.gbl...
>>
>> "Kardon Coupé" <prefer.to@readon.newsgroups> wrote
>>> Dear All,
>>>
>>> I've written a simple custom app that converts a file, by reading bytes,
>>> into a text file, but I'm getting confused with my carriage returns
>>> and/or
>>> line feeds...
>>>
>>> I get my .txt file output, but if I load the text file into notepad, it
>>> is
>>> ok, until I press a key, return, or something, and it all goes askew, if
>>> I
>>> load it into wordpad, or MS Word, the whole text file goes on the very
>>> first
>>> line?
>>>
>>> I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return'
>>> and
>>> 10 is Line Feed?
>>>
>>> What am I doing wrong, hope someone can help me..
>>
>> It is very difficult to know where the error is in your code, if you post
>> no code to look at.
>> Work up a small example that has the same problem, and post that....
>>
>> LFS
>>
>>
>
>
Author
25 Feb 2007 8:06 PM
Mike Williams
"Robert Morley" <rmor***@magma.ca.N0.Freak1n.sparn> wrote in message
news:u8CT$bQWHHA.192@TK2MSFTNGP04.phx.gbl...

> What chipset are those opcodes for?  Looks suspiciously similar
> to the 6500 series of 20+ years ago (which I just brought up in
> another thread, coincidentally).

Yep. That's 6502 stuff alright. Couldn't mistake it.

Mike
Author
26 Feb 2007 12:04 AM
Michael C
"Kardon Coupé" <prefer.to@readon.newsgroups> wrote in message
news:O97sGhPWHHA.4404@TK2MSFTNGP03.phx.gbl...
> Guys, sorry, I thought posting lots of code b4 it was asked for was
> frowned upon, so many different rules for so many newsgroups....

Posting lots of code full stop is frowned upon IMO. People here are not
being paid to answer your question so you need to go to the effort to make
the code as small as possible while still demonstrating the problem. Having
the code able to be easily copy/pasted into a project is good also :-)

Michael
Author
25 Feb 2007 3:01 AM
Robert Morley
It's likely a problem in your code, but to be on the safe side, usually
you're best using Chr$(13) & Chr$(10) as your line break.  Note that in VB,
there's a much shorter way to type this:  vbCrLf.  Similarly, there's vbCr
and vbLf if you want them separately.  The shorter way to type them will
also produce faster code, though in almost all cases, the difference would
be utterly negligible.


Rob

Show quoteHide quote
"Kardon Coupé" <prefer.to@readon.newsgroups> wrote in message
news:%23B7HMuHWHHA.2256@TK2MSFTNGP02.phx.gbl...
> Dear All,
>
> I've written a simple custom app that converts a file, by reading bytes,
> into a text file, but I'm getting confused with my carriage returns and/or
> line feeds...
>
> I get my .txt file output, but if I load the text file into notepad, it is
> ok, until I press a key, return, or something, and it all goes askew, if I
> load it into wordpad, or MS Word, the whole text file goes on the very
> first
> line?
>
> I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return'
> and 10 is Line Feed?
>
> What am I doing wrong, hope someone can help me..
>
> Regards
> Paul.
>
>
>
Author
25 Feb 2007 6:26 AM
AmiDaniel
On Feb 24, 6:23 pm, "Kardon Coupé" <prefer...@readon.newsgroups>
wrote:
> I'm using chr$(13) and/or chr$(10) as far as I was aware 13 was 'Return' and
> 10 is Line Feed?

Which is it--"and" or "or"? Windows text encoding always uses Chr(13)
+ Chr(10) as the new line character, so a newline in windows-land will
always be two bytes. If you open up a file uses notepad that, instead
of using CR+LF, uses only CR or only LF for newlines, then all the
text will appear on one line, possibly with question marks or small
boxes in place of the LF character. Unix encoding uses only LF--
perhaps this is what's causing your problems?

It's sort of difficult to provide any help without knowing more
specific details of what you're doing...

--
Daniel Cannon