|
-
Oct 10th, 2002, 01:36 PM
#1
Thread Starter
Addicted Member
text box / print prob
I have a text box (txtMisc) that user can enter a message, When cmdAdd_Click the text is written to a picture box (picDisplay) Then when cmdPrint_Click contents of picDisplay are printed.
Reality hits when the text is shown in the picture box - it appears twice, once in it's full form, the second with the last two letters missing. The text prints correctly , once when printed.
Private Sub cmdADD_Click()
Form4.picDisplay.Print (" ") & (txtMisc.Text) ' & vbNewLine
strValue = strValue & (txtMisc.Text)
'PrintEx (txtMisc.Text), , , , Arial, 20, peBold, vbRed
txtMisc.Text = (" ")
If Len(strValue) > 0 Then
strPrint = strPrint & strValue 'store for printing
'trim last vbnewline
strValue = Left(strValue, Len(strValue) - Len(vbNewLine))
picDisplay.Print strValue
End If
strValue = " "
End Sub
Private Sub cmdPrint_Click()
If Len(strPrint) = 0 Then Exit Sub
'trim last vbnewline
strPrint = Left(strPrint, Len(strPrint) - Len(vbNewLine))
Printer.Print strPrint
Printer.EndDoc
picDisplay.Picture = LoadPicture("")
picDisplay.CurrentX = 0
picDisplay.CurrentY = 0
strPrint = ""
End Sub
-
Oct 10th, 2002, 01:51 PM
#2
PowerPoster
I think this line gives you a little headach:
strPrint = Left(strPrint, Len(strPrint) - Len(vbNewLine))
Try using this instead:
VB Code:
If Right(strPrint, 2) = vbNewLine Then
strPrint = Left(strPrint, Len(strPrint) - Len(vbNewLine))
End If
'OR
strPrint = IIf(Right(strPrint, 2) = vbNewLine, Left(strPrint, Len(strPrint) - 2), strPrint)
-
Oct 10th, 2002, 01:52 PM
#3
PowerPoster
Instead of 2 use Len(vbNewLine)
-
Oct 10th, 2002, 02:26 PM
#4
Thread Starter
Addicted Member
working better using the code below as you suggested but,
strPrint = IIf(Right(strPrint, 2) = vbNewLine, Left(strPrint, Len(strPrint) - 2), strPrint)
1. why 'IIf' not 'If'
2. why, when sent to printer does it remove the last 2 letters of the text i.e if I type 'extra cheese' in the text box, it is displayed in the picture box correctly but when printed it says ' extra chee' ?
-
Oct 10th, 2002, 02:35 PM
#5
PowerPoster
IIf is a function which works like If ... Else ... End If structure. You may use either but IIf is shorter and I thnk is faster.
-
Oct 10th, 2002, 06:19 PM
#6
Software Eng.
Originally posted by IROY55
IIf is shorter and I thnk is faster.
Typing wise, yes; speed wise, no.
But then again, with all these 4Ghz CPU's up today, who cares?
-
Oct 10th, 2002, 06:26 PM
#7
Re: text box / print prob
Originally posted by mbonfyre
strValue = Left(strValue, Len(strValue) - Len(vbNewLine))
Don't forget to use the $ in function like Left$ to avoid double conversion when dealing with 'Strings'.
-
Oct 10th, 2002, 07:32 PM
#8
PowerPoster
Typing wise, yes; speed wise, no
Not exactly, I'm afraid. IIf function was most definitely written in C, C++ or Assembly therefore it's much faster then almost any logic yet to be compiled in VB itself. I remeber timing many different logics under Win 3.1 and even Win95 and difference was real. Of course to day it's almost impossible to see that with this supersonic fast PCs.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|