I am fascinated by this thread.
It implies that kimiraikkonen routinely uses "For Each..." rather than
iterating through array indices.
I started programming on early forms of BASIC that pre-dated the inclusion
of "For Each... ". In fact I think they pre-dated UBOUND for that matter :-)
I find it intriguing that newer programmers would start with "For Each" and
then go back to learning an index-based method. A bit like learning to drive
on an automatic transmission car then moving to a manual, I suppose :-)
--
David Streeter
Synchrotech Software
Sydney Australia
[quoted text, click to view] "kimiraikkonen" wrote:
> On Jan 28, 4:52 pm, "\(O\)enone" <oen...@nowhere.com> wrote:
> > kimiraikkonen wrote:
> > > The problem is: I want to see the last line of text file ordered/
> > > sorted as the "first" item in my combobox like the philosophy "the
> > > last text line must be the most recent item for my combobox"? How can
> > > i do this?
> >
> > The way I would solve this is to use the IO.File.ReadAllLines() function to
> > read the text file into memory. This returns an array of strings, each one
> > of which will correspond to a line within the file. (This is effectively the
> > same as your ReadAllText() and then Split() calls, but in less code). Then
> > you can simply loop through the array backwards and add each line to the
> > textbox as you read it:
> >
> > \\\
> > Dim i As Integer
> > Dim strs() As String
> >
> > strs = IO.File.ReadAllLines("history.txt")
> >
> > For i = UBound(strs) To 0 Step -1
> > combobox1.Items.Add(strs(i))
> > Next
> > ///
> >
> > HTH,
> > --
> >
> > (O)enone
>
> (O)enone, that worked. However it was an interesting idea to sort
> items by creating a string array, then the key point was to use
> "UBound" and "Step" inside a for-next loop. Thank you.
[quoted text, click to view] On 2008-01-28, \(O)enone <oenone@nowhere.com> wrote:
> kimiraikkonen wrote:
>> The problem is: I want to see the last line of text file ordered/
>> sorted as the "first" item in my combobox like the philosophy "the
>> last text line must be the most recent item for my combobox"? How can
>> i do this?
>
> The way I would solve this is to use the IO.File.ReadAllLines() function to
> read the text file into memory. This returns an array of strings, each one
> of which will correspond to a line within the file. (This is effectively the
> same as your ReadAllText() and then Split() calls, but in less code). Then
> you can simply loop through the array backwards and add each line to the
> textbox as you read it:
>
> \\\
> Dim i As Integer
> Dim strs() As String
>
> strs = IO.File.ReadAllLines("history.txt")
>
> For i = UBound(strs) To 0 Step -1
> combobox1.Items.Add(strs(i))
> Next
> ///
>
> HTH,
I would simplify this even farther.... You can completely do away with
the loop....
Dim strs() As String = IO.File.ReadAllLines("history.txt")
Array.Reverse (strs)
combobox1.Items.AddRange (strs)
HTH
--