更新或刷新我的变量 [英] Update or Refresh My Variable

查看:52
本文介绍了更新或刷新我的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello代码项目..

下面的代码是我在twitter上获取时间线的功能..



Hello code project..
Below code is my function to get my timeline in twitter..

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





每隔2秒钟使用timer1.tick事件,我的textbox1.text将填充我的推特时间线。





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

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





但是当我在我的Twitter帐户中创建新推文时我的问题。

我的textbox1.text无法显示我的更新推文他仍然显示我的旧推文。

所以为了解决这个问题,我每隔10秒钟重启应用程序就会使用timer2.tick事件。





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.

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





i需要帮助如何使我的textbox1.text可以每10秒自动更新一次推文,而不必重新启动应用程序?有人有想法解决我的问题吗?



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?

推荐答案

1)。修剪
' //更换@mentions周围的所有垃圾标签,只留下提及!
TweetText = Regex( \< a href =。*?\< s \> #\< \ / s\> \< b\>(?*)\< \ / b\> \< \ / a\> ;)。替换(TweetText,
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 )。修剪
' //更换#hashtags周围的所有垃圾标签,只留下标签!
TweetText = 正则表达式( < a href =。*?\< \ / a \ >)。替换(TweetText,字符串 .Empty).Trim
' //删除所有剩余的垃圾标签,例如链接/ youtube / images
TweetText = HtmlDecode(TweetText)
TextBox1.Text + =(TweetText)
下一步
结束 Sub
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





但是当我在我的Twitter帐户中创建新推文时我的问题。

我的textbox1.text无法显示我的更新推文他仍然显示我的旧推文。

所以为了解决这个问题,我每隔10秒钟重启应用程序就会使用timer2.tick事件。





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.

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





i需要帮助如何使我的textbox1.text可以每10秒自动更新一次推文,而不必重新启动应用程序?有谁有想法解决我的问题?



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?


你的第二个计时器很傻 - 摆脱它。



以下应该解决你的问题...



a)确保textbox1定义为Multiline



b)确保textbox1足够大或更明智地拥有ScrollBars = True



c)将System.Environment.NewLine添加到TweetText,然后将其添加到文本框中(以确保每条推文都是在一个单独的行上,不会消失在文本框的右侧)



d)每次将光标定位在文本框的底部(如果它滚动或在那里太大的数据了)

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)
TextBox1.Text += (TweetText) + System.Environment.NewLine
'this moves the cursor to the bottom
textBox1.SelectionStart = textBox1.Text.Length
textBox1.ScrollToCaret()







尝试在上为每个推文添加一个断点作为推文中的字符串当你的代码中断悬停在推文并检查Count = x位 - 确保列表中有内容。



如果显示Count = 0,那么你需要检查你的函数 parseTweets()

如果它显示Count = 1(或更多),那么进入下一行并查看TweetText ...如果那是空白那么它可能是你的正则错误




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


这篇关于更新或刷新我的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