FULL Visual Basic 6.0 Enterprise Edition With Serial - BL4CKH4ND [2022-Latest]
z Hi Guys, just started with VB 6 yesterday. Anyone out there that can help me with a problem. I am trying to use a serial port with VB6 and when I press the button to send data to the device it just displays the serial input in VB and the data is never sent to the device. Any help would be great. Thanks and regards, Andy A:Vb6 Serial Port Having done quite a bit with VB6, I'd guess you're not sending the right number of bytes. When a serial port is open in VB6, it creates a handle to a COM port. The port is usually set to a null-terminated string, so you'd expect your code to say something like this: OpenSerialPort(Null) A string of no characters. OpenSerialPort reads each character until it reaches the Null terminator and assigns it to a variable. This is a serious flaw in the design of COM port programming. Once the serial port is opened, the port is no longer available for use by other applications. You may or may not want to do things like this: SerialPort1.Write(strText) SerialPort1.Close() That closes the COM port but doesn't free up any resources (such as the serial port handle). This is typically a bad idea. If you had the user do it, you can add a Shutdown() method to the COM port (look at 'doc file COM1_Shutdown) but you'd probably want to allow the user to cancel this by using the CancelAsync() method (look at 'doc file COM1_CancelAsync). Just because VB6 is a serial port doesn't mean the user should be able to write anything to the serial port. If you don't want that kind of interaction, don't open the serial port. Is there a chance that you are trying to send the string strText to a serial port with the format "COM2" (ie, no port number)? If that is the case, you have to explicitly specify the port number when you open the port. The OpenSerialPort method, when used with the SerialPort1 argument, should take the port number and look something like this: OpenSerialPort "COM2" If the port number needs to be a String, you could use the port's Driver Property to get it.