Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello code project..
Below code is my function to get my timeline in twitter..

VB
Dim Tweets As List(Of String) = parseTweets("hazeleekaizera")
    Private Function fetchData(ByVal Url As String) As String
        Dim callBack As String = New System.Net.WebClient().DownloadString(New Uri(Url))
        Return IIf(Not String.IsNullOrEmpty(callBack), callBack, String.Empty)
    End Function
    Function parseTweets(ByVal Username As String) As List(Of String)
        Dim tmpList As New List(Of String)
        Dim callBack As String = fetchData(String.Format("http://twitter.com/{0}", Username))

        If Not String.IsNullOrEmpty(callBack) Then
            Dim Tweets As MatchCollection = New Regex("\<p class=""js-tweet-text tweet-text""\>(.+)\<\/p\>").Matches(callBack)
            If Not Tweets Is Nothing Then
                For Each Tweet As Match In Tweets
                    tmpList.Add(Tweet.Groups(1).Value)
                Next
                Return tmpList
            End If
        Else
            Return Nothing
        End If
    End Function


And using timer1.tick event every 2 second my textbox1.text will filled with my twitter timeline.

VB
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    For Each Tweet As String In Tweets
        Dim TweetText As String = New Regex("\<a href="".*?\<s\>\@\<\/s\>\<b\>(.*?)\<\/b\>\<\/a\>").Replace(Tweet, "@$1").Trim
        '// Replacing all trash tags around @mentions leaving just the mention!
        TweetText = New Regex("\<a href="".*?\<s\>#\<\/s\>\<b\>(.*?)\<\/b\>\<\/a\>").Replace(TweetText, "#$1").Trim
        '// Replacing all trash tags around #hashtags leaving just the hashtag!
        TweetText = New Regex("<a href="".*?\<\/a\>").Replace(TweetText, String.Empty).Trim
        '// Remove all remaining trash tags e.g. links/youtube/images
        TweetText = HtmlDecode(TweetText)
        TextBox1.Text += (TweetText)
    Next
End Sub


but my problem when i create new tweet in my twitter account.
my textbox1.text can't display my update tweet he still display my old tweet.
so to handle this problem i use timer2.tick event by restart the app every 10 second.

VB
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Application.Restart()
    End Sub


i need help how to make my textbox1.text can automate update tweet every 10 second without having to perform application restart? anybody have idea to solve my problem?
Posted

1 solution

Your second timer is silly - get rid of it.

The following should solve your problem ...

a) Make sure that textbox1 is defined as Multiline

b) Ensure that the textbox1 is big enough or more sensibly has ScrollBars = True

c) Add a System.Environment.NewLine to TweetText before adding it to the textbox (to make sure each tweet is on a separate line, not disappearing off to the right of the textbox)

d) Position the cursor at the bottom of the text box each time (if it scrolls or there is too much data for the size)
VB
TextBox1.Text += (TweetText) + System.Environment.NewLine
'this moves the cursor to the bottom
textBox1.SelectionStart = textBox1.Text.Length
textBox1.ScrollToCaret()


[EDIT - see OP comments, still not working]
Try putting a breakpoint on For Each Tweet As String In Tweets When your code breaks hover over Tweets and check the bit that says "Count=x" - make sure there is something in the List.

If it says "Count=0" then you will need to examine your function parseTweets()
If it says "Count=1" (or more) then step onto the next line and have a look at TweetText ... if that is blank then it could be your regex that's at fault
 
Share this answer
 
v3
Comments
Gun Gun Febrianza 16-Nov-13 13:51pm    
ok i will try it again sir... report soon :)
Gun Gun Febrianza 16-Nov-13 14:00pm    
sirr i did application restart to make my textbox1.text can detect my new tweet on my twitter account timeline. without application restart my textbox1.text only display first time data of mytimeline. so how to make my textbox1.text could display my new time at specific time using timer without restart my app?
CHill60 16-Nov-13 14:11pm    
Try putting Tweets = parseTweets("hazeleekaizera") at the top of your Timer1_Tick event - you need to refresh the list on a regular basis. You should probably increase the time between ticks as 2 seconds is a bit extreme :-)
Gun Gun Febrianza 16-Nov-13 14:19pm    
hehehe okay i will try it :) thanks for help me again and again..
Gun Gun Febrianza 16-Nov-13 14:24pm    
hmmm still cannot display my new tweet sir.. :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900