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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:18:56+00:00 2026-06-04T03:18:56+00:00

EDIT Ok, so after working through this for a while, I’ve come up with

  • 0

EDIT

Ok, so after working through this for a while, I’ve come up with a solution that works, and it’s cleaner than I had originally thought up for it. Thanks for the help guys. Here’s the code.

Function Program_Search() As String()
    'An ArrayList of Objects containing strings for each row.
    'So the result is ArrayList(objRow1(strID, strPrograms), objRow2(strID, strPrograms).. etc)
    Dim program_results As ArrayList = Get_Results("SELECT ID, Programs FROM tbMetrics ORDER BY ID ASC", strConnectionString)

    'Initialize the list of programs. This will contian the tbMetrics Programs that match the selected Program name.
    Dim programs As ArrayList = New ArrayList

    'Loop through each row selected
    For Each row As Object In program_results
        'Not currently used.
        Dim strID As String = row(0).ToString

        'An integer representation of a binary number. Each digit represents a different program being checked.
        Dim intPrograms As Integer = CInt(row(1).ToString)

        'Convert number to binary string (reversed)
        Dim strReversed As String = StrReverse(Convert.ToString(intPrograms, 2))

        'Loop through each of the programs in the drop down box which should contain all of the possible choices in order.
        For index As Integer = 0 To ddlPrograms.Items.Count - 1
            'A bit of an ugly if state that checks for a 1 in the binary position for the selected program.
            'Then if it's selected, it checks that the program matches the one selected by the user.
            'Finally, it makes sure it doesn't add the same number to the array.
            If (strReversed.Length - 1) >= index _
                And strReversed(index) = "1" _
                And ddlPrograms.SelectedValue.ToString = ddlPrograms.Items(index).Value.ToString _
                And programs.Contains(intPrograms) = False Then

                'If it passes all of the above checks, then finally add the program integer to the arraylist.
                programs.Add(intPrograms)
            End If
        Next index
    Next row

    'Return the list of programs as an array, to be used with SQL IN().
    Return programs.ToArray
End Function

END EDIT

ORIGINAL BELOW

Ok, so I’m a PHP programmer, trying to learn some VB.NET. Arrays greatly confuse me in VB.NET, so I wrote some example code in PHP the way I know how to do it. I would greatly appreciate it if someoen could show me the proper way it would work in VB.NET.

<?php

function get_result() {
    $result = query("SELECT id, value FROM test_table");
    /*Returned as:
    array(
      array("id1", "value1"), 
      array("id2", "value2")...etc.
    )*/

    $haystack_top = array();

    foreach ($result as $row) {
        $id = $row[0]; //Not used currently
        $value = $row[1];

        for($i=0; $i <= $value; $i++) {
            if (check_value($i)) {
                $haystack_value = get_new_value($i);
                $haystack_top[$value][] = $haystack_value;
            }
        }
    }

    $needle = get_needle();

    $result = array();

    foreach ($haystack_top as $value=>$haystack) {
        if (in_array($needle, $haystack)) {
            $result[] = $value;
        }
    }

    return array_unique($result);
}

?>

Here’s an older, unfinished copy of what I’ve been working on in Vb.NET It’s not in the form I actually need because I changed how the logic should work while building the PHP example, but it shows the confusion I ran into with Arrays in VB.NET.

Function Program_Search() As String()
    Dim program_results As Object = Get_Results("SELECT ID, Programs FROM tbMetrics ORDER BY ID ASC", strConnectionString)

    'Create an array of strings to fill with potential field results.
    Dim fields As List(Of String) = New List(Of String)()

    For Each row As Object In program_results
        Dim strID As String = row(0).ToString
        Dim strPrograms As String = row(1).ToString

        Dim intPrograms As Integer = CInt(strPrograms)

        'Convert number to binary string (reversed)
        Dim strReversed As String = StrReverse(Convert.ToString(intPrograms, 2))

        For index As Integer = 0 To ddlPrograms.Items.Count - 1
            If (strReversed.Length - 1) >= index Then
                If strReversed(index) = "1" Then
                    fields.Add(ddlPrograms.Items(index).Value.ToString)
                End If
            End If
        Next index
    Next row

    Dim programs As String() = fields.ToArray

    Dim results As String()

    If programs.Contains(ddlPrograms.SelectedValue.ToString) Then

    End If

    Return programs
End Function

Because someone was curious about the Get_Results function here’s the code for that.

'Runs the passed query and returns each row as an object within an ArrayList
    Function Get_Results(ByVal query As String, ByVal ConnectionStringName As String) As ArrayList
        Dim sqlComm As Data.SqlClient.SqlCommand = Get_Connection(query, ConnectionStringName)

        'Open that connection
        sqlComm.Connection.Open()

        'Execute the query and store all of the results into the SqlDataReader.
        Dim sqlRead As Data.SqlClient.SqlDataReader = sqlComm.ExecuteReader()

        Dim result As ArrayList = New ArrayList

        'Read each row one by one.
        While sqlRead.Read()
            'Create an object of the size needed.
            Dim row(sqlRead.FieldCount - 1) As Object

            'Fill the row object with the values.
            sqlRead.GetValues(row)

            'Add the result object to the array.
            result.Add(row)
        End While

        'Close all open connections to the database.
        sqlRead.Close()
        sqlComm.Connection.Close()

        Return result
    End Function
  • 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-04T03:18:56+00:00Added an answer on June 4, 2026 at 3:18 am

    Based on this comment “…to be honest, I’m just confused how to properly create dynamic multi-dimensional arrays in VB.NET, and how to use them like I do in my PHP example…”, I’ll provide my answer.

    Your line:

     Dim fields As List(Of String) = New List(Of String)()
    

    creates a list, not an array. Lists are a bit easier to use as you can add items without having to resize. You could make a List(Of MyObject) if you would like to do that instead of a 2D array. Just create a class with two fields and make a list of those objects. Your class would be about 4 lines of code.

    To create a 2D array, which is what it looks like you’re doing, you should find everything you need here.

    http://msdn.microsoft.com/en-us/library/d2de1t93(v=vs.90).aspx

    Unfortunately, to create a dynamic 2D array, there’s no streamline way to do that. You have to copy the elements over to another array, if I’m not mistaken. It’s pretty lame, I know. That’s why I like the List(Of MyObject) approach in that you can just MyList.Add(myObject) when you create a new item.

    If you need to iterate through the items later to retrieve the values, you can just use a for-loop and access them as such:

    MyList(i).MyObjectPropertyName1
    MyList(i).MyObjectPropertyName2
    

    VB.NET is probably one of the more readable languages, but with any, you have to get used to it. I looked at your PHP and my head almost exploded. I’m sure if I took a couple hours and learned the syntax, it’d make (more) sense.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
[EDIT] I am changing this to more concisely explain what my problem was, after
How can I edit this to run only once after user scroll up: (function
Yeah, so this one through me or a loop for a while until I
I working my way through a C++ and Operating Systems book and I've come
I have been working through the CS106B course from Stanford, and while completing the
Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ Example calculation of nullable and first uses a
After-edit: Wow, this question go long. Please forgive =\ I am creating a new
This is a question that extends from the originally posted here: Link to loading-xaml
Edit note: After a seemingly enourmous amount of bad feedback MS got from their

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.