Re: Help with Array(s)

From: SStory (TheStorys_at_TAKEOUTTHISSPAMBUSTERsofthome.net)
Date: 03/16/04


Date: Tue, 16 Mar 2004 13:25:50 -0600

Wow,
I would think XML would return in something with an XML schema and you could
use that to build a dataset from it easily. But will take your word for it.

no matter what you do, do this
      For Each oRec In oRs
> sValue1 = oRec.Item("Value1") 'String Value
> iValue2 = cInt(oRec.Item("Value2")) 'make an int

Then when you add it will be sorted as a number and do as you like.

You could
dim x(2,n) where n is number of records and then sort that

Array.Sort sorts one-dimentional arrays, but don't think it will 2dim arrays
like this one.

Or you could use a sortedlist--again don't know how many records you are
talking about.

You could use a Datatable if it is a lot of records.. just depends

sortedlist:
so if you want list sorted by number and the other is a key then you could
use the first as the key and number as the value and it would be sorted

Depends on what you want to do.

Help sample for sortedlist, taken from vb.net help
=====================================
Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

Public Class SamplesSortedList

    Public Shared Sub Main()

        ' Creates and initializes a new SortedList.
        Dim mySL As New SortedList()
        mySL.Add("First", "Hello")
        mySL.Add("Second", "World")
        mySL.Add("Third", "!")

        ' Displays the properties and values of the SortedList.
        Console.WriteLine("mySL")
        Console.WriteLine(" Count: {0}", mySL.Count)
        Console.WriteLine(" Capacity: {0}", mySL.Capacity)
        Console.WriteLine(" Keys and Values:")
        PrintKeysAndValues(mySL)
    End Sub

    Public Shared Sub PrintKeysAndValues(myList As SortedList)
        Console.WriteLine(ControlChars.Tab & "-KEY-" & ControlChars.Tab & _
           "-VALUE-")
        Dim i As Integer
        For i = 0 To myList.Count - 1
            Console.WriteLine(ControlChars.Tab & "{0}:" & ControlChars.Tab &
_
               "{1}", myList.GetKey(i), myList.GetByIndex(i))
        Next i
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
'
' mySL
' Count: 3
' Capacity: 16
' Keys and Values:
' -KEY- -VALUE-
' First: Hello
' Second: World
' Third: !

Let me know if this helps any....
Don't know if your first value is a unique key or what... Assume you want
to sort list by second int value and display.
Still if you can import XML into dataset which should be easy if you have
the schema I'd think, then that would be the easiest way by far.

Shane

"Rich Wallace" <rich.wallace@minusthecannedmeat.jfsheadotcom> wrote in
message news:%23WELNH3CEHA.2052@TK2MSFTNGP11.phx.gbl...
> Thank you Shane...
>
> We're using Verastream Host adapter from WRQ to connect to our AS400. My
> app in in VB.NET but their most current DLL was written in VB6..soon in
.NET
> so that will help in the future.
>
> The output from a passed in query returns a 'recordset' that the WRQ folks
> define so I current use the following code to loop through it:
>
> --------------------------------------------------------------------------

