It works perfectly, but (for an A) can you tell me WHY this makes a difference?
Main Topics
Browse All TopicsI'm trying to display some text in a picturebox, however each word generates a new line, which is contry to what the tutorial I'm working through suggests (Its possible I've misread something).
The entire project is up at http://david.us-lot.org/tm
Private Sub PrintLine(Text)
Dim NextWord As String
While InStr(Text, Chr$(32)) 'While there is a space
NextWord = Left(Text, InStr(Text, Chr$(32)))
Text = Right(Text, (Len(Text) - InStr(Text, Chr$(32))))
If (pa.CurrentX + pa.TextWidth(NextWord)) > pa.ScaleWidth Then
NewLine
End If
pa.Print NextWord
Wend
If (pa.CurrentX + pa.TextWidth(NextWord)) > pa.ScaleWidth Then
NewLine
End If
pa.Print NextWord
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here is a redesigned version of the code:
Private Sub PrintLine(Text)
Dim lngPos As Long
Dim NextWord As String
Dim lngLastPos As Long
lngLastPos = 1
lngPos = InStr(1, Text, Chr$(32))
While lngPos > 0 'While there is a space
NextWord = Left(Text, lngPos)
If (CurrentX + TextWidth(NextWord)) > ScaleWidth Then
NextWord = Left(Text, lngLastPos)
Print NextWord
Text = Mid(Text, lngLastPos)
lngLastPos = 1
lngPos = InStr(1, Text, Chr$(32))
Else
lngLastPos = lngPos
lngPos = InStr(lngPos + 1, Text, Chr$(32))
End If
Wend
If (CurrentX + TextWidth(Text)) > ScaleWidth Then
NextWord = Left(Text, lngLastPos)
Print NextWord
Text = Mid(Text, lngLastPos)
End If
Print Text
End Sub
CHeers
>add a new line rather then add something to remove a new line.
That's fine for non-printed things, but I think that the original problem was that basic was run on teletypes, and if you didn't have the newline character, it just kept printing at the right margin and you'd eventually end up with a whole in the paper where the pritn head kept printing.
The answer, according to the BASIC group was, "let's keep it simply and default it to go to a new line whenever a line ends." In other words, if you don't ask it to stay on the same line, you must want the next line, which is reinforced by the fact that you didn't put more text on the line with the print.
For example, should you put your address like this:
print John Smithson
print 123 Evergreen Rd.
print Smalltown, WZ
or should you do this
print John Smithson (next line)
print 123 Evergreen Rd. (next line)
print Smalltown, WZ (next line)
?
--
The problem you're having is the opposite, that you want the next line to be part of the same line, so the BASIC people felt that you should tell it that:
print firstword (same line)
print secondword (same line)
print thirdword (same line)
which becomes:
print "firstword";
print "secondword";
print "thirdword";
--
I see it as a 50-50 deal. Either you think it's better to do a new line unless told otherwise, or you think it only do a new line when told.
It's kind of like using Do While versus Do Until. Which should you use, if you were only ever allowed to use one? The ansswer is probably use the one that's simplest most of the time for your own needs.
So maybe print shoudl be replaced with two new commands:
* PrintWithNewLine
* PrintWithoutNewLine
Now it becomes clear which one to use for your needs. Hmmm...why didn't I think of that sooner?
rspahitz,
Thanks for filling in the explanation. It is surprising how little is known about the origins of the BASIC langauge (especially when one tends to take this for granted). And then perhaps not so surprising when you think that 90% (my guess) of VB programmers were not even born when BASIC was first "invented". Even fewer know that not even Microsoft was around then (Gates would have been about 10 years old at the time), let alone know where or who created BASIC or what it stand for, for that matter.
This may explain the lack of understanding (and tolerance) at some of its quirks in the syntax. Of course all of this is history in VB.NET ...
Anthony
Hi, Anthony.
I hope I didn't sound *that* old. I started Basic in the late 70s (also when a lot of VB'ers weren't yet born) with a TRS-80 (an exciting time!) and enjoyed it enough that I learned a lot about it.
VB, although based on BASIC, really has many differences, especially since VB5 with the object-oriented push. But because of the origins, you still sometimes get the legacy stuff. And now with VB.net, I can see all this going away and VB erally being a new product.
Business Accounts
Answer for Membership
by: acperkinsPosted on 2002-08-09 at 07:25:56ID: 7209345
Private Sub PrintLine(Text)
Dim NextWord As String
While InStr(Text, Chr$(32)) 'While there is a space
NextWord = Left(Text, InStr(Text, Chr$(32)))
Text = Right(Text, (Len(Text) - InStr(Text, Chr$(32))))
If (pa.CurrentX + pa.TextWidth(NextWord)) > pa.ScaleWidth Then
NewLine
End If
pa.Print NextWord; ' Change this
Wend
If (pa.CurrentX + pa.TextWidth(NextWord)) > pa.ScaleWidth Then
NewLine
End If
pa.Print NextWord; ' Change this
End Sub
Anthony