title: How to open a TCP/IP port to a printer in VB6
body: <p>I was wondering if somebody knows how to connect to a thermal printer with a TCP/IP interface using Visual Basic 6.  It is to send ESC/POS command to the printer so that I can control it directly without the need to use a driver.</p>
  
  <p>The problem is on the first line; how do I establish a connection with the printer and also give the printer's ip and other things so that the host pc/sender pc smoothly communicates with printer?</p>
  
  <pre><code>open
  PRINT #1, CHR$(&amp;H1B);"@"; 'Initializes the printer (ESC @)
  PRINT #1, CHR$(&amp;H1B);"a";CHR$(1);'Specifies a centered printing position (ESC a)
  PRINT #1, CHR$(&amp;H1B);"!";CHR$(0); 'Specifies font A (ESC !)
  PRINT #1, "January 14, 2002  15:00"; 
  PRINT #1, CHR$(&amp;H1B);"d";CHR$(3); 'Prints and 3 line feeding (ESC d)
  PRINT #1, CHR$(&amp;H1B);"a";CHR$(0); 'Selects the left print position (ESC a)
  PRINT #1, CHR$(&amp;H1B);"!";CHR$(1); 'Selects font B
  PRINT #1, "TM-U210B               $20.00";CHR$(&amp;HA);
  PRINT #1, "TM-U210D               $21.00";CHR$(&amp;HA);
  PRINT #1, "PS-170                     $17.00";CHR$(&amp;HA);
  PRINT #1, CHR$(&amp;HA);'Line feeding (LF)
  PRINT #1, CHR$(&amp;H1B);"!";CHR$(17); 'Selects double-height mode
  PRINT #1, "TOTAL                  $58.00"; CHR$(&amp;HA);
  PRINT #1, CHR$(&amp;H1B);"!";CHR$(0); 'Cancels double-height mode
  PRINT #1, "------------------------------";CHR$(&amp;HA);
  PRINT #1, "PAID                   $60.00";CHR$(&amp;HA);
  PRINT #1, "CHANGE             $ 2.00";CHR$(&amp;HA);
  PRINT #1, CHR$(&amp;H1D);"V";CHR$(66);CHR$(0); 'Feeds paper &amp; cut
  
  ’Drawer Kick (ESC p)
  
  PRINT #1, CHR$(&amp;H1B); CHR$(&amp;H70); CHR$(&amp;H0); CHR$(60); CHR$(120); 
  </code></pre>