Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

For Loop doesn;t reference the correct object

Posted on 2009-04-06
1
Medium Priority
?
143 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

886 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