Solved

For Loop doesn;t reference the correct object

Posted on 2009-04-06
1
133 Views
Last Modified: 2012-05-06
I have an arraylist that is created with a variable number of CurrCOMPort

When I go into the SendRequestCommand() sub I always seem to have my indicatorPort referencing to my last added in  CurrCOMPort #.

How Can I ahve it so that it loops through all comport and the indicatorPort refences the correct serial object?
Private WithEvents IndicatorPort As IO.Ports.SerialPort

 Public Sub Indicator_COM()

        Dim intloop As Integer

        'Dim IndicatorCOMPort As String

        For intloop = 0 To ActiveCOM.Count - 1

            IndicatorPort = New IO.Ports.SerialPort

            IndicatorPort.PortName = "COM" & ActiveCOM(intloop)

            IndicatorPort.BaudRate = 57600

            IndicatorPort.DataBits = 8

            IndicatorPort.Parity = IO.Ports.Parity.None

            IndicatorPort.StopBits = IO.Ports.StopBits.One

            IndicatorPort.Open()

            CurrCOMPort.Add(IndicatorPort)

        Next

    End Sub
 
 

 Public Sub SendRequestCommand()

        Dim intloop As Integer

        For intloop = 0 To CurrCOMPort.Count - 1

            IndicatorPort.Write("[REQ]")

        Next
 

    End Sub

Open in new window

0
Comment
Question by:cmdolcet
1 Comment
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 24080899
Wow... that shouldn't have even compiled.
Use this:
        For intloop = 0 To CurrCOMPort.Count - 1
            IndicatorPort = CurrCompPort.Item(intloop)
            IndicatorPort.Write("[REQ]")
        Next
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now