--
> ------------------------
>         Dim oRs As Interop_AppConnLib.AppConnRecordSet
>         Dim oRec As Interop_AppConnLib.AppConnRecord
>         Dim sQry As String
>
>         sQry = "myQuery"
>
>         Try
>             oRs = oVHA.ExecuteSQLStatement(sQry)
>
>             For Each oRec In oRs
>                 sValue1 = oRec.Item("Value1") 'String Value
>                 sValue2 = oRec.Item("Value2") 'String Value that I'd like
to
> convert to Int and then sort both values against
>
>                 '...do other work based on values returned
>
>             Next
>
>             oRs = Nothing
>         Catch ex As Exception
>             MsgBox(ex.Message
>         End Try
> --------------------------------------------------------------------------
--
> ------------------------
>
> The WRQ tool will return the data back to XML but the structure is so
> complex, it would take an hour or two just to code for theri structe to
use
> it.
>
> Please let me know if you need anything else.
>
> -Rich
>
> "SStory" <TheStorys@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
> news:uM9hMA3CEHA.1688@TK2MSFTNGP12.phx.gbl...
> > Rich,
> >
> > Hmm..
> > Would love to find out about how you are connecting to AS400.
> > Is there not a good .NET solution to connect to AS400 or do you need 3rd
> > party?
> >
> > Anyhow, for your question.
> >
> > You say recordset...so does that mean you are using ADO?  If so are you
> > using VB6?  If that is true you should ask that newsgroup.  If not and
you
> > are using ADO.NET, then,
> >
> > There are mainly datareaders and datasets.
> > How many rows of data are you expecting to have returned?  A lot of just
a
> > few?
> >
> > 1.)  If you were to use that "recordset" to build a dataset, you could
> sort
> > it I think.
> >
> > 2.) Or if you were going to convert from your "recordset" to an array,
why
> > not just convert the 2nd item to Integer using
> > either CInt(2nd fieldvalue) or ctype(2ndfieldvalue,Integer) to do that,
> then
> > you could easily sort numerically and correctly.
> >
> > Arrays
> > =====
> > There are many flavors of arrays in dotnet and classes for arrays.
> > ArrayList
> > SortedArrayList
> > etc.
> >
> > I think SortedArrayList, may or may not be the best choice for large
> amounts
> > of data so again, how many rows max do you expect to be putting in an
> array?
> >
> > Yes, you can take your data and stuff it into something in .NET and sort
> it
> > but really could use more information first. Such as the questions that
I
> > have asked.
> >
> > Hope to be of Help,
> >
> > Shane
> >
> > "Rich Wallace" <rich.wallace@minusthecannedmeat.jfsheadotcom> wrote in
> > message news:%2316buu2CEHA.4080@TK2MSFTNGP09.phx.gbl...
> > > Hi all,
> > >
> > > I've scanned over previous posts but I'm still not feeling comfortable
> > with
> > > making a decision on using an Array or a Structure for what I need to
> do.
> > > If someone can point me in the right direction, I would truly
appreciate
> > it.
> > >
> > > I have a RecordSet from third-party solution which queries an IBM
AS400
> > and
> > > contains the following records:
> > >
> > > 1 - "A", "900000.00"
> > > 2 - "B", "950000.00"
> > > 3 - "C", "1000000.00"
> > >
> > > When I retrieve the recordset, I need to have the data sorted by the
> > second
> > > value and loop through the records and perform other tasks based on
the
> > > current record.  The problem is, the tool only sends me text or string
> > > values back instead of an integer, so I can't do an order by (SQL
> > statement
> > > based query) on the second value as it will put the "1000000.00" value
> > first
> > > instead of "900000.00".  I understand that I can perform some kind of
> Sort
> > > against an array and I thought maybe I could send both values within
> each
> > > record to an Array and use that to loop though but I've never used
> Arrays
> > > before so I'm a bit lost.
> > >
> > > Can somebody help??
> > >
> > > TIA
> > > -Rich
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: Hash of hashes, of hashes, of arrays of hashes
    ... >>> I'm trying to create a data structure that will make it ... >>> easier to create a series of slightly different XML documents. ... >> string for that inner block, ... >a child that has no arrays. ...
    (comp.lang.perl.misc)
  • Re: Another Flex/VMS example - Browsing the ACCOUNTNG.DAT file
    ... XML) certainly works there.) ... if you specified the sortOn method using Array.NUMERIC the array will be sorted using a numeric sort instead of a string sort. ... My example use the AMF protocol which is native in Flex ... Send me email with a valid email and I will give you access to the repository. ...
    (comp.os.vms)
  • Re: sorting a dataset
    ... Ideally, I would like to return the data in structured hierarchical xml, eg: ... I know I can copy my dataset into a dataview and sort the ... >> are sorting a dataview. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: sorting a dataset
    ... Ideally, I would like to return the data in structured hierarchical xml, eg: ... I know I can copy my dataset into a dataview and sort the ... >> are sorting a dataview. ...
    (microsoft.public.dotnet.xml)
  • Re: does C# have any collection objects that support sort functionality so that I dont have to writ
    ... the IComparable interface. ... Also, since arrays are strongly typed, you know that all elements are of the ... for ArrayLists. ... The Sort() method will utilize each object's IComparable ...
    (microsoft.public.dotnet.languages.csharp)