Jump to content
Cor3Quad

Visual basic

Recommended Posts

Vreau sa preiau niste date de pe un site (de forma <span id="epm_asd_1" class="bold">50</span>) si sa le afieseze in program..ii ceva de genu (mentionez ca nu ma pricep prea bine) :

label1 - preluat de pe un site

label2 = 0 => creste dupa ce porneste progressbar pana la "label1"

label3 - preluat de pe site

progressbar = trebuie sa mearga proportional si sa "dureze" random , in functie de label1(daca label1 = 100 ->1 minut).

exemplu :

Label1 = 50

label2 = 0 (tot timpu)

label3 = 20

Care ii problema :

Porneste progressbar-ul si "dureaza" 0,30 secunde ;

- label 2 trebe sa creasca pana la label 1(50) ;

Cum fac toate astea ? Progressbar-ul sa "dureze" o anumita durata de timp in functie de label 1 , label 2 sa creasca pana la label 1 si cum preiau datele de pe un site ?

Link to comment
Share on other sites


Imports System.Text.RegularExpressions

Button1 -> Care ia datele:

Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("[b][url]http://site.com/[/url][/b]")
Dim response As System.Net.HttpWebResponse = request.GetResponse

Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

Dim rssourcecode As String = sr.ReadToEnd

Dim r As New System.Text.RegularExpressions.Regex("[b]<span id=""epm_asd_1"" class=""bold"">50</span>[/b]")'[b] O Sa extraga ce este intre > si </[/b]
Dim matches As MatchCollection = r.Matches(rssourcecode)

For Each itemcode As Match In matches

label1.text = (itemcode.Value.Split("></").GetValue(1))
'System.Threading.Thread.Sleep(600)
Timer1.Start()

'TextBox1.RegexObj.Replace("subject", "replacement")
Next


Timer1--
Progressbar1.Value = progressbar1.value + 3
If Progressbar1.value = 99 Then
timer1.stop()
progressbar1.value = 100
timer1.stop() 'in caz ca nu se opreste cand trebuie

End If

[Mai Departe sper ca te descurci tu] !!

RegularExpression => adica codul html din care vrei sa extragi :


De exemplu : <span id="epm_asd_1" class="bold">50</span>

Sper ca ti-a fost de ajutor ! :D

Link to comment
Share on other sites

Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.1234.com/pages/")
Dim response As System.Net.HttpWebResponse = request.GetResponse

Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

Dim rssourcecode As String = sr.ReadToEnd

Dim r As New System.Text.RegularExpressions.Regex("<span id=""epm_ads_1"" class=""bold"">50</span>") ' O Sa extraga ce este intre > si </
Dim matches As MatchCollection = r.Matches(rssourcecode)

For Each itemcode As Match In matches

Label5.Text = (itemcode.Value.Split("></").GetValue(1))
'System.Threading.Thread.Sleep(600)


'TextBox1.RegexObj.Replace("subject", "replacement")
Next
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value = ProgressBar1.Value + 3
ProgressBar1.Increment(1)
Label6.Text = ProgressBar1.Value & (" % ")
If ProgressBar1.Value = 100 Then
Label6.Text = "Done"
Timer1.Stop()
End If
End Sub
End Class

Timer-ul l-am mai adaptat eu , problema ii ca nu primesc nimic de pe site + ca se blocheaza cateva secunde cand dau sa preia datele.

Edited by Cor3Quad
Link to comment
Share on other sites

cum sa primesti ceva de pe site daca nu e nimic de primit?

http://www.1234.com/pages/

Nu inteleg de ce ai pus incrementu. practic faci value=value +4

Nu mai stiu de ce l-am pus :-?

Iar in VB , la adresa era pus bine , aici am editat cand am postat.

Cum adica vrei sa iei date de forma <span id="epm_asd_1" class="bold">50</span> ?

Adica vrei sa iei ce este intre taguri? (<span id="epm_asd_1" class="bold">50</span>)

Banuiesc (,) ca 50 se schimba in alte cife (10,30 etc.)

Daca da uite aici:

Edit:

Tre' sa importi Imports System.Net .

Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wc As New WebClient
Dim html As String
html = wc.DownloadString("http://www.1234.com/pages/")
Label1.Text = GetBetween(html, "<span id=""epm_asd_1"" class=""bold"">", "</span>")
End Sub
Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String
Dim lTemp As Long
lSearch = InStr(lSearch, sSearch, sStart)
If lSearch > 0 Then
lSearch = lSearch + Len(sStart)
lTemp = InStr(lSearch, sSearch, sStop)
If lTemp > lSearch Then Return Trim(Mid$(sSearch, lSearch, lTemp - lSearch))
End If
Return vbNullString
End Function
End Class

Problema :

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

Nu apare nimic la Label.

Link to comment
Share on other sites

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll

Nu apare nimic in label


Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim wc As New WebClient
Dim html As String
html = wc.DownloadString("http://www.1234.com/pages/")
Label1.Text = GetBetween(html, "<span id=""epm_ads_1"" class=""bold"">", "</span>")
End Sub
Private Function GetBetween(ByVal sSearch As String, ByVal sStart As String, ByVal sStop As String, Optional ByVal lSearch As Integer = 1) As String
Dim lTemp As Long
lSearch = InStr(lSearch, sSearch, sStart)
If lSearch > 0 Then
lSearch = lSearch + Len(sStart)
lTemp = InStr(lSearch, sSearch, sStop)
If lTemp > lSearch Then Return Trim(Mid$(sSearch, lSearch, lTemp - lSearch))
End If
Return vbNullString
End Function
End Class

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...