12/13/2013

ตัวอย่างการทำ Crystal Report แบบง่ายๆ ถ้าใน Visual Studio ไม่มี  Crystal Report  เหมือนในรูปให้ติดตั้ง Crystal Report ก่อนจะเริ่มทำนะค่ะ วิธีการติดตั้ง Crystal Report ดังลิ้งนี้ค่ะ http://codingsecret.blogspot.com/2014/08/install-crystal-report-on-visual-studio.html เมื่อติดตั้งเสร็จเรียนร้อยจะมี Crystal Report เหมือนในรูป 1....

Posted on Friday, December 13, 2013 by nuyingnaja

วันนี้เล่น Crystal Report ใน vb.net  พอเขียนโปรแกรมและแต่ง Report ให้ Connect กับ dataset เสร็จเรียบร้อยแล้ว  ติดปัญหาที่หาไฟล์ไม่เจอ ดังนี้ " Could not load file or assembly 'file:///C:\Program Files\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll'...

Posted on Friday, December 13, 2013 by nuyingnaja

10/20/2013

Public Sub ConnectionSql()         Dim Conn As SqlConnection = New SqlConnection        Dim IP As String = "192.000.XXX.XXX"        Dim DBName As String = "Store"        Dim Username As String = "MyAdmin"        Dim Password As String = "password"        Try             Conn.Close()           ...

Posted on Sunday, October 20, 2013 by nuyingnaja

9/22/2013

ค้นหา  Column ใน DataTable If Not dtLawWord.Columns.Contains("ID") Then                 MessageBox.Show("Can not Find Columns ID") End I...

Posted on Sunday, September 22, 2013 by nuyingnaja

9/19/2013

Imports Microsoft.Office.Interop.Word Imports Microsoft.Office.InteropImports Microsoft.OfficePublic Class classWord    Public Sub GetWord()        Dim WdApp As New Application        Dim WdDoc As Word.Document        WdDoc = WdApp.Documents.Open("D:\text.doc")        Dim rStart, rStop As Integer        rStart = 100       ...

Posted on Thursday, September 19, 2013 by nuyingnaja

9/17/2013

For Each oRow As DataGridViewRow In DataGridView1.Rows             TextBox1.Text = oRow.Cells(1).Value Nex...

Posted on Tuesday, September 17, 2013 by nuyingnaja

Private Sub CopyFileToFolder(ByVal FileName As String, ByVal FileNameNew As String)         File.Copy(FileName, FileNameNew, True) End Su...

Posted on Tuesday, September 17, 2013 by nuyingnaja

Private Sub CreatFolder(ByVal pathName As String)         If Not System.IO.Directory.Exists(pathName) Then        ' ถ้าไม่มี Directory name นี้            My.Computer.FileSystem.CreateDirectory(pathName)  ' ก็จงสร้าง Directory name นี้        End If End Su...

Posted on Tuesday, September 17, 2013 by nuyingnaja

9/16/2013

Dim i As Integer = DataGridView1.Rows.Count - 1 For irow = 0 To DataGridView1.Rows.Count - 1             ' if Row is Selete Check Box is Delete row             If DataGridView1.Rows.Item(i).Cells(0).Value = True Then                 DataGridView1.Rows.RemoveAt(i)             End If            ...

Posted on Monday, September 16, 2013 by nuyingnaja

For iIndex = DataGridView1.RowCount - 1 To 0 Step -1                If DataGridView1.Rows.Item(iIndex).Cells(0).Value = txt_lawSearch.Text Then                     DataGridView1.Rows(iIndex).Selected = True                    Me.DataGridView1.CurrentCell = Me.DataGridView1.Rows(iIndex).Cells(0)                   ...

Posted on Monday, September 16, 2013 by nuyingnaja

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick         Dim ICell As Integer = e.ColumnIndex        Dim IRow As Integer = e.RowIndex         If _IRow >= 0 Then             MsgBox(dgvView.Rows.Item(IRow).Cells(ICell).Value)         End If  End...

Posted on Monday, September 16, 2013 by nuyingnaja

DataGridView1.Rows.Clear()        With DataGridView1         .Rows.Add("1", "AAA")         .Rows.Add("2", "BBB")         .Rows.Add("3", "CCC")         .Rows.Add("4", "DDD")         .Rows.Add("5", "EEE") End With ==== หรือ ==== Dim dt As New DataTable DataGridView1.DataSource = dt...

Posted on Monday, September 16, 2013 by nuyingnaja

Private Sub btn_Browse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Browse.Click            Try            Dim BrowseFolder As New FolderBrowserDialog            BrowseFolder.ShowDialog()            txt_FolderFile.Text = BrowseFolder.SelectedPath           ...

