วันพฤหัสบดีที่ 13 กุมภาพันธ์ พ.ศ. 2557

Download ข้อมูล หน้า WEB เช่นข้อมูลราคาหุ้นทำไง โดย VB.NET

Download ข้อมูล หน้า WEB เช่นข้อมูลราคาหุ้นทำไง โดย VB.NET


ตามนี้เลย
เราจะใช้ Class ที่ชื่อ WebClient 



Using client As New WebClient 
     client.Headers("User-Agent") = "helloxxx/2.1"
     client.Headers("Accept-Encoding") = "gzip"
 
     Dim arr() As Byte = client.DownloadData("http://expert-programming-tutor.com/") 
     Console.WriteLine(arr.Length)
     Console.WriteLine(client.ResponseHeaders("Content-Encoding"))
 End Using


โดย ทีมงาน
http://expert-programming-tutor.com/
รับสอนเขียนโปรแกรมคอมพิวเตอร์
รับสอนเขียนโปรแกรมVB.NET




วันพุธที่ 12 กุมภาพันธ์ พ.ศ. 2557

การอ่าน XML ลง Datatable โดยใช้ vb.net

การอ่าน XML ลง DataTable โดยใช้ vb.net


1 สร้าง windows form application 2 เลือก DataGridView  จาก tool `ด้านซ้ายมือ


3 add event form load โดยการ double click ที่พื้นที่ว่างเปล่า


ใส่ code ดังนี้

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim ds As DataSet
        ds = New DataSet
        ds.ReadXml("a.xml")
        Me.DataGridView1.DataSource = ds.Tables(0)
    End Sub
End Class



โดยที่ให้อ่าน file XML ที่อยู่ที่ default path (โดยปกติ คือ ที่เดียกกับ file .exe  (../debug/))

เนื้อหาของ file xml มีดังนี้

 
<customers>
<customer>
<name>a</name>
<lastname>a</lastname>
<phone>a</phone>
</customer>
<customer>
<name>b</name>
<lastname>b</lastname>
<phone>b</phone>
</customer>
<customer>
<name>c</name>
<lastname>c</lastname>
<phone>c</phone>
</customer>
<customer>
<name>d</name>
<lastname>d</lastname>
<phone>d</phone>
</customer>
</customers>

ผลลัพธ์ที่ได้



สอนเขียนโปรแกรม vb.net
http://www.expert-programming-tutor.com/




วันพุธที่ 15 มกราคม พ.ศ. 2557

การแสดงรายชื่อ File ทั้งหมดใน directory

 try
            {
                string dirPath = @"C:\\opencv\\opencv\\build\\x86\\vc11\\lib";

                List<string> dirs = new List<string>(Directory.EnumerateFiles (dirPath));

                foreach (var dir in dirs)
                {
                    richTextBox1.Text += (dir.Substring(dir.LastIndexOf("\\") + 1)) + "\n";
                }
             
            }
            catch (UnauthorizedAccessException UAEx)
            {
                Console.WriteLine(UAEx.Message);
            }
            catch (PathTooLongException PathEx)
            {
                Console.WriteLine(PathEx.Message);
            }


ผลลัพธ์