By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,236 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Refreshing the data in an XMLReader object

P: n/a
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.C ount - 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(i ntCurrentRow).ChildNodes(0
).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1
).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).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.
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents mnuMain As System.Windows.Forms.MainMenu

Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem

Friend WithEvents tmrScroll As System.Windows.Forms.Timer

Friend WithEvents lblTicker As System.Windows.Forms.RichTextBox

Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem

Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Me.mnuMain = New System.Windows.Forms.MainMenu()

Me.MenuItem1 = New System.Windows.Forms.MenuItem()

Me.MenuItem4 = New System.Windows.Forms.MenuItem()

Me.MenuItem5 = New System.Windows.Forms.MenuItem()

Me.MenuItem7 = New System.Windows.Forms.MenuItem()

Me.MenuItem2 = New System.Windows.Forms.MenuItem()

Me.tmrScroll = New System.Windows.Forms.Timer(Me.components)

Me.lblTicker = New System.Windows.Forms.RichTextBox()

Me.MenuItem3 = New System.Windows.Forms.MenuItem()

Me.SuspendLayout()

'

'mnuMain

'

Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem1, Me.MenuItem5})

'

'MenuItem1

'

Me.MenuItem1.Index = 0

Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem4})

Me.MenuItem1.Text = "&File"

'

'MenuItem4

'

Me.MenuItem4.Index = 0

Me.MenuItem4.Text = "Exit"

'

'MenuItem5

'

Me.MenuItem5.Index = 1

Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.MenuItem7, Me.MenuItem2, Me.MenuItem3})

Me.MenuItem5.Text = "&Application"

'

'MenuItem7

'

Me.MenuItem7.Index = 0

Me.MenuItem7.Text = "A&bout"

'

'MenuItem2

'

Me.MenuItem2.Index = 1

Me.MenuItem2.Text = "&Configuration"

'

'tmrScroll

'

Me.tmrScroll.Enabled = True

'

'lblTicker

'

Me.lblTicker.BorderStyle = System.Windows.Forms.BorderStyle.None

Me.lblTicker.Dock = System.Windows.Forms.DockStyle.Fill

Me.lblTicker.Font = New System.Drawing.Font("Courier New", 8.25!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))

Me.lblTicker.Multiline = False

Me.lblTicker.Name = "lblTicker"

Me.lblTicker.ReadOnly = True

Me.lblTicker.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None

Me.lblTicker.Size = New System.Drawing.Size(824, 12)

Me.lblTicker.TabIndex = 0

Me.lblTicker.Text = ""

'

'MenuItem3

'

Me.MenuItem3.Index = 2

Me.MenuItem3.Text = "Stock &Watchlist"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(824, 12)

Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblTicker})

Me.ForeColor = System.Drawing.SystemColors.ControlLight

Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWind ow

Me.MaximizeBox = False

Me.Menu = Me.mnuMain

Me.MinimizeBox = False

Me.Name = "Form1"

Me.ShowInTaskbar = False

Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual

Me.Text = "Virtual Airline Stock Market - Stock Ticker"

Me.TopMost = True

Me.ResumeLayout(False)

End Sub

#End Region

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.C ount - 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(i ntCurrentRow).ChildNodes(0
).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1
).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).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

Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem4.Click

'Exit Program

End

End Sub

Private Sub MaintainSize(ByVal frmTicker As Form)

Dim BoundRec As Rectangle = Screen.GetBounds(frmTicker)

Me.Width = BoundRec.Width

Me.Height = 64

Me.Left = 0

Me.Top = 0

End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

'Set the ticker to be 10 pixels less than the window size.

lblTicker.Width = Me.Width - 10

Dim temp As New Form()

MaintainSize(temp)

End Sub

Private Sub tmrScroll_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tmrScroll.Tick

If lblTicker.Text = "" Then

lblTicker.Text = strTickerText

Else

lblTicker.Text = Mid(lblTicker.Text, 2)

End If

Dim temp As New Form()

MaintainSize(temp)

End Sub

Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem7.Click

'Load about form

Dim AboutForm As New About()

AboutForm.Show()

End Sub

Private Sub MenuItem2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem2.Click

intTickerSpeed = InputBox("Please enter the speed for the ticker (characters
per interval):")

tmrScroll.Interval = intTickerSpeed

End Sub

Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuItem3.Click

End Sub

End Class

"Angus Lepper" <CE*@AngusEnterprises.cjb.net> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...
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.C ount - 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(i ntCurrentRow).ChildNodes(0 ).InnerText

strCurrentStockPrice =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).ChildNodes(1 ).InnerText

strCurrentStockChange =
xmlReader.ChildNodes(0).ChildNodes(1).ChildNodes(i ntCurrentRow).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.

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.