Results 1 to 2 of 2

Thread: [2005] Delegates?

  1. #1

    Thread Starter
    Hyperactive Member OMITT3D's Avatar
    Join Date
    Mar 2006
    Posts
    368

    [2005] Delegates?

    VB Code:
    1. Imports System.Xml
    2.  
    3. ''' <summary>
    4. ''' Digg Notify
    5. ''' This program sends a quick pop up when someone has dugg one of your stories.  When it hits FP it will stop monitoring.
    6. ''' </summary>
    7. '''
    8.  
    9. Public Class frmMain
    10.     Private rand As New Random
    11.     Public objXMLDoc As New XmlDocument
    12.     Dim objNode As System.Xml.XmlNode
    13.     Dim strPath = Application.StartupPath & "\Config.ini"
    14.     Dim arrDiggCount(100) As String
    15.     Dim strSliceMsg As String = ""
    16.     Dim i As Integer = 0
    17.     Dim j As Integer = 0
    18.     Dim strCheckHmpg(100) As String
    19.     Dim bolCheck As Boolean = False
    20.  
    21.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    22.         txtUser.Text = INIRead(strPath, "Config", "User", "Username")
    23.         numStories.Text = INIRead(strPath, "Config", "NumStories", "15")
    24.         numMinDiggs.Text = INIRead(strPath, "Config", "MinDiggs", "0")
    25.     End Sub
    26.  
    27.     Private Sub tmrUpdate_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrUpdate.Tick
    28.         'Dim Thread As New System.Threading.Thread(AddressOf DiggUpdate)
    29.         'Thread.IsBackground = True
    30.         'Thread.Priority = Threading.ThreadPriority.Normal
    31.         'Thread.Start()
    32.         DiggUpdate()
    33.     End Sub
    34.  
    35.     Private Delegate Sub DiggUpdateDelegate()
    36.     Public Sub DiggUpdate()
    37.         Try
    38.             i = 0
    39.             objXMLDoc.Load("http://digg.com/rss/" & txtUser.Text & "/index1.xml")
    40.             For Each elemOut As Xml.XmlElement In objXMLDoc.GetElementsByTagName("item")
    41.                 For Each elemIn As Xml.XmlElement In elemOut.GetElementsByTagName("digg:diggCount")
    42.                     arrDiggCount(i) = elemIn.ChildNodes(0).InnerText
    43.                     i = i + 1
    44.                 Next elemIn
    45.             Next elemOut
    46.  
    47.             i = 0
    48.             lstStories.Items.Clear()
    49.  
    50.             For Each objNode In objXMLDoc.SelectNodes("rss/channel/item")
    51.                 If i < numStories.Text Then
    52.                     If INIRead(strPath, txtUser.Text, objNode.SelectSingleNode("title").InnerText, "") = "" Then
    53.                         INIWrite(strPath, txtUser.Text, objNode.SelectSingleNode("title").InnerText, arrDiggCount(i))
    54.                     End If
    55.  
    56.                     If arrDiggCount(i) > 30 And INIRead(strPath, "Ignored", objNode.SelectSingleNode("title").InnerText, "0") <> 1 Then
    57.                         strCheckHmpg(i) = objNode.SelectSingleNode("title").InnerText
    58.                         bolCheck = True
    59.                     End If
    60.  
    61.                     If INIRead(strPath, txtUser.Text, objNode.SelectSingleNode("title").InnerText, "") <> arrDiggCount(i) And INIRead(strPath, "Ignored", objNode.SelectSingleNode("title").InnerText, "0") <> 1 And INIRead(strPath, "Config", "MinDiggs", "0") <= arrDiggCount(i) Then
    62.  
    63.                         Dim strTitle As String = objNode.SelectSingleNode("title").InnerText
    64.                         If strTitle.Length > 40 Then
    65.                             strTitle = strTitle.Substring(0, 40) & "..."
    66.                         End If
    67.  
    68.                         INIWrite(strPath, txtUser.Text, objNode.SelectSingleNode("title").InnerText, arrDiggCount(i))
    69.                         strSliceMsg = strSliceMsg & strTitle & "(" & arrDiggCount(i) & ")" & vbCrLf
    70.                     End If
    71.  
    72.                     If INIRead(strPath, "Ignored", objNode.SelectSingleNode("title").InnerText, "0") = 1 Then
    73.                         lstStories.Items.Add("(" & arrDiggCount(i) & ") " & objNode.SelectSingleNode("title").InnerText & " [Ignored]")
    74.                     Else
    75.                         lstStories.Items.Add("(" & arrDiggCount(i) & ") " & objNode.SelectSingleNode("title").InnerText)
    76.                     End If
    77.                 Else
    78.                     Exit For
    79.                 End If
    80.  
    81.                 i = i + 1
    82.             Next
    83.             If strSliceMsg <> "" Then
    84.                 Dim slice As New frmToast(Me.rand.Next(5000, 10000), strSliceMsg)
    85.                 slice.Height = Me.rand.Next(150, 150)
    86.                 slice.Show()
    87.                 strSliceMsg = ""
    88.             End If
    89.             i = 0
    90.             If bolCheck = True Then
    91.                 objXMLDoc.Load("http://digg.com/rss/containertechnology.xml")
    92.                 For Each objNode In objXMLDoc.SelectNodes("rss/channel/item")
    93.                     Do Until i > numStories.Text
    94.                         If objNode.SelectSingleNode("title").InnerText = strCheckHmpg(i) Then
    95.                             INIWrite(strPath, "Ignored", strCheckHmpg(i), "1")
    96.                             Dim slice As New frmToast(Me.rand.Next(5000, 10000), objNode.SelectSingleNode("title").InnerText & " Hit FP!")
    97.                             slice.Height = Me.rand.Next(150, 150)
    98.                             slice.Show()
    99.                             strCheckHmpg(i) = ""
    100.                         End If
    101.                         i = i + 1
    102.                     Loop
    103.                     i = 0
    104.                 Next
    105.                 bolCheck = False
    106.             End If
    107.             i = 0
    108.         Catch ex As Exception
    109.         End Try
    110.  
    111.  
    112.     End Sub
    113.  
    114.     Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
    115.         If tmrUpdate.Enabled = True Then
    116.             tmrUpdate.Enabled = False
    117.             btnStart.Text = "Start"
    118.         Else
    119.             tmrUpdate.Enabled = True
    120.             btnStart.Text = "Pause"
    121.         End If
    122.         If INIRead(strPath, "Config", "User", "") <> txtUser.Text Then
    123.             INIWrite(strPath, "Config", "User", txtUser.Text)
    124.         End If
    125.     End Sub
    126.  
    127.     Private Sub btnIgnore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIgnore.Click
    128.         INIWrite(strPath, "Ignored", lstStories.SelectedItem, "1")
    129.     End Sub
    130.  
    131.     Private Sub btnUnignore_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUnignore.Click
    132.         INIWrite(strPath, "Ignored", lstStories.SelectedItem, "0")
    133.     End Sub
    134.  
    135.     Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    136.         INIRead(strPath, "Config", "NumStories", numStories.Text)
    137.         INIWrite(strPath, "Config", "MinDiggs", numMinDiggs.Text)
    138.     End Sub
    139. End Class

    Can someone help me with the cross thread errors when I uncomment threading? Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Delegates?

    There are numerous examples of accessing control members via delegation already posted on the forum. Search for "invokerequired" with my user name and you'll find several, plus I'm sure others have posted too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width