Proposed Answer print cpcl

  • Thursday, December 01, 2011 3:59 PM
     
     

    Hallo Friends

    I have a PDA Casio IT-600 and want print to a Citizen CMP-30 printer via bluetooth.

    If I print with following code, it works fine:

           Dim comPort1 As New SerialPort("COM6", 57600, Parity.None, 8, StopBits.One)

            Try
                comPort1.Open()
            Catch ex As Exception
                MessageBox.Show("Bitte schalten Sie den Drucker ein oder stellen Sie die Bluetooth-Verbindung wieder her!")
                Exit Sub
            End Try

            comPort1.WriteLine("! 0 200 200 229 1")
            comPort1.WriteLine("T 7 0 30 02 Text1")
            comPort1.WriteLine("T 7 0 30 22 Text2")
            comPort1.WriteLine("PRINT")

            comPort1.Close()

    But if I try to use an variable text like following code it doesn't works:

           Dim comPort1 As New SerialPort("COM6", 57600, Parity.None, 8, StopBits.One)

            Try
                comPort1.Open()
            Catch ex As Exception
                MessageBox.Show("Bitte schalten Sie den Drucker ein oder stellen Sie die Bluetooth-Verbindung wieder her!")
                Exit Sub
            End Try

            Dim text1 As String = "Text1"
            Dim text2 As String = "Text2"

            comPort1.WriteLine("! 0 200 200 229 1")
            comPort1.WriteLine("T 7 0 30 02" + text1)
            comPort1.WriteLine("T 7 0 30 22" + text2)
            comPort1.WriteLine("PRINT")

            comPort1.Close()

     

    What have I to do to print variable text or barcode?

    Anyone help me please.

    Thanks in advance

All Replies

  • Friday, December 02, 2011 2:19 PM
     
     Proposed Answer

    In your second part with the variables you do not have a whitespace between the 02" and the contents of the variable text1.

    Writeline will do "T 7 0 30 02" + text1 --> "T 7 0 30 02" + "Text1" --> "T 7 0 30 02Text1" while you probably want "T 7 0 30 02 Text1"



    Edit:

    See http://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in-vb-net

    In vb.net it might be better to use & instead of + to concatenate strings

    • Edited by bart___s Friday, December 02, 2011 2:19 PM
    • Edited by bart___s Friday, December 02, 2011 2:23 PM
    • Proposed As Answer by bart___s Tuesday, December 06, 2011 7:38 AM
    • Marked As Answer by alpton Wednesday, December 07, 2011 9:35 AM
    • Unmarked As Answer by alpton Wednesday, December 07, 2011 9:36 AM
    •  
  • Wednesday, December 07, 2011 9:50 AM
     
     

    Thanks bart__s.

    It works.

    "In vb.net it might be better to use & instead of + to concatenate strings" - yes, I know. I tried it with & and +. But my mistake was the missing whitespace.

     

  • Friday, December 09, 2011 3:28 PM
     
     

    Thanks bart__s.

    It works.

    "In vb.net it might be better to use & instead of + to concatenate strings" - yes, I know. I tried it with & and +. But my mistake was the missing whitespace.