Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to figure out how to get the values from this page into different text boxes:

http://hiscore.runescape.com/index_lite.ws?player=Lanc1988

 

Each of the values on that page are separated by commas so after some searching I read that I should use the String.Split(',') somehow but I can't figure it out. Could someone provide with me the easiest way of how to put the first value into a textbox (txtBox1) and the next value into txtBox2 and the third into txtBox3. Im sure I should be able to get the rest once I have an idea of how to start.

 

Thanks.

Posted

I wouldn't use TextBoxes unles you know there will never be any more values on the page than textboxes you have.

 

I'd do something like this.

 

String theData = "123,132,44,55,66,-1,-1,-1";

String[] scores = theData.Split(',');

listBox1.DataSource = scores;

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted
Ok. I think i'll use a ListView with the View set to Details since the listbox wont quite give me the look I need. I'm not sure how to do the first part that you put.. String theData = "........"; How do I have it use the webpage?
Posted (edited)

ok.. that helped but i must be missing something because when I click the button to do the code the program is only getting the first 3 scores and nothing else.. here is my code for the button:

 

       Dim ScoresURL As String = "http://hiscore.runescape.com/index_lite.ws?player=Lanc1988"

       Dim client As WebClient = New WebClient
       Dim data As Stream = client.OpenRead(ScoresURL)
       Dim reader As StreamReader = New StreamReader(data)

       Dim line, vals() As String

       line = reader.ReadLine
       vals = line.Split(",")

       ListView1.Items.Add("Overall")
       ListView1.Items(0).SubItems.Add(vals(0))
       ListView1.Items(0).SubItems.Add(vals(1))
       ListView1.Items(0).SubItems.Add(vals(2))
       ListView1.Items.Add("Attack")
       ListView1.Items(1).SubItems.Add(vals(3))
       ListView1.Items(1).SubItems.Add(vals(4))
       ListView1.Items(1).SubItems.Add(vals(5))
       ListView1.Items.Add("Defence")
       ListView1.Items(2).SubItems.Add(vals(6))
       ListView1.Items(2).SubItems.Add(vals(7))
       ListView1.Items(2).SubItems.Add(vals(8))
       ListView1.Items.Add("Strength")
       ListView1.Items(3).SubItems.Add(vals(9))
       ListView1.Items(3).SubItems.Add(vals(10))
       ListView1.Items(3).SubItems.Add(vals(11))
       ListView1.Items.Add("Hitpoints")
       ListView1.Items(4).SubItems.Add(vals(12))
       ListView1.Items(4).SubItems.Add(vals(13))
       ListView1.Items(4).SubItems.Add(vals(14))
       ListView1.Items.Add("Ranged")
       ListView1.Items(5).SubItems.Add(vals(15))
       ListView1.Items(5).SubItems.Add(vals(16))
       ListView1.Items(5).SubItems.Add(vals(17))
       ListView1.Items.Add("Prayer")
       ListView1.Items(6).SubItems.Add(vals(18))
       ListView1.Items(6).SubItems.Add(vals(19))
       ListView1.Items(6).SubItems.Add(vals(20))
       ListView1.Items.Add("Magic")
       ListView1.Items(7).SubItems.Add(vals(21))
       ListView1.Items(7).SubItems.Add(vals(22))
       ListView1.Items(7).SubItems.Add(vals(23))
       ListView1.Items.Add("Cooking")
       ListView1.Items(8).SubItems.Add(vals(24))
       ListView1.Items(8).SubItems.Add(vals(25))
       ListView1.Items(8).SubItems.Add(vals(26))
       ListView1.Items.Add("Woodcutting")
       ListView1.Items(9).SubItems.Add(vals(27))
       ListView1.Items(9).SubItems.Add(vals(28))
       ListView1.Items(9).SubItems.Add(vals(29))
       ListView1.Items.Add("Fletching")
       ListView1.Items(10).SubItems.Add(vals(30))
       ListView1.Items(10).SubItems.Add(vals(31))
       ListView1.Items(10).SubItems.Add(vals(32))
       ListView1.Items.Add("Fishing")
       ListView1.Items(11).SubItems.Add(vals(33))
       ListView1.Items(11).SubItems.Add(vals(34))
       ListView1.Items(11).SubItems.Add(vals(35))
       ListView1.Items.Add("Firemaking")
       ListView1.Items(12).SubItems.Add(vals(36))
       ListView1.Items(12).SubItems.Add(vals(37))
       ListView1.Items(12).SubItems.Add(vals(38))
       ListView1.Items.Add("Crafting")
       ListView1.Items(13).SubItems.Add(vals(39))
       ListView1.Items(13).SubItems.Add(vals(40))
       ListView1.Items(13).SubItems.Add(vals(41))
       ListView1.Items.Add("Smithing")
       ListView1.Items(14).SubItems.Add(vals(42))
       ListView1.Items(14).SubItems.Add(vals(43))
       ListView1.Items(14).SubItems.Add(vals(44))
       ListView1.Items.Add("Mining")
       ListView1.Items(15).SubItems.Add(vals(45))
       ListView1.Items(15).SubItems.Add(vals(46))
       ListView1.Items(15).SubItems.Add(vals(47))
       ListView1.Items.Add("Herblore")
       ListView1.Items(16).SubItems.Add(vals(48))
       ListView1.Items(16).SubItems.Add(vals(49))
       ListView1.Items(16).SubItems.Add(vals(50))
       ListView1.Items.Add("Agility")
       ListView1.Items(17).SubItems.Add(vals(51))
       ListView1.Items(17).SubItems.Add(vals(52))
       ListView1.Items(17).SubItems.Add(vals(53))
       ListView1.Items.Add("Thieving")
       ListView1.Items(18).SubItems.Add(vals(54))
       ListView1.Items(18).SubItems.Add(vals(55))
       ListView1.Items(18).SubItems.Add(vals(56))
       ListView1.Items.Add("Slayer")
       ListView1.Items(19).SubItems.Add(vals(57))
       ListView1.Items(19).SubItems.Add(vals(58))
       ListView1.Items(19).SubItems.Add(vals(59))
       ListView1.Items.Add("Farming")
       ListView1.Items(20).SubItems.Add(vals(60))
       ListView1.Items(20).SubItems.Add(vals(61))
       ListView1.Items(20).SubItems.Add(vals(62))
       ListView1.Items.Add("Runecraft")
       ListView1.Items(21).SubItems.Add(vals(63))
       ListView1.Items(21).SubItems.Add(vals(64))
       ListView1.Items(21).SubItems.Add(vals(65))
       ListView1.Items.Add("Hunter")
       ListView1.Items(22).SubItems.Add(vals(66))
       ListView1.Items(22).SubItems.Add(vals(67))
       ListView1.Items(22).SubItems.Add(vals(68))
       ListView1.Items.Add("Construction")
       ListView1.Items(23).SubItems.Add(vals(69))
       ListView1.Items(23).SubItems.Add(vals(70))
       ListView1.Items(23).SubItems.Add(vals(71))
       ListView1.Items.Add("Summoning")
       ListView1.Items(24).SubItems.Add(vals(72))
       ListView1.Items(24).SubItems.Add(vals(73))
           ListView1.Items(24).SubItems.Add(vals(74))

