Results 1 to 8 of 8

Thread: text box / print prob

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    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

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I think this line gives you a little headach:
    strPrint = Left(strPrint, Len(strPrint) - Len(vbNewLine))
    Try using this instead:
    VB Code:
    1. If Right(strPrint, 2) = vbNewLine Then
    2.     strPrint = Left(strPrint, Len(strPrint) - Len(vbNewLine))
    3. End If
    4. 'OR
    5. strPrint = IIf(Right(strPrint, 2) = vbNewLine, Left(strPrint, Len(strPrint) - 2), strPrint)
    Roy

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Instead of 2 use Len(vbNewLine)
    Roy

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    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' ?

  5. #5
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    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.
    Roy

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    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?

  7. #7
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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'.

  8. #8
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    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.
    Roy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width