danucalovj

Stocks/XML Parsing (working)

Jan 11th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.78 KB | None | 0 0
  1. Imports System.Xml
  2.  
  3. Public Class Form1
  4.  
  5.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  6.        
  7.         Dim symlist = "aapl,goog,aeo,gs,anr"
  8.         Dim symarr() = symlist.Split(",")
  9.         getQuotes(symarr)
  10.  
  11.         For Each row As DataGridViewRow In DataGridView1.Rows
  12.             If CDbl(row.Cells(3).Value.ToString) < 0 Then
  13.                 row.Cells(3).Style.BackColor = Color.Red
  14.             Else
  15.                 row.Cells(3).Style.BackColor = Color.Green
  16.             End If
  17.             If CDbl(row.Cells(4).Value.ToString) < 0 Then
  18.                 row.Cells(4).Style.BackColor = Color.Red
  19.             Else
  20.                 row.Cells(4).Style.BackColor = Color.Green
  21.             End If
  22.  
  23.         Next
  24.  
  25.     End Sub
  26.     Public Sub getQuotes(ByVal arr() As String)
  27.  
  28.         For Each n As String In arr
  29.             Dim doc As XmlDocument
  30.  
  31.             ' Create a new XmlDocument  
  32.             doc = New XmlDocument()
  33.  
  34.             ' Load data
  35.             Dim XMLString As String = "http://dev.markitondemand.com/Api/Quote?symbol=THESYMBOL"
  36.             XMLString = XMLString.Replace("THESYMBOL", n)
  37.             doc.Load(XMLString)
  38.             'Read Data
  39.             Dim xmlreader1 = New XmlNodeReader(doc)
  40.             Dim data1 As String = ""
  41.  
  42.             While xmlreader1.Read()
  43.  
  44.                 Select Case xmlreader1.NodeType
  45.                     Case XmlNodeType.Text
  46.                         If Not xmlreader1.Value = "SUCCESS" Then
  47.                             data1 = data1 & xmlreader1.Value & ","
  48.                         End If
  49.  
  50.                 End Select
  51.  
  52.             End While
  53.             Dim data1array = data1.Split(",")
  54.             DataGridView1.Rows.Add(data1array)
  55.  
  56.         Next
  57.  
  58.     End Sub
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment