Author Topic: Q: how to get a single control to use indexed drivers  (Read 1121 times)

Chipprogr

  • Newbie
  • *
  • Posts: 10
    • View Profile
Q: how to get a single control to use indexed drivers
« on: February 03, 2016, 04:10:44 PM »
HI there,

   I am needing a little help please. I have an application Im writing in VS 2015 that will use a single control that needs to then connect to the appropriate PLC.
essentially I am trying to do this...
DrumNo is an Integer
My drivers are named EthernetIPforSLCMicroCom1 to EthernetIPforSLCMicroCom10

TempController1.CommComponent = EthernetIPforSLCMicroCom(DrumNo)
but I cannot figure out the syntax to allow indexing of the 10 plc addresses.

Thanks for the help - Eric



dmroeder

  • Global Moderator
  • Full Member
  • *****
  • Posts: 207
    • View Profile
Re: Q: how to get a single control to use indexed drivers
« Reply #1 on: February 03, 2016, 04:51:14 PM »
Use a select case or if statements:

If DrumNo = 1 Then TempController1.CommComponent = EthernetIPforSLCMicroCom1
If DrumNo = 2 Then TempController1.CommComponent = EthernetIPforSLCMicroCom2

and so on.

I've never tried swapping drivers while running, not sure if there is any error handling you have to do but above is how you would reassign.

Chipprogr

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Q: how to get a single control to use indexed drivers
« Reply #2 on: February 03, 2016, 05:05:43 PM »
Thanks, I know I can get it to work that way but I want to find a cleaner , less code way.

I was hoping to use something like directcast but I cannot get the syntax to work out.

-Eric

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Q: how to get a single control to use indexed drivers
« Reply #3 on: February 03, 2016, 06:25:48 PM »
Dustin beat me to a solution. I was going to propose a Select-Case like this:

        Select Case DrumNo
            Case 1
                TempController1.CommComponent = EthernetIPforCLXCom1
            Case 2
                TempController1.CommComponent = EthernetIPforCLXCom2
        End Select




If you wanted to treat the drivers as an array, you would need to create an array, then assign each driver instance like this
Code: [Select]
Private Drivers(10) As AdvancedHMIDrivers.IComComponent

Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Drivers(0) = EthernetIPforCLXCom1
    Drivers(1) = EthernetIPforCLXCom2
.
.
.
End Sub

From there you could use similar code like you had:


TempController1.CommComponent = Drivers(DrumNo)

dmroeder

  • Global Moderator
  • Full Member
  • *****
  • Posts: 207
    • View Profile
Re: Q: how to get a single control to use indexed drivers
« Reply #4 on: February 04, 2016, 11:07:36 AM »
If you wanted to treat the drivers as an array, you would need to create an array, then assign each driver instance like this
Code: [Select]
Private Drivers(10) As AdvancedHMIDrivers.IComComponent

Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Drivers(0) = EthernetIPforCLXCom1
    Drivers(1) = EthernetIPforCLXCom2
.
.
.
End Sub

From there you could use similar code like you had:


TempController1.CommComponent = Drivers(DrumNo)

That's a good idea there.