تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] مساعدة التحقق من الاتصال بالانترنت
#4
(18-05-17, 04:09 PM)alma2 كتب :
كود :
Imports System.Xml

Public Class Form1

   Dim WithEvents BackgroundWorker1 As New System.ComponentModel.BackgroundWorker


   Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
       Button1.Enabled = False
       Button2.Enabled = True
       If Not Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.RunWorkerAsync()
   End Sub

   Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
       If Me.BackgroundWorker1.IsBusy Then Me.BackgroundWorker1.CancelAsync()
       Button1.Enabled = True
       Button2.Enabled = False

   End Sub


   Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
       BackgroundWorker1.WorkerSupportsCancellation = True
       Control.CheckForIllegalCrossThreadCalls = False

       Dim url As String = String.Format("https://www.hamqth.com/xml.php?id={0}&callsign={1} &prg=BKLOG", Label17.Text, calls.Text)

       Dim document As New XmlTextReader(url)

       'loop through the xml file
       While (document.Read())
           If Me.BackgroundWorker1.CancellationPending Then Exit Sub

           Dim type = document.NodeType

           'if node type was element
           If (type = XmlNodeType.Element) Then

               'if the loop found a <FirstName> tag
               If (document.Name = "adr_name") Then

                   Lfullname.Text = document.ReadInnerXml

               End If
               If (document.Name = "us_state") Then

                   state.Text = document.ReadInnerXml

               End If
               'if the loop found a <FirstName> tag
               If (document.Name = "qth") Then

                   qth.Text = document.ReadInnerXml

               End If


               'if the loop found a <FirstName> tag
               If (document.Name = "grid") Then

                   WORKinfo.GRIDSQUARE.Text = document.ReadInnerXml

               End If

               'if the loop found a <FirstName> tag
               If (document.Name = "qsl_via") Then

                   WORKinfo.Lqslmgr.Text = document.ReadInnerXml

               End If

               'if the loop found a <FirstName> tag
               If (document.Name = "latitude") Then

                   WORKinfo.LAT.Text = document.ReadInnerXml

               End If

               'if the loop found a <FirstName> tag
               If (document.Name = "longitude") Then

                   WORKinfo.LON.Text = document.ReadInnerXml

               End If

           End If

       End While

   End Sub

End Class

شكرا لك فعلا هذا الكود اللي كنت احتاجه

شكرا
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
RE: مساعدة التحقق من الاتصال بالانترنت - بواسطة dubai.eig - 19-05-17, 06:46 PM


التنقل السريع :


يقوم بقرائة الموضوع: