tags:

views:

48

answers:

3

Hi there, I have done this programming in java and it works but can't make it run in vb6 (and I need to)

Basically I need to send data to zebra printer over the network. The whole process works (no error reported but the printer does not print. In Java I have used:

 public void printOnions(ArrayList<String> DataArr){
        // LH is x,y coordinates for starting position
        // FO is x,y coordinates to start current print
        // BY sets the barcode size
        // BC is code128 then orientation, height,
        //    print interpretation line, print above barcode,
        //    check digit
        // A is font type, height and width
        // FD data start, FS data end
        String BarCode = DataArr.get(2) + "-" + DataArr.get(3);
        transferType = "^MTT";  // use thermal transfer
        String ZPLString = "^LH5,5" + transferType + // Sets the type to thermal transfer
            "^BY2" + "^MNM" +
            "^FO50,30" + "^ADN,96,20^FD" + DataArr.get(0) + "     " + DataArr.get(1) + "^FS" +
            "^FO250,130" + "^BCN,70,N,N,N"  + "^FD" + BarCode + "^FS" +
            "^FO50,230" + "^ADN,96,20^FD" + BarCode +  "      " + DataArr.get(4) + "^FS";

        PrtTags(ZPLString);

    }

    public void initializeZPL(String printerIn) throws IOException {
        try {
            //create stream objs
            int port = 9100;
            Socket sock = new Socket(printerIn, port);
            ostream = new FileOutputStream(printerIn);
            pstream = new PrintStream(sock.getOutputStream() );
        } catch (UnknownHostException ex) {
            Logger.getLogger(ZebraZPLView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ZebraZPLView.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
        }
    }
    public void PrtTags(String ZPLString){
    try{
       ZPLString = "^XA" + ZPLString + "^XZ";
       char[] chars = ZPLString.toCharArray();
       pstream.print(chars);
           // pstream.close();
       pstream.flush();
       }
       catch (Exception e) {
           e.printStackTrace();
       }

    }

This is vb6:

Dim Buffer() As Byte

Dim printer As String
printer = "ZBR3677984"
If sock.State = sckClosed Then
   sock.RemoteHost = printer
   sock.RemotePort = 9100
   sock.Connect

   Me.txtPrice.Text = "connected" & vbNewLine & sock.LocalHostName _
                       & vbNewLine & CStr(sock.RemotePort) _
                       & vbNewLine & CStr(sock.RemoteHost)
   Dim ZPLString As String
   ZPLString = "^LH10,10" & "^MTT" & "^BY2" & "^MNM" & _
            "^FO15,0" & "^ADN,36,20^FD" & "Line-1 " & "   Line 2 " & "^FS" & _
            "^FO15,50" & "^ADN,56,40^FD" & "line-3 " & "^FS" & _
            "^FO100,100" & "^BCN,70,N,N,N" & "^FD" & "line-4" & "^FS" & _
            "^FO15,190" & "^ADN,56,40" & "^FD" & "line-5" & "^FS" & _
            "^FO15,250" & "^BCN,70,N,N,N" & "^FD" & "line-6" & "^FS"

    ZPLString = "^XA" + ZPLString + "^XZ"
    ZPLString = "^XA" + "test" + "^XZ"

    ReDim Buffer(Len(ZPLString)) As Byte

    Buffer = ZPLString
    sock.SendData Buffer
End If

I am missing some king of NetworkStream to print. Does anybody have a line of thought ? Very much appreciated

Dallag

A: 

I wrote code to print to a zebra label printer in VB6, and was able to do this by installing the correct zebra printer driver. Once this is done you can simply use the VB6 printer object to send text to the printer.

http://www.nodevice.com/driver/company/Zebra.html

dretzlaff17
Hi thanks,You see the printer is not listed in the printers list on my pc.I do not want to use the printer object.I want to sent raw data to a networked printer.thanks
Dallag
A: 

Your sending a byte array of unicode chars, i.e if ZPLString was "X" your buffer contains 2 bytes; 88 00.

I suspect you don't want this as your using a CharArray so you should convert from unicode using: buffer = StrConv(ZPLString, vbFromUnicode).

Alex K.
Thanks Alex,i have tried it still no output. I think the problem is deeper.You see in java or C# to print to socket a FileOutputStream or networkstream is used but I do not know how to do this in vb6.Your help is greatly appreciated.I think I will have to rewrite the whole of my legacy vb6 application.......doh,
Dallag
Or make a com enabled c# dll that just does the sending
Alex K.
Great idea and easier than to rewrite the lot, appreciated.
Dallag
A: 

Before you send you have to wait for the connection to actually occur. If I remember well the socket control has a connect event. Trap this event and send your string on the event handler when it succeeds.

For details see the control documentation on the IDE's MSDN collection.

Also beware of socket errors (Use On Error everywhere).

All this is from memory so the details may be a bit off. I don't have access to VB any more (which is a good thing)..

renick