Solved

For Loop doesn;t reference the correct object

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
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 …

810 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