A
Angus Lepper
I'm writing a stock ticker for a stock market simulation, and can load the
data into the xmlreader in the first place, but can't figure out how to
refresh/update the data in it. Any ideas?
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
'Dataset used to read data in from files
Dim dsTicker As New DataSet("Ticker")
'XML Reader used to read data from dataset and
'handle it
Dim xmlReader As New Xml.XmlDataDocument()
'Path to xml file
Const strTickerPath = "http://www.vastock.com/raw/ticker.xml"
'String used to hold xml read from file, to pass to the xml reader
Dim strCurrentXML As String
'Strings used to hold information about the stock
Dim strCurrentStockName As String
Dim strCurrentStockPrice As String
Dim strCurrentStockChange As String
'Integer used to loop through records
Dim intCurrentRow As Integer = 0
Dim intCurrentLoop
Dim intTickerSpeed As Integer = 100
Dim strTickerText As String
Dim strWatchListOn As Boolean
Dim strWatchList As String
Dim strWatchListData As String
Dim i As Long
Dim WatchArray As Array
[Snipped autogen form designer code]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Show loading window
Dim LoadingForm As New Loading()
LoadingForm.Show()
'Set the ticker to be 10 pixels less than the window size.
lblTicker.Width = Me.Width - 10
'Refresh Ticker
LoadTickerData()
InsertTickerData()
'Set size
Me.Width = Screen.FromControl(Me).GetWorkingArea(Me).Width
tmrScroll.Interval = intTickerSpeed
'Set the ticker to be 10 pixels less than the window size.
lblTicker.Width = Me.Width - 10
Dim temp As New Form()
MaintainSize(temp)
LoadingForm.Close()
End Sub
Private Sub InsertTickerData()
strWatchList = ""
For intCurrentLoop = 1 To
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes.Count - 1
'Load data into strings, using indices to navigate - 0 being the first node
meaning:
'xmlReader.ChildNodes(0) is navigating to the <ticker> element
'xmlReader.ChildNodes(0).ChildNodes(1) is navigating to the <data> element
'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(0) is navigating to the
<entry> element
'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(0).ChildNodes(n) is
navigating to:
'0 = Stock Name
'1 = Stock Price
'2 = Stock Price Change
'Then .InnerText simply reads the data from that node.
strCurrentStockName =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(0
).InnerText
strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(1
).InnerText
strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(2
).InnerText
If strWatchListOn = "1" Then
For i = 0 To WatchArray.GetUpperBound(0)
If strCurrentStockName = WatchArray(i) Then
strWatchList &= strCurrentStockName
strWatchList &= " Price: v$" & strCurrentStockPrice
strWatchList &= " Change: v$"
strWatchList &= " | "
End If
Next
End If
lblTicker.Text &= strCurrentStockName
lblTicker.Text &= " Price: v$" & strCurrentStockPrice
lblTicker.Text &= " Change: " & strCurrentStockChange
lblTicker.Text &= " | "
intCurrentRow = intCurrentRow + 1
Next
strTickerText = lblTicker.Text
End Sub
Private Sub LoadTickerData()
'Read the xml file into the dataset
dsTicker.ReadXml(strTickerPath)
'Set the string to the ACTUAL XML - not the data
strCurrentXML = dsTicker.GetXml
'Load that string/xml into the xmlReader for handling
xmlReader.LoadXml(strCurrentXML)
End Sub
I'll attach the full code in a message below this one.
data into the xmlreader in the first place, but can't figure out how to
refresh/update the data in it. Any ideas?
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
'Dataset used to read data in from files
Dim dsTicker As New DataSet("Ticker")
'XML Reader used to read data from dataset and
'handle it
Dim xmlReader As New Xml.XmlDataDocument()
'Path to xml file
Const strTickerPath = "http://www.vastock.com/raw/ticker.xml"
'String used to hold xml read from file, to pass to the xml reader
Dim strCurrentXML As String
'Strings used to hold information about the stock
Dim strCurrentStockName As String
Dim strCurrentStockPrice As String
Dim strCurrentStockChange As String
'Integer used to loop through records
Dim intCurrentRow As Integer = 0
Dim intCurrentLoop
Dim intTickerSpeed As Integer = 100
Dim strTickerText As String
Dim strWatchListOn As Boolean
Dim strWatchList As String
Dim strWatchListData As String
Dim i As Long
Dim WatchArray As Array
[Snipped autogen form designer code]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Show loading window
Dim LoadingForm As New Loading()
LoadingForm.Show()
'Set the ticker to be 10 pixels less than the window size.
lblTicker.Width = Me.Width - 10
'Refresh Ticker
LoadTickerData()
InsertTickerData()
'Set size
Me.Width = Screen.FromControl(Me).GetWorkingArea(Me).Width
tmrScroll.Interval = intTickerSpeed
'Set the ticker to be 10 pixels less than the window size.
lblTicker.Width = Me.Width - 10
Dim temp As New Form()
MaintainSize(temp)
LoadingForm.Close()
End Sub
Private Sub InsertTickerData()
strWatchList = ""
For intCurrentLoop = 1 To
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes.Count - 1
'Load data into strings, using indices to navigate - 0 being the first node
meaning:
'xmlReader.ChildNodes(0) is navigating to the <ticker> element
'xmlReader.ChildNodes(0).ChildNodes(1) is navigating to the <data> element
'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(0) is navigating to the
<entry> element
'xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(0).ChildNodes(n) is
navigating to:
'0 = Stock Name
'1 = Stock Price
'2 = Stock Price Change
'Then .InnerText simply reads the data from that node.
strCurrentStockName =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(0
).InnerText
strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(1
).InnerText
strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(intCurrentRow).ChildNodes(2
).InnerText
If strWatchListOn = "1" Then
For i = 0 To WatchArray.GetUpperBound(0)
If strCurrentStockName = WatchArray(i) Then
strWatchList &= strCurrentStockName
strWatchList &= " Price: v$" & strCurrentStockPrice
strWatchList &= " Change: v$"
strWatchList &= " | "
End If
Next
End If
lblTicker.Text &= strCurrentStockName
lblTicker.Text &= " Price: v$" & strCurrentStockPrice
lblTicker.Text &= " Change: " & strCurrentStockChange
lblTicker.Text &= " | "
intCurrentRow = intCurrentRow + 1
Next
strTickerText = lblTicker.Text
End Sub
Private Sub LoadTickerData()
'Read the xml file into the dataset
dsTicker.ReadXml(strTickerPath)
'Set the string to the ACTUAL XML - not the data
strCurrentXML = dsTicker.GetXml
'Load that string/xml into the xmlReader for handling
xmlReader.LoadXml(strCurrentXML)
End Sub
I'll attach the full code in a message below this one.