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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:40:16+00:00 2026-06-09T20:40:16+00:00

Hey all i am trying to get my array in the correct format to

  • 0

Hey all i am trying to get my array in the correct format to be placed into an ASP.net webpage for a table for an order.

The order should be:

model_number
comm_category
service
freight
sales_tax
sales
unit_price
price
id_price

Currently it is outputting as this:

model_number
price
unit_price
id_price
sales_tax
sales
service
freight
comm_category

And because of this i am unable to append to my string in the correct order using my code here:

Public Sub AssocArray_To_String(ByRef Output As System.Text.StringBuilder, ByVal AssocArrayInput As AssocArray)
    For iParent As Integer = 0 To AssocArrayInput.Count - 1
        Dim intX As Integer = 0
        Dim arrParent As AssocArray = TryCast(AssocArrayInput.Item(iParent), AssocArray)
        If arrParent Is Nothing Then Continue For

        For iChild As Integer = 0 To arrParent.Count - 1
            Call buildItems(PHPConvert.ToString(arrParent.Keys(iChild)), PHPConvert.ToString(arrParent.Values(iChild)), intX)
            intX += 1
        Next iChild
    Next iParent
End Sub

Private Sub buildItems(ByVal nameOfItem As String, ByVal itemItself As String, ByVal intX As Integer)
    Dim tmpStuff As Decimal = 0.0
    Dim qty As Integer = 1
    Dim model_number As String = ""
    Dim comm_category As String = ""
    Dim service As Double = 0
    Dim freight As Double = 0
    Dim sales_tax As Double = 0
    Dim sales As Double = 0
    Dim unit_price As Double = 0
    Dim price As Double = 0
    Dim id_price As Double = 0

    If nameOfItem = "model_number" Then
        model_number = itemItself
        tableLoop += "<tr><td bgcolor=""#CCCCCC""><asp:Label ID=""item_count_" & intX & """ Text=""Label"">" & qty & "</asp:Label></td>"
        tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""model_number_" & intX & """ Text=""Label"">" & model_number & "</asp:Label></td>"
    ElseIf nameOfItem = "comm_category" Then
        comm_category = itemItself
        tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""comm_category_" & intX & """ Text=""Label"">" & comm_category & "</asp:Label></td>"
    ElseIf nameOfItem = "service" Then
        service = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""service_" & intX & """ Text=""Label"">" & service & "</asp:Label></td>"
    ElseIf nameOfItem = "freight" Then
        freight = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td><asp:Label ID=""freight_" & intX & """ Text=""Label"">" & freight & "</asp:Label></td>"
    ElseIf nameOfItem = "sales_tax" Then
        sales_tax = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td><asp:Label ID=""sales_tax_" & intX & """ Text=""Label"">" & sales_tax & "</asp:Label></td>"
    ElseIf nameOfItem = "sales" Then
        sales = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""sales_" & intX & """ Text=""Label"">" & sales & "</asp:Label></td>"
    ElseIf nameOfItem = "unit_price" Then
        unit_price = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td bgcolor=""#CCCCCC""><asp:Label ID=""unit_price_" & intX & """ Text=""Label"">" & unit_price & "</asp:Label></td></tr>"
    ElseIf nameOfItem = "price" Then
        price = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td><asp:Label ID=""amount_" & intX & """ Text=""Label"">" & price & "</asp:Label></td>"
    ElseIf nameOfItem = "id_price" Then
        id_price = Format(Convert.ToDouble(itemItself), "$######.00")
        tableLoop += "<td><asp:Label ID=""id_price_" & intX & """ Text=""Label"">" & id_price & "</asp:Label></td>"
    End If
End Sub

The end results are this:

<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>

Which should output like this:

<tr><td bgcolor="#CCCCCC"><asp:Label ID="item_count_0" Text="Label">1</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="model_number_0" Text="Label">TTN491-7BW</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="comm_category_5" Text="Label">X24</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="service_6" Text="Label">51</asp:Label></td>
<td><asp:Label ID="freight_7" Text="Label">384</asp:Label></td>
<td><asp:Label ID="sales_tax_3" Text="Label">290.37</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="sales_1" Text="Label">3084.63</asp:Label></td>
<td bgcolor="#CCCCCC"><asp:Label ID="unit_price_8" Text="Label">3135.63</asp:Label></td></tr>
<td><asp:Label ID="amount_2" Text="Label">3810</asp:Label></td>
<td><asp:Label ID="id_price_4" Text="Label">3810</asp:Label></td></tr>

How can i put the array in the correct order?

  • 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-09T20:40:18+00:00Added an answer on June 9, 2026 at 8:40 pm

    Why aren’t you just simply referencing the items you need directly, instead of looping through the associative keys (which come back in arbitrary order):

    Dim arrParent As AssocArray = TryCast(AssocArrayInput.Item(iParent), AssocArray)
    If arrParent Is Nothing Then Continue For
    
    Call buildItems("model_number", PHPConvert.ToString(arrParent.Values("model_number")), intX)
    Call buildItems("comm_category", PHPConvert.ToString(arrParent.Values("model_number")), intX)
    Call buildItems("service", PHPConvert.ToString(arrParent.Values("model_number")), intX)
    Call buildItems("freight", PHPConvert.ToString(arrParent.Values("model_number")), intX)
    'ETC
    

    Or better yet, just get rid of BuildItems altogether and inline the logic in the appropriate places above.

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

Sidebar

Related Questions

Hey all i am trying to use my already array that i populated into
Hey all I'm trying to get a window populated with a table view that
Hey all i am trying to get my code below to work in order
Hey all, i have a problem with trying to get 2 forms to close
Hey all. Trying to get a little more efficient with lists in Python but
Hey all, i am trying to get my bottom bar to center on the
Hey all, I've been trying to get a series of objects to appear that
Hey all. Im trying to sort out how to get MATLAB running as best
Hey all i am trying to get the value from this code: <DIV id=lcm_simlive_countdown>00
Hey guys I've been trying all day to get an ant file to automatically

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.