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 7807539
In Process

The Archive Base Latest Questions

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

I am converting a VB.NET project to C# and I got stuck on this

  • 0

I am converting a VB.NET project to C# and I got stuck on this if-loop, could anyone help me convert this? I am assuming that i’ll need to use the GetType()-method for this but I’m not sure how.

The Loop:

Private Sub oOpcGroup_DataChange(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles() As Integer, ByRef ItemValues() As Object, ByRef Qualities() As Integer, ByRef TimeStamps() As Date)

    Dim i As Integer

    For i = 1 To NumItems
        If VarType(ItemValues(i)) And Not VariantType.Array Then
            txtSubValue.Text = ItemValues(i)
        Else
            MsgBox("Data type return error, returned array, expected single item", MsgBoxStyle.Critical, "Data Change Error")
            Exit Sub
        End If
    Next i
    Exit Sub
End Sub

This is what I have so far:

void oOpcGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)    //Events OPCGroup
    {

        for (int i = 0; i < NumItems; i++)
        {
            if(){

            }
            else
            {
                MessageBox.Show("Expected single item.", "Data type return error.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

    }
  • 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:52:56+00:00Added an answer on June 2, 2026 at 2:52 am

    Here is what I came up with, using the GetType() instead of the Information.VarType.

    I did replace the MsgBox method call with a call to System.Windows.Forms.MessageBox.Show.

    private void oOpcGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)  
    {
    
        for (int i = 0; i < NumItems; i++)
        {
            var obj = ItemValues.GetValue(i);
    
            if (obj != null && !obj.GetType().IsArray)
            {
                txtSubValue.Text = obj.ToString();
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Data type return error, returned array, expected single item", "Data Change Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help converting a VB.NET handles statement to C#. This is the VB
Consider the scenario of upgrading an ASP.NET MVC project. This question is around up-converting
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
While converting a project that used SlimDX, and therefore has unmanaged code, to .NET
I am considering converting a project that I've inherited from .net 1.1 to .net
I have this function in vb.net that I converted from C# for a project
I'm converting one of our ASP.NET MVC application from 1.0 to 2.0. This is
I am converting a script from PHP to ASP.net C#. In PHP, i could
I am converting an old html based website to ASP.NET, so that we can
I'm having trouble converting a C# Linq statement to VB.NET. I need the following

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.