Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:28:28+00:00 2026-06-02T02:28:28+00:00

I am converting a Windows Form from VB to C# and I ran in

  • 0

I am converting a Windows Form from VB to C# and I ran in to an error when I attempted to do a synchronized read of my OPC tags.

I have this code:

public partial class FrmPartialMain : Form
{   
    RsiOPCAuto.OPCServer oOpcServer;
    RsiOPCAuto.OPCGroup oOpcGroup;

    int ClHandle; //this is set to 1 in another part of the code.
    int SvHandle;


    int OpcDsCashe = 1;
    int OpcDsDevice = 2;
    private void cmdSyncRead_Click(object sender, EventArgs e)
    {
        int lNumItems = oOpcGroup.OPCItems.Count; // = 3
        int[] h = new int[lNumItems];
        Array arValues = new int[lNumItems];
        Array arHandles;
        Array arErrors;
        object Qualities;
        object Timestamps;


        h[ClHandle - 1] = oOpcGroup.OPCItems.Item(ClHandle).ServerHandle;  
        arHandles = (Array)h;
        //Error on the next line bellow.
        oOpcGroup.SyncRead((short)OpcDsDevice, lNumItems, ref arHandles, out arValues, out arErrors, out Qualities, out Timestamps);


        txtSubValue.Text = Convert.ToString(arValues.GetValue(0));
    }
}

oOpcGroup.Read() reads the value, quality and timestamp information for one or more items in a group. and the return type looks like this:

 SyncRead(short Source, int NumItems, ref System.Array ServerHandles, out System.Array Values, out System.Array Errors, out object Qualities, out object TimeStamps);

Running this code gives me the error in the title, Value Does not fall within the expected range. Any ideas of what i might be doing wrong here?

Brainstorm away!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:28:30+00:00Added an answer on June 2, 2026 at 2:28 am

    It’s alive!

    This is the fixed code:

    public partial class FrmPartialMain : Form
    {   
        RsiOPCAuto.OPCServer oOpcServer;
        RsiOPCAuto.OPCGroup oOpcGroup;
    
        int ClHandle; //this is set to 1 in another part of the code.
        int SvHandle;
    
    
        int OpcDsCashe = 1;
        int OpcDsDevice = 2;
        private void cmdSyncRead_Click(object sender, EventArgs e)                                                                                  //Sync Read
        {
            int lNumItems = oOpcGroup.OPCItems.Count;
            int[] arH = new int[1 + lNumItems];
            Array arValues = new object[1 + lNumItems]; //<-- This needed to be an object array.
            Array arHandles;
            Array arErrors;
            object Qualities;
            object Timestamps;
    
            arH[ClHandle] = oOpcGroup.OPCItems.Item(ClHandle).ServerHandle;
    
            arHandles = (Array)arH;
            oOpcGroup.SyncRead((short)OpcDsDevice, lNumItems, ref arHandles, out arValues, out arErrors, out Qualities, out Timestamps);
    
            txtSubValue.Text = Convert.ToString(arValues.GetValue(1));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem, when converting Windows application from .NET2.0 to .NET3.5. I do this
I am converting several VBA projects to Windows form applications. The only problem I
I am currently converting what was a Console Application into a Windows Form application.
I am converting a program from C to C++. I have the compiler set
I am from a c# background and am converting a vb.net windows forms app
I am inserting data from a Windows Forms form into an SQL database as
i have a PictureBox in my Windows Form application and i am in the
I have a remoting application (2 player Magic the Gathering Game) using windows form
When converting from Unix to Windows, I get the correct output; however, when going
I am currently converting a Windows Form application to ios. The windows implementation uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.