Posted on Monday, September 16, 2013 by nuyingnaja

Private Sub WriteTxt_dt(ByVal dt As DataTable, ByVal path As String)        Dim sw As StreamWriter = New StreamWriter("D:\" &  path & ".txt")        Dim FRow As DataRow()        FRow = dt.Select("", "", DataViewRowState.CurrentRows)        For Each r1 In FRow             Dim lineoftext = r1("ID").ToString & " = " & r1("NAME").ToString           ...

Posted on Monday, September 16, 2013 by nuyingnaja

9/15/2013

Private Sub WriteXml_dt(ByVal dt As DataTable)        If dt.Rows.Count <> 0 Then            'Save File Xml to D:\NewFolder             dt.WriteXml("D:\NewFolder\Test.xml", XmlWriteMode.WriteSchema, True)        End If End Sub  Function ReadXml_dt()        Dim _filePath As String = "D:\NewFolder"       ...

Posted on Sunday, September 15, 2013 by nuyingnaja

9/12/2013

          วันนี้นำเสนอ การลบลายน้ำใน Microsoft Word ด้วย VB.NET (Delete WaterMark Word)  ขั้นตอนมีดังนี้ 1. เตรียมเอกสาร Microsoft Word ที่มี ลายน้ำ ตัวอย่างประมาณนี้    - ในเอกสารนี้ประกอบด้วย ลายน้ำ (WaterMark)    - ในเอกสารนี้ประกอบด้วย ลายน้ำส่วนหัว (Header WaterMark) 2....

Posted on Thursday, September 12, 2013 by nuyingnaja

9/11/2013

Code Open file in visual basic 2010 โค้ด อ่านไฟล์ขึ้นมาแสดง System.Diagnostics.Process.Start("D:\TEST.txt") หรือ Process.Start("D:\TEST.txt") หรือ  Shell("D:\app.exe"...

Posted on Wednesday, September 11, 2013 by nuyingnaja

9/04/2013

 คำสั่งปิด Process ที่บ้างครั้งไม่จำไม่เป็น และต้องการปิด เขียนโค้ดดังนี้ Example ' สั่งปิด Process WINWORD   Dim procQ As System.Diagnostics.Process For Each procQ In System.Diagnostics.Process.GetProcessesByName("WINWORD")             procQ.Kill() Ne...

Posted on Wednesday, September 04, 2013 by nuyingnaja

การตัดข้อความ การแยกประโยคด้วยคำหรือตัวอักษร 1. Split() การตัดข้อความ Syntax Split(ByVal Expression As String, Optional ByVal Delimiter As String) Example Dim test_date As String = "16 มิถุนายน 2556" Dim getStr() As String = Split(test_date, " ") For i = 0 To getStr.Length - 1                   MsgBox(getStr(i))          ' 1. 16          ' 2.  มิถุนาย          ' 3.  2556 Next **...

Posted on Wednesday, September 04, 2013 by nuyingnaja

การสลับคำจาก ตัวแรกให้ไปอยู่ตัวสุดท้าย และตัวสุดท้ายมาอยู่ตัวแรก ด้วย ฟังก์ชัน StrReverse 1. StrReverse() สลับคำ กลับคำ Syntax InStrRev(ByVal StringCheck As String, ByVal StringMatch As String, Optional ByVal Start As Integer) Example Dim test_word As String test_word = "I Love Thailand"  ' need  dnaliahT evoL I Dim word As Integer =  StrReverse(test_word)   'dnaliahT evoL I จากฟังก์ชันนี้จะเห็นได้ว่า ตัวอักษรจะสลับตำแหน่งกัน จากหน้ามือเป็นหลังมือ &nbs...

Posted on Wednesday, September 04, 2013 by nuyingnaja

Public Function InStr(ByVal String1 As String, ByVal String2 As String, Optional ByVal Compare As Microsoft.VisualBasic.CompareMethod = Binary) As Integer      Member of Microsoft.VisualBasic.Strings Summary: การแทนที่คำ ด้วย ฟังก์ชัน Replace 1. InStr() ค้นหาคำที่ต้องการ Syntax InStr(ByVal String1 As String, ByVal String2 As String) InStrRev(ByVal String1 As String, ByVal String2 As String) Example Dim test_word As String test_word = "I Love Thailand"  ' need "h" Dim location As Integer = InStr(test_word, "h")         ...

Posted on Wednesday, September 04, 2013 by nuyingnaja

การตัดคำที่มีประโยคยาว แต่ต้องการเฉพาะคำที่ต้องการเท่านั้น โดยใช้ ฟังก์ชัน Mid ตัดคำ ตัวอย่างดังนี้   Syntax Mid(ByVal str As String, ByVal Start As Integer, ByVal Length As Integer) Example Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Dim test_word As String         test_word = "Thailand Only"         ' need "Thailand"        ...

Posted on Wednesday, September 04, 2013 by nuyingnaja

การแทนที่คำ ด้วย ฟังก์ชัน Replace 1. Replace() แทนที่คำที่ต้องการ Syntax Replace(ByVal Expression As String,ByVal Find As String, ByVal Replacement As String) Example ตัวอย่างคำ  Helly gyygle ให้แทน y เป็น 0 จะได้ัดังนี้    Helly gyygle = Hello google Coding in vb.net Dim word as String = "Helly gyygle" Dim str as String = Replace(word , "y", "o")   ' Hello google Dim str2 as String = word .Replace("y", "o")  ' Hello googl...

Posted on Wednesday, September 04, 2013 by nuyingnaja

9/03/2013

แปลง ตัวหนังสือเป็นตัวเลข ใน vb.net เขียน Code ได้ดังนี้         Dim str As String = "50.50"         Dim str2 As String = "1,050.49"         Dim Conv_num As Integer = CInt(str)    '  50         Dim Conv_num2 As Double = CInt(str)    '  50.0         Dim Conv_num3 As Integer = Val(str)   '  50        ...

Posted on Tuesday, September 03, 2013 by nuyingnaja

แปลง ตัวเลขเป็นตัวหนังสือ ใน vb.net เขียน Code ได้ดังนี้ Dim num As Integer = 500 Dim num2 As Decimal = 2550.49 Dim Convstr As String = CStr(num)     '  500 Dim Convstr2 As String = CStr(num2)   '  2550.49 Dim Conv_num7 As String = Integer.Parse(num)  ' 500 Dim Conv_num8 As String = Decimal.Parse(num2) ' 2550.49 *** บทความที่เกี่ยวข้อง *** Convert String to Integer...

Posted on Tuesday, September 03, 2013 by nuyingnaja

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         ' แสดงวันที่และเวลา         MsgBox(Now)          ' แสดงวันที่         MsgBox(Now.Today) End Sub ** บทความที่เกี่ยวข้อง ** แสดงรูปแบบวันที่ ค.ศ. และ พ.ศ. VB.NET Convers String to Date in vb.net DateAdd แสดงการเพิ่มวันที่และช่วงเวลา บวก ลบ วันที่ / DateDiff เปรียบเทียบวันที่และเวลา FormatDateTime รูปแบบวันที่...

Posted on Tuesday, September 03, 2013 by nuyingnaja

แสดงการเพิ่มวันที่และช่วงเวลา ใน vb.net Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         'ต้องการทราบว่า นับจากวันนี้อีก 10 วันเป็นวันอะไร         MsgBox(DateAdd(DateInterval.Day, 10, Today))        ...

Posted on Tuesday, September 03, 2013 by nuyingnaja

         ใน vb.net มีการบวก ลบ วันที่ ซึ่งมีหลากหลายรูปแบบ และผลต่างแต่ละรูปแบบก็แล้วแต่การนำมาใช้งานของโปรแกรมนั้นๆ วันนี้มาดูกัน มีแบบไหนบ้าง 1. DateDiff() เปรียบเทียบวันที่เวลาระหว่าง เวลา1 และ เวลา2 Syntax DateDiff(DateInterval,Date1,Date2) DateInterval  มีดังนี้ เยอะมาก DateInterval.Day DateInterval.DayOfYear DateInterval.Hour DateInterval.Minute DateInterval.Month DateInterval.Quarter DateInterval.Second DateInterval.Weekday DateInterval.WeekOfYear DateInterval.Year Example Private...

Posted on Tuesday, September 03, 2013 by nuyingnaja

วันนี้มาดูในส่วนของการเปลี่ยนวันที่ (Convers) จาก String เป็น Datetime ดังนี้ค่ะ Dim str_date As String = "20/09/2013" Dim date_ As Date = CDate(str_date) ** บทความที่เกี่ยวข้อง ** แสดงรูปแบบวันที่ ค.ศ. และ พ.ศ. VB.NET Convers String to Date in vb.net DateAdd แสดงการเพิ่มวันที่และช่วงเวลา บวก ลบ วันที่ / DateDiff เปรียบเทียบวันที่และเวลา FormatDateTime หาวันนี้ปัจจุบัน DateNow รูปแบบวันที่ เพิ่มเติม...

Posted on Tuesday, September 03, 2013 by nuyingnaja

         FormatDateTime ใน vb.net มีอยู่หลากหลายรูปแบบแล้วแต่การใช้งาน มาดูกันว่ามี Format แบบไหนบ้าง Private Sub textbox_show()         Dim test_date As Date = Now         Me.txtD1.Text = Format(test_date, "dd/MM/yyyy")        ...

Posted on Tuesday, September 03, 2013 by nuyingnaja

              การแสดงรูปแบบวันที่  มีอยู่ 2 แบบคือ แบบ ค.ศ. และ พ.ศ. ในโปรแกรมถ้าไม่เขียนโค้ดกำหนดไว้  โปรแกรมจะแสดงรูปแบบวันที่ตามที่เครื่องกำหนดไว้  ดังนั้นถ้าต้องการทำให้แสดงรูปแบบวันที่เหมือนกันจะต้องเขียน โค้ดดังนี้ จะต้องเขียน code ไว้ใน Form1_Load หรือ Private Sub New()...

Posted on Tuesday, September 03, 2013 by nuyingnaja

9/02/2013

Close Msgbox in vb.net (โค้ดสั่งปิด Msgbox ในโปรแกรม) ทั่วไปแล้วเราจะใช้ Msgbox ในการแสดงข้อความเตือนต่าง เช่น MsgBox("Please Login !!!") แต่ Code ตัวนี้จะแสดงข้อความเตือน 3 วินาที แล้วปิด Msgbox ในโปรแกรม ให้ด้วย เขียน code ดังนี้ Private Sub Msgbox_Show()         CreateObject("WScript.Shell").PopUp("Please...

Posted on Monday, September 02, 2013 by nuyingnaja

8/30/2013

คำสั่งหารปัดทศนิยมใน vb.net มีหลายตัว มาดูกันเลยว่าแต่ละ funtion ผลลัพธ์ของการปัดเศษจะเป็นอย่างไร 1. ปรับตัวเลขทศนิยมให้เป็นจำนวนเต็ม มากกว่า 0.5 ปัดขึ้น  น้อยกว่าหรือเท่ากับ 0.5 ปัดลง Dim number As Double   number = Math.Round(1.5)    ' ค่าที่ได้คือ  2 number = Math.Round(1.4)    ' ค่าที่ได้คือ  1  2. ปรับตัวเลขทศนิยมเป็นจำนวนเต็ม ปรับเศษขึ้นอย่างเดียว Dim number As Double number = Math.Ceiling(1.5)    ' ค่าที่ได้คือ  2 number = Math.Ceiling(1.4)   ...

Posted on Friday, August 30, 2013 by nuyingnaja

8/21/2013

Public Function GetNoOfPagesDOC(ByVal FileName__1 As String) As Integer         Dim num As Integer = 0         Dim fileName__2 As Object = FileName__1         Dim [readOnly] As Object = False         Dim isVisible As Object = True         Dim objDNS As Object = Word.WdSaveOptions.wdDoNotSaveChanges         Try            ...

Posted on Wednesday, August 21, 2013 by nuyingnaja

Public Function GetNoOfPagesPDF(ByVal FileName As String) As Integer        Dim Count As Integer = 0        If FileName <> "" Then            'Open the file            Dim fstream As New IO.FileStream(FileName, IO.FileMode.Open, IO.FileAccess.Read)            Dim stream As New IO.StreamReader(fstream)       ...

Posted on Wednesday, August 21, 2013 by nuyingnaja

 ' Open File ShowDialog     Public Function OpenFile(ByVal TypeFile As String)         Dim _FileFull As String = ""         Dim _typefile As String = ""         If TypeFile = "pic" Then             _typefile = "Picture Files (*.JPG)|*.JPG;"         ElseIf TypeFile = "word" Then            ...

Posted on Wednesday, August 21, 2013 by nuyingnaja

Private _StrConnAccess As String     Private cConn As New clsConnection     Public ReadOnly Property ConnectionStringAccess() As String         Get             Dim _StrConnAccess As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=C:\Excel1.mdb;"             Return _StrConnAccess         End Get     End Property    ...

Posted on Wednesday, August 21, 2013 by nuyingnaja

8/20/2013

การอ่าน Microsoft Office Word จากตำแหน่งใน เอกสาร 1. Create New Project  ตามนี้ 2. Create Form1 => Add Reference... ดังนี้ 3. เลือก  Interop.Microsoft.office Interop.Word ดังนี้ 4. เตรียมเอกสารใ้ห้พร้อม ตัวอย่างได้สร้างไว้ที่  D:\Test_Word.docx 5. เขียน Code ตามนี้ Imports Microsoft.Office.Interop.Word Imports...

Posted on Tuesday, August 20, 2013 by nuyingnaja