Solved

For Loop doesn;t reference the correct object

Posted on 2009-04-06
1
135 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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