Solved

For Loop doesn;t reference the correct object

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

13 Experts available now in Live!

Get 1:1 Help Now