Edited by Lanc1988
Posted
I see the reason.. if you look at the webpage, the numbers are in groups of 3.. the 3 numbers are separated by commas but each set of 3 is separated by a space.. what do I need to change in my code to fix this?
Posted

I highly recommend that you use the DataSource property of the listbox, don't waste time doing this

.Items.Add(value);

 

Something roughly like this will help you with the spaces in your data.

 

List<int> liTheScores = new List<int>(50);
String theData = "123,132,44 55,66,-1 -1,-1,84";

String[] trios = theData.Split(' ');

foreach(string sTrio in trios)
{
   String[] scores = sTrio.Split(','); 
   foreach(string sScore in scores)
       liTheScores.Add((int)sScore);
}    

listBox1.DataSource = liTheScores;

 

You may also want to change

line = reader.ReadLine

to

AllData = reader.ReadToEnd();

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted (edited)

Use 2 Arrays Start by Splitting the input on a space. this will result in an array that contains the groups of 3 values.

You can then split each of those in turn on the comma.

        Dim line, vals() As String
Dim SubVals() as String
       line = reader.ReadLine
       vals = line.Split(" ")

       ListView1.Items.Add("Overall")
SubVals = Vals(0).Split(",")
       ListView1.Items(0).SubItems.Add(SubVals(0))
       ListView1.Items(0).SubItems.Add(SubVals(1))
       ListView1.Items(0).SubItems.Add(SubVals(2))
       ListView1.Items.Add("Attack")
SubVals = Vals(1).Split(",")
       ListView1.Items(1).SubItems.Add(SubVals(0))
       ListView1.Items(1).SubItems.Add(SubVals(1))
       ListView1.Items(1).SubItems.Add(SubVals(2))
       ListView1.Items.Add("Defence")
	SubVals = Vals(2).Split(",")
       ListView1.Items(2).SubItems.Add(SubVals(0))
       ListView1.Items(2).SubItems.Add(SubVals(1))
       ListView1.Items(2).SubItems.Add(SubVals(2))
'And so on

You may event want to make an array of the Items so you can just loop through the values.

 

[edit]Nate posted while I was typing[/edit]

Edited by roger_wgnr
Posted (edited)

thanks roger.. the code you posted helped me alot. but im still having a slight problem.. it seems like it isn't actually a space between the sets of three. if you view the source of the page it is showing each set of three on a new line. does anyone know what it might be? i tried vbtab and Environment.NewLine but that didn't work either.

 

heres the code.. only the first entry in the listview is right.. all the rest are the same as the first one:

       Dim ScoresURL As String = "http://hiscore.runescape.com/index_lite.ws?player=Lanc1988"

       Dim client As WebClient = New WebClient
       Dim data As Stream = client.OpenRead(ScoresURL)
       Dim reader As StreamReader = New StreamReader(data)

       Dim line, vals() As String
       Dim SubVals() As String

       line = reader.ReadLine
       vals = line.Split(" ")

       ListView1.Items.Add("Overall")
       SubVals = vals(0).Split(",")
       ListView1.Items(0).SubItems.Add(SubVals(0))
       ListView1.Items(0).SubItems.Add(SubVals(1))
       ListView1.Items(0).SubItems.Add(SubVals(2))
       ListView1.Items.Add("Attack")
       SubVals = vals(1).Split(",")
       ListView1.Items(1).SubItems.Add(SubVals(0))
       ListView1.Items(1).SubItems.Add(SubVals(1))
       ListView1.Items(1).SubItems.Add(SubVals(2))
       ListView1.Items.Add("Defence")
       SubVals = vals(2).Split(",")
       ListView1.Items(2).SubItems.Add(SubVals(0))
       ListView1.Items(2).SubItems.Add(SubVals(1))
       ListView1.Items(2).SubItems.Add(SubVals(2))

Edited by Lanc1988
  • Leaders
Posted

Not sure exactly what is going on, but try something along the lines of:

vals = "".Split(New Char() {Chr(13), Chr(10)}, StringSplitOptions.RemoveEmptyEntries)

Some software and OS's will use a carriage return (13) for a newline, others use a line feed (10), and others (including windows) use a carriage return followed by a line feed. Fun, huh?

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...