Page 1 of 2

NPrint() and NPrintN()

Posted: Mon Mar 21, 2005 1:17 pm
by MLK
yes, i'm a lazy :)

Re: NPrint() and NPrintN()

Posted: Mon Mar 21, 2005 8:01 pm
by PB
What do they do?

Posted: Mon Mar 21, 2005 8:09 pm
by Psychophanta
I guess it avoid to have to write "Chr(10)+Chr(13)+" everytime for console printing.

Posted: Mon Mar 21, 2005 9:53 pm
by MLK
Chr(10)+Chr(13) / #CRLF$ / #LF$ - isn't working. you have to call PrintN("") each time

NPrintN("") = PrintN("") + Print("") + PrintN("")
NPrint("") = PrintN("") + Print("")

Posted: Mon Mar 21, 2005 10:09 pm
by dracflamloc
Does PB accept the standard characters for that kind of thing? It does not. In all honesty I think it needs to.

like in C:
printf("\nThis is on a new line\n")

so in PB:
Print("\nThis is on a new line\n")

Posted: Mon Mar 21, 2005 10:51 pm
by traumatic
dracflamloc wrote:In all honesty I think it needs to.

like in C:
printf("\nThis is on a new line\n")

so in PB:
Print("\nThis is on a new line\n")
Yes! :)


Here's a small workaround for the CRLF problem (windows only):

Code: Select all

Procedure _Print(hConsole.l, strToWrite.s)
  WriteConsole_(hConsole, strToWrite, Len(strToWrite), @cWritten, #NULL)
  ProcedureReturn cWritten
EndProcedure

hConsole = OpenConsole()

_Print(hConsole, "hello" + #LF$ + "world")

Input()
CloseConsole()
BTW, maybe using wsprintf directly could also be a (temporarily) solution:

Code: Select all

OpenConsole()
u32dll = OpenLibrary(#PB_Any, "user32.dll")

*f = IsFunction(u32dll, "wsprintfA")
If *f
  buf.s = Space(64)
  CallFunctionFast(*f, @buf.s, "int=%i, hex=%08x", 42, 8192)
  Print(buf)  
EndIf

CloseLibrary(u32dll)

Input()
CloseConsole()

Posted: Mon Mar 21, 2005 10:55 pm
by Psychophanta
dracflamloc wrote:Does PB accept the standard characters for that kind of thing? It does not. In all honesty I think it needs to.

like in C:
printf("\nThis is on a new line\n")

so in PB:
Print("\nThis is on a new line\n")
Noooo, that's uglyest. the called Escape senquences are hightly unreadable. :shock:

NPrintN is a great idea

Posted: Mon Mar 28, 2005 6:24 am
by npath
I agree, this would be nice to have:

Code: Select all

Procedure NPrintN(string.s)
  PrintN("")
  PrintN(string)
EndProcedure
OpenConsole()
NPrintN("Testing")
wait$=Input()
CloseConsole()

Re: NPrintN is a great idea

Posted: Mon Mar 28, 2005 7:22 am
by PB
I don't understand... Print() and PrintN() already exist, so what's the problem?

Re: NPrintN is a great idea

Posted: Mon Mar 28, 2005 12:25 pm
by Psychophanta
PB wrote:I don't understand... Print() and PrintN() already exist, so what's the problem?
Yes, but there is requested NPrint() and NPrintN(), this is, a CR before print the text.

Re: NPrintN is a great idea

Posted: Mon Mar 28, 2005 1:04 pm
by PB
Oh, now I see. :oops:

Posted: Mon Mar 28, 2005 7:34 pm
by dracflamloc
Psychophanta wrote:
dracflamloc wrote:Does PB accept the standard characters for that kind of thing? It does not. In all honesty I think it needs to.

like in C:
printf("\nThis is on a new line\n")

so in PB:
Print("\nThis is on a new line\n")
Noooo, that's uglyest. the called Escape senquences are hightly unreadable. :shock:
Unreadable?!?!?!?
Escape characters are a godsend in complex console apps.

I mean:
Print("Blah App\n1.0\nCopyright 2005")
is a hell of a lot better than:
Print("Blah App"+chr(13)+chr(10)+"1.0"+chr(13)+chr(10)+"Copyright 2005")
and having to use three lines of code just to print a header is ridiculus.

Also, its not like you would HAVE to use them...

Posted: Mon Mar 28, 2005 9:25 pm
by Blade
Agree with dracflamloc!
In fact I used the following to make my life easy(er):

Code: Select all

Procedure .s ParseText(txt.s)
  txt=ReplaceString(txt,"\n",Chr(10),1)
  txt=ReplaceString(txt,"\t",Chr(9),1)
  ProcedureReturn txt
EndProcedure
:)

Posted: Mon Mar 28, 2005 9:32 pm
by Psychophanta
\n inside "" are 2 characters: \ and n
\t inside "" are 2 characters: \ and t
chr(10) means 1 character, the one which ascii is 10
chr(13) means 1 character, the one which ascii is 13

Can't imagine a way to do it more legible, but something like this:
AsciiCharacter(10) or AsciiCharacter(13) ...

So sorry, but no agree with you.

Posted: Mon Mar 28, 2005 9:36 pm
by dracflamloc
Wtf are you talking about, haha

Are you trying to state basic knowledge that a chr() command creates one character, and "\n" is two characters?

I BOW DOWN TO YOUR AMAZING KNOWLEDGE AND BEG YOU TO FATHER MY CHILDREN!

:roll:

no offense or anything...