Hi bernbomb, you're receiving this error because the ItemID "400" doesn't exist, see the following link with ItemID 400
http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=400
How to fix
replace
Code:
text = GetItemValue("400")
with
Code:
text = GetItemValue("1119")
Explanation/random talking
You can see if something is wrong with the sourcecode by browsing to the url in a webbrowser, or having a textbox show your variable "sourcecode" and browse through it there.
alternatively if you do a simple "msgbox(newvalue)" after
Code:
Dim NewValue As String = GetBetween(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>", "</tr>")
to
Code:
Dim NewValue As String = GetBetween(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>", "</tr>")
msgbox(newvalue)
and/or between the lines where you are modifying it, you can see the results(blank)
How to get ItemID's
Replace 400 with a proper ItemID, If you don't know how to get an ItemID, go to the Grand Exchange via webbrowser and search for an item, I'll search for "Steel platebody" and we'll use "Steel platebody" as the example.
Code:
Right-click the picture OR the text link and click one of the following.
1. copy image location (Firefox)
2. copy link location (Firefox)
OR
3. properties (Internet Explorer)
4. copy shortcut (Internet Explorer)
The links you should have gotten are:
[url]http://services.runescape.com/m=itemdb_rs/Steel_arrow/viewitem.ws?obj=1119[/url]
[url]http://services.runescape.com/m=itemdb_rs/3892_obj_sprite.gif?id=1119[/url]
so we see that 1119 is our item ID, replace
Code:
text = GetItemValue("400")
with
Code:
text = GetItemValue("1119")
just like we did before.
The ID's can be found in the page source too, of course. - And forgive me if you already knew how to get the numbers - i just assumed you don't.
More random shiz
I don't understand the purpose of the following lines though, getting the price works without it, and what is newvalue(0) supposed to represent because it has no value.
Code:
NewValue = Replace(NewValue, NewValue(0), vbNullString)
You'll also notice that since your variable "text" is integer it will remove commas from "1,232" etc, to prevent this you'll want to make it a string instead.
------------------------------------------
now I'm just being picky, this is how I'd do it, does essentially the same thing but with more simpler functions, webclient doesn't allow as much control as httpwebrequest - but that's fine because we won't be needing to edit the cookie, referrer, etc.
Code:
Public Function GetItemValue(ByRef ItemID As Integer)
Dim Amount As String, webbrw As New Net.WebClient, sourcecode As String
sourcecode = webbrw.DownloadString("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" & ItemID)
Dim NewValue As String = Replace(Split(Split(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>")(1), "</td>")(0), "<td>", "")
'replaced the second splits "</tr>" with "</td>" for one less replace
'if you really dont want every split/replace to be together then just uncomment this
'Dim NewValue As String = Split(Split(sourcecode, "<th scope=" & Chr(34) & "row" & Chr(34) & ">Current guide price:</th>")(1), "</td>")(0)
' NewValue = Replace(NewValue, "<td>", "")
Amount = NewValue
Return Amount
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim text As String
text = GetItemValue("1119")
TextBox1.Text = text
End Sub
So what you've posted has the potential to give information about one item, do you plan on customizing it a bit? IE; viewing other items, not just one set in code? Do you have an idea how to do it?
I'll be posting a project very soon, depending on when i get time to finish it.