Shefali 0 Light Poster

hello all
i m having a really silly problem. i have written some codes with mscomm, but i dont know why all of a sudden i m having this problem.

the problem is:

Private Sub Form_Load()
     With MSComm1
           .Commport=1
           .Settings="19200,N18,1"
           .InputLen=0
           .PortOpen=True '(Here the error message says that the port is  
                                   'already open, but if i dont use this and try to
                                   ' send something to the serial port it says
                                   ' port not open)
     End With
End Sub

i dont know what the problem is. if i say portopen=true it says already open. i even tried to check by
if mscomm1.portopen =true then mscomm1.portopen=false.

still no result.
kindly suggest.
regards. shefali

Dani AI

Generated

For — a focused troubleshooting checklist and a few practical fixes for the MSComm symptom where the port appears to be both open and closed.

First checks (no code required)

  • Verify no other program holds the COM port: close terminal apps and device utilities. Use Process Explorer (Find Handle) or Sysinternals tools to search for the COM name if needed.
  • Look in Device Manager under "Ports (COM & LPT)" to confirm which COM number is assigned and that the driver is healthy. Unplug/replug USB-serial adapters and power-cycle the device.
  • In the VB project, confirm the MSComm control does not have PortOpen set at design time. Open the form properties and make sure PortOpen is False before runtime.

Runtime and code-side checks

  • Set CommPort and a correctly formatted Settings string before opening the port; the Settings format is comma-separated (for example, baud,parity,data bits,stop bits). Ensure the string uses commas and valid values.
  • Add a deterministic cleanup path so the port is always closed: clear or close PortOpen inside form unload/error handlers. The IDE can leave a handle open if a run is terminated abruptly, so graceful close on shutdown prevents stale locks.
  • If problems persist, test the same COM port with a known terminal program (PuTTY/Tera Term) to isolate hardware/driver issues from application logic.

If none of the above fixes it, reinstall the serial driver or try a different COM number. Capturing the OnComm error/CommEvent values during failure will provide a definitive next diagnostic step.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.