6 Replies - 551 Views - Last Post: 03 October 2012 - 07:57 AM Rate Topic: -----

#1 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,920
  • Joined: 18-September 06

RSS Reader - Headlines Repeating

Posted 02 October 2012 - 03:55 AM

Hi guys,

I have an RSS Reader application designed to take a few headlines at random from an RSS feed and display them in a textbox. Currently, that all works fine, although it does have one annoying habit which I can't quite figure out. Because the headlines are selected at random, it is entirely possible that the same headline is displayed more than once. I'd like to find a way of preventing that.

Although I do not currently have any code for this, I have considered using an array to temporarily store the random numbers generated for selecting the headlines which can then be checked when the next random number is selected, and if the new random number is already in the array, it is discarded and another selected.

This sounds quite possible, but before I go ahead and put it together, I was wondering if anyone had any other, easier ideas? Not asking for code, I'll figure that out, just ideas of someplace to start. Or do you think I should proceed with my array idea?

Thanks :)
Bort

Is This A Good Question/Topic? 0
  • +

Replies To: RSS Reader - Headlines Repeating

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: RSS Reader - Headlines Repeating

Posted 02 October 2012 - 04:35 AM

Here is a snippet from AdamSpeight2008, where he removes the pick from temp list, before he makes new pick. That way the result is of distinct elements.

This post has been edited by lucky3: 02 October 2012 - 04:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,920
  • Joined: 18-September 06

Re: RSS Reader - Headlines Repeating

Posted 02 October 2012 - 04:38 AM

Ooh, nice Lucky3. Thanks :)

This post has been edited by Bort: 02 October 2012 - 04:38 AM

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: RSS Reader - Headlines Repeating

Posted 02 October 2012 - 05:16 AM

Note with that snippet, if they are entries that are the same there is a chance they'll appear in the output.
For example.
{1,2,2,3,3,3}.GetRandomPick(3) => {2,1,2}


If you need Distinct elements then consider using the Linq method .Distinct, with a lambda function to select which part to work over.
Remember that RSS is also XML, so you can use xml literals and linq over xml.

This post has been edited by AdamSpeight2008: 02 October 2012 - 05:17 AM

Was This Post Helpful? 0
  • +
  • -

#5 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,920
  • Joined: 18-September 06

Re: RSS Reader - Headlines Repeating

Posted 02 October 2012 - 08:14 AM

Hmm, thought I had replied here, but apparently not.

I think the snippet will work Adam, but thanks for the warning. If not, I'll come back and look at the Linq and Literals you mention.
Was This Post Helpful? 0
  • +
  • -

#6 Bort  Icon User is offline

  • Ill-informed Mongoloid
  • member icon

Reputation: 396
  • Posts: 2,920
  • Joined: 18-September 06

Re: RSS Reader - Headlines Repeating

Posted 03 October 2012 - 07:50 AM

I tried figuring out your snippet Adam, but was unsure of how to work it into my application, so I thought up another way of checking...

StartOver:
                        i = ran1.Next(results.Count - 1)
                        If lblHeadlines.Text.Contains(results(i).Description.ToString) Then
                            GoTo StartOver
                        End If
                        lblHeadlines.Text = lblHeadlines.Text & vbCrLf & vbCrLf & results(i).Description.ToString
                    Next z


Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: RSS Reader - Headlines Repeating

Posted 03 October 2012 - 07:57 AM

That's probably because that snippet has nothing to do with producing distinct elements. It allows you to pick a random subset (of the specified length) from the the input selection. Think about this if the count was the same as the number of items in the list, what does it return?

"ABCDEFGHIJKLMNOPQRSTUVWXYZ".GetRandomPick(4) => {"F"c,"A"c."C"c,"T"c}



Edit: Also it help you, if separate the DATA from the GUI. The xml rss feed is your data. Producing a distinct selection of that, shouldn't have anything to do with the gui.

This post has been edited by AdamSpeight2008: 03 October 2012 - 08:07 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1