Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

winsock--seems to be sending binary data

Status
Not open for further replies.

Jasen

IS-IT--Management
May 1, 2002
435
US
I have a very simple bit of code that instantiates a winsock object, opens a connection to port 9100, sends a string of ZPL code (zebra printer language), and quits.
It works perfectly in VB.

That same code ported to VBA does not work.

I setup a program to act as a fake destination printer so I could see what data actually gets sent, and the VB app sends a nice string.. the other seems to send the data in a binary form. Or maybe it's just corrupted?

The winsock control is pretty simple, it doesn't have many properties to mess with, and I can't see any that would affect this. Has anyone else seen this behavior?
 
Could you show us the code you're using?

HarleyQuinn
---------------------------------
Black coat, white shoes, black hat, cadillac. The boy's a timebomb!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before post
 
This is pretty much it.

Code:
    Dim Zebra as Object
    Dim data as String

	Set zebra = createobject("MSWinsock.Winsock.1")

	Zebra.Protocol = sckTCPProtocol
	Zebra.RemotePort = 9100
	Zebra.RemoteHost = "x.x.x.x"
	     
    data="^XA~TA000~JSN^LT0^MMT^MNW^MTD^PON^PMN^XZ" 'truncated for brevity

    Zebra.Connect
    
    Do While Zebra.State < sckConnected
        DoEvents  
    Loop
    
    If Zebra.State = sckConnected Then
        Zebra.SendData data
    else
        'error condition
    end if

    Zebra.Close
 
I'm not sure what VBA host you are automating, but a client Office license does not include the use of the Winsock control or many of the VB controls at all. I believe the only legal way to use this from Office VBA is to develop a deployable solution using Office Developer Edition (2000, 2002) or one of the developer add-on kits VSTO/VSTA (2003, 2007).
 
It's not Office, but an HMI application that uses a VBA/VBS scripting interface.
This is also on a machine where the full VS6 is installed, so I would think the proper registry entries for enabling the winsock control are there. I don't think licensing is making my Winsock output garbage data anyhow.
It's a bizarre problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top