none
VB6 to VB2012

    Question

  • Hello

    Can anyone help me to translate this code to visual studio 2010, I am having a hard time finding the equivalent code. 

    MScomm1.output = "L"

    thanks :P


    janinepaule

    Tuesday, June 26, 2012 4:13 PM

Answers

All replies

  • The replacment is the SerialPort class: 

    http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx

    It's Write method is probably what you're looking for.


    Armin

    Tuesday, June 26, 2012 4:17 PM
  • I believe that "MScomm1" is referring to an old MSCOMM control which is not naturally part of .Net.

    You'll either need to add a refernece to the library containing that control or refactor the code to use a SerialPort component (preferrably the latter).


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, June 26, 2012 4:19 PM
  •  do i have to declare anything to use this method?

    janinepaule

    Tuesday, June 26, 2012 4:20 PM
  • Yes, it is.

    Can I still use it or is there any equivalent code?


    janinepaule

    Tuesday, June 26, 2012 4:22 PM
  • You need to declare a variable of type SerialPort.

    Armin

    Tuesday, June 26, 2012 4:28 PM
  • You need to declare a variable of type SerialPort.

    Armin

    this is my code declaring the serialport. Sorry for bothering you guys, I really dont have any background with Visual Basic :)) Thanks to your help :)

    Dim comport As System.IO.Ports.SerialPort = _
            New System.IO.Ports.SerialPort
            comport.BaudRate = 9600
            comport.PortName = "COM1"
            comport.Open()

    How can I declare the write method? I think it was really the equivalent code of the MScomm.output.

     

    janinepaule

    Tuesday, June 26, 2012 4:39 PM
  • I don't know if it is possible to keep using it - the Interop and Upggrade forum would be a more appropriate place for that question:

    http://social.msdn.microsoft.com/Forums/en/vbinterop/threads

    Refactoring to use a SerialPort component means more than just changing a line of code or two... you'd probably have to restructure the application.  But that is the correct route as the upgrade process from VB6 to .Net is not streamlined or efficient when it comes to larger or complex projects (it might work ok for very simple projects).  In the end you will want to rewrite this app in order to get the best performance from the code.

    There are lots of serial port examples here on the forums and in the MSDN library.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, June 26, 2012 4:44 PM
  • You don't have to declare it, just call it:

     comport.Write("L")

    Be aware to choose the right encoding when sending Strings. That means, a String is converted to a sequence of bytes sent to the serial port. The default encoding is ASCII which is a 7 bit code (no values > 127). If you want to change it, set the Encoding property, for example to UTF8 encoding:

        comport.encoding = system.text.encoding.utf8

    You must know in advance which encoding is expected by the receipient of the data.


    Armin



    Tuesday, June 26, 2012 5:05 PM
  • You can still use the Microsoft Comm Control in .NET (limited to 32-bit), or the Windows API if you prefer:

    How to access serial and parallel ports by using Visual Basic .NET


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, June 26, 2012 7:00 PM
  • Hi japu,

    it's now time to learn SerialPort. Here is a beginners code sample: http://code.msdn.microsoft.com/SerialPort-Sample-in-VBNET-fb040fb2

    I hope this helps

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010

    Tuesday, June 26, 2012 7:09 PM
  • Hi japu,

    it's now time to learn SerialPort. Here is a beginners code sample: http://code.msdn.microsoft.com/SerialPort-Sample-in-VBNET-fb040fb2

    I hope this helps

    regards Ellen


    Ich benutze/ I'm using VB2008 & VB2010

    Thanks guys! This will be a big help :)

    janinepaule

    Tuesday, June 26, 2012 11:23 PM