[VB.NET] การพิมพ์ใบเสร็จด้วย ActiveReports .NET ลงกระดาษขนาด A4 และ A5 (ครึ่ง A4)
http://www.g2gnet.com/webboard/images/vbnet/ar6billa4a5.pngอันที่จริงโค้ดชุดนี้แอดมินทำแจกไว้ตั้งแต่ปีที่แล้ว พึ่งนึกขึ้นได้ก็เลยเอามาลงให้ได้รับชมกัน ไม่มีคำอธิบายอะไรมากมายหรอกครับ หลักการรวมๆก็คือการป้อนข้อมูลเข้าสู่ตารางกริด โดยบางหลักจะต้องมีการ Validate Cell เพื่อป้อนข้อมูลเฉพาะแบบตัวเลขจำนวนเต็ม หรือจำนวนแบบทศนิยมเท่านั้น จากนั้นก็เอาข้อมูลเหล่านั้นมาทำการพิมพ์ผลลัพธ์ โดยทำการลูปนับจำนวนแถวจากตารางกริดในส่วนของ FetchData และรวมไปถึงการใช้เงื่อนไขในการพิมพ์ลงกระดาษ 2 ขนาด คือ A4 และ A5 ด้วยการใช้รายงานเพียงตัวเดียว ...
มาดูโค้ดส่วนหลักๆในฟอร์ม ...
' / --------------------------------------------------------------------------------
' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
' / eMail : thongkorn@hotmail.com
' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
' / Facebook: https://www.facebook.com/commonindy (Worldwide)
' / Purpose: Print bill on paper size is A4/A5.
' / Microsoft Visual Basic .NET (2010) & ActiveReports 6
' /
' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
' / You can modify and/or distribute without to inform the developer.
' / --------------------------------------------------------------------------------
Public Class frmPrintBillA4A5
Private Sub frmPrintBillA4A5_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
Application.Exit()
End Sub
Private Sub frmPrintBillA4A5_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.F7
Call btnPreview_Click(sender, e)
Case Keys.F10
Me.Close()
End Select
End Sub
Private Sub frmPrintBillA4A5_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'// Can use key down.
Me.KeyPreview = True
Me.ToolStrip1.Cursor = Cursors.Hand
'// Sample data.
txtInvoiceNo.Text = "INV-60080001"
txtCustomer.Text = "นายบุญห่อ พ่อมันรวย"
txtCPhone.Text = "08-9999-6666"
txtSumTotal.Text = "0.00"
'// Initialized
Call InitilaizeGrid()
Call FillDataSample()
'// Sum of Quantity x UnitPrice.
Call CalSumTotal()
'//
End Sub
'// Sample Data
Private Sub FillDataSample()
Dim row As String() = New String() {"ค่าอุปกรณ์ตัวต้านทาน 2.2K โอห์ม 5%", "20", "50.00", "1000.00"}
dgvData.Rows.Add(row)
row = New String() {"ค่าเปิดฝาเครื่อง", "1", "1,000.00", "1,000.00"}
dgvData.Rows.Add(row)
row = New String() {"ค่าแรงในการปัดฝุ่น", "1", "3,000.00", "3,000.00"}
dgvData.Rows.Add(row)
row = New String() {"ค่าแรงประกอบเครื่องกลับคืน", "1", "5,000.00", "5,000.00"}
dgvData.Rows.Add(row)
row = New String() {"ค่าซ่อม", "1", "50.00", "50.00"}
dgvData.Rows.Add(row)
End Sub
' / --------------------------------------------------------------------------------
Private Sub InitilaizeGrid()
'// Create columns with @Run Time
Dim Column1 As New DataGridViewTextBoxColumn()
Dim Column2 As New DataGridViewTextBoxColumn()
Dim Column3 As New DataGridViewTextBoxColumn()
Dim Column4 As New DataGridViewTextBoxColumn()
With dgvData
With Column1
.Name = "Description"
.HeaderText = "รายละเอียด"
.ReadOnly = False
.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
End With
With Column2
.Name = "Quantity"
.HeaderText = "จำนวน"
.ValueType = GetType(Integer)
.ReadOnly = False
.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
End With
With Column3
.Name = "UnitPrice"
.HeaderText = "ราคา/หน่วย"
.ValueType = GetType(Decimal)
.ReadOnly = False
.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Format = "N2"
End With
With Column4
.Name = "Total"
.HeaderText = "รวมเป็นเงิน"
.ValueType = GetType(Decimal)
.ReadOnly = True
.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Format = "N2"
End With
'// Add all columns.
With dgvData
.Columns.Add(Column1)
.Columns.Add(Column2)
.Columns.Add(Column3)
.Columns.Add(Column4)
End With
End With
'// Sample coding with Run-Time
With dgvData
.RowHeadersVisible = True
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.ReadOnly = False
.AllowUserToResizeColumns = True
.AllowUserToResizeRows = True
.SelectionMode = DataGridViewSelectionMode.CellSelect
.MultiSelect = False
'// Data rows
.Font = New Font("Tahoma", 9)
.RowTemplate.MinimumHeight = 20
.RowTemplate.Height = 26
'// Column Header
.ColumnHeadersHeight = 30
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing
'// แสดงสีสลับแถวคู่-คี่
.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue
'// Auto adjust column width.
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
'// Header Own Style
With .ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.Black
.Font = New Font("Tahoma", 9, FontStyle.Bold)
End With
End With
End Sub
Private Sub btnPreview_Click(sender As System.Object, e As System.EventArgs) Handles btnPreview.Click
If dgvData.Rows.Count <= 0 Then Exit Sub
' Instance name ARDesigner มันจะชี้ไปที่ไฟล์ arPrintBillA4A5.vb
Dim rpt As New arPrintBillA4A5
' Run Report
rpt.Run()
' โหลดรายงาน document (arPrintBillA4A5) เข้าสู่ ActiveReports Viewer
'// Zoom 90%
Me.Viewer1.ReportViewer.Zoom = 0.9
Me.Viewer1.Document = rpt.Document
End Sub
Private Sub dgvData_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvData.CellContentClick
'//
End Sub
Private Sub ToolStripButton1_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton1.Click
frmSetting.ShowDialog()
End Sub
Private Sub ToolStripButton2_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButton2.Click
Me.Close()
End Sub
' / --------------------------------------------------------------------------------
' / Add new row
Private Sub btnAddRow_Click(sender As System.Object, e As System.EventArgs) Handles btnAddRow.Click
Dim row As String() = New String() {"", 1, 0, 0.0}
dgvData.Rows.Add(row)
' /
If dgvData.RowCount > 0 Then Call CalSumTotal()
End Sub
' / --------------------------------------------------------------------------------
' / Remove selected row
Private Sub btnRemoveRow_Click(sender As System.Object, e As System.EventArgs) Handles btnRemoveRow.Click
If dgvData.RowCount = 0 Then Exit Sub
dgvData.Rows.Remove(dgvData.CurrentRow)
dgvData.Refresh()
' /
If dgvData.RowCount > 0 Then Call CalSumTotal()
End Sub
' / --------------------------------------------------------------------------------
' / Calcualte sum of Total (Column Index = 3)
Private Sub CalSumTotal()
txtSumTotal.Text = "0.00"
For i As Byte = 0 To dgvData.RowCount - 1
' CDbl = Convert to Double แปลงค่าตัวเลขเป็นแบบ Double
txtSumTotal.Text = CDbl(txtSumTotal.Text) + CDbl(dgvData.Rows(i).Cells(3).Value)
Next
txtSumTotal.Text = Format(CDbl(txtSumTotal.Text), "#,##0.00")
End Sub
' / --------------------------------------------------------------------------------
' / Before Edit Data
Private Sub dgvData_CellBeginEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles dgvData.CellBeginEdit
Dim Quantity As Double = dgvData.Rows(e.RowIndex).Cells(1).Value
Dim UnitPrice As Double = dgvData.Rows(e.RowIndex).Cells(2).Value
dgvData.Rows(e.RowIndex).Cells(3).Value = (Quantity * UnitPrice).ToString("#,##0.00")
' /
Call CalSumTotal()
End Sub
' / --------------------------------------------------------------------------------
' / After you press Enter
Private Sub dgvData_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvData.CellEndEdit
Dim Quantity As Double
Dim UnitPrice As Double
Select Case e.ColumnIndex
Case 1, 2 ' Column Index = 1 (Quantity), Column Index = 2 (UnitPrice)
' Quantity
' If Null Value
If IsDBNull(dgvData.Rows(e.RowIndex).Cells(1).Value) Then dgvData.Rows(e.RowIndex).Cells(1).Value = 0
Quantity = dgvData.Rows(e.RowIndex).Cells(1).Value
If Quantity = 0 Then
dgvData.Rows(e.RowIndex).Cells(1).Value = 1
End If
' UnitPrice
' If Null Value
If IsDBNull(dgvData.Rows(e.RowIndex).Cells(2).Value) Then dgvData.Rows(e.RowIndex).Cells(2).Value = 0.0
UnitPrice = dgvData.Rows(e.RowIndex).Cells(2).Value
If UnitPrice = 0 Then
dgvData.Rows(e.RowIndex).Cells(2).Value = 0
End If
End Select
' Quantity x UnitPrice
dgvData.Rows(e.RowIndex).Cells(3).Value = (Quantity * UnitPrice).ToString("#,##0.00")
'//
Call CalSumTotal()
End Sub
' / --------------------------------------------------------------------------------
Private Sub dgvData_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles dgvData.EditingControlShowing
Select Case dgvData.Columns(dgvData.CurrentCell.ColumnIndex).Name
' / Can use both ColumeIndex or Field Name
Case "Quantity", "UnitPrice"
'// Stop and Start event handler
RemoveHandler e.Control.KeyPress, AddressOf ValidKeyPress
AddHandler e.Control.KeyPress, AddressOf ValidKeyPress
End Select
End Sub
' / --------------------------------------------------------------------------------
Private Sub ValidKeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
Dim tb As TextBox = sender
Select Case dgvData.CurrentCell.ColumnIndex
Case 1' Quantity is Integer
Select Case e.KeyChar
Case "0" To "9" ' digits 0 - 9 allowed
Case ChrW(Keys.Back) ' backspace allowed for deleting (Delete key automatically overrides)
Case Else ' everything else ....
' True = CPU cancel the KeyPress event
e.Handled = True ' and it's just like you never pressed a key at all
End Select
Case 2' UnitPrice is Double
Select Case e.KeyChar
Case "0" To "9"
' Allowed "."
Case "."
' can present "." only one
If InStr(tb.Text, ".") Then e.Handled = True
Case ChrW(Keys.Back)
Case Else
e.Handled = True
End Select
End Select
End Sub
Private Sub txtSumTotal_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtSumTotal.KeyPress
'// Don't press any key.
e.Handled = True
End Sub
Private Sub rdoA5_Click(sender As Object, e As System.EventArgs) Handles rdoA5.Click
Call btnPreview_Click(sender, e)
End Sub
Private Sub rdoA4_Click(sender As Object, e As System.EventArgs) Handles rdoA4.Click
Call btnPreview_Click(sender, e)
End Sub
End Class
http://www.g2gnet.com/webboard/images/vbnet/ar6billa4a5setup.png
มาดูโค้ดส่วนของการตั้งค่าและบันทึกผลลงใน INI File ...
' / --------------------------------------------------------------------------------
' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
' / eMail : thongkorn@hotmail.com
' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
' / Facebook: https://www.facebook.com/commonindy (Worldwide)
' / Purpose: Setting up information.
' / Microsoft Visual Basic .NET (2010) & MS Excel 2003+
' /
' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
' / You can modify and/or distribute without to inform the developer.
' / --------------------------------------------------------------------------------
Public Class frmSetting
Dim strFileINI As String
Private Sub frmSetting_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.F8
Call btnSave_Click(sender, e)
Case Keys.Escape
Me.Close()
End Select
End Sub
' / --------------------------------------------------------------------------------
Private Sub frmSetting_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'// ตั้งค่าให้ KeyPreView = True เพื่อให้เกิดเหตุการณ์ KeyDown ทำงานได้
Me.KeyPreview = True
'//
strFileINI = MyPath(Application.StartupPath) & "Config.ini"
'// เช็คว่ามีไฟล์ Config.ini อยู่หรือไม่???
If My.Computer.FileSystem.FileExists(strFileINI) Then
txtOwner.Text = ReadIni(strFileINI, "Config", "Owner", "")
txtAddress.Text = ReadIni(strFileINI, "Config", "Address", "")
txtRemark1.Text = ReadIni(strFileINI, "Config", "Remark1", "")
txtRemark2.Text = ReadIni(strFileINI, "Config", "Remark2", "")
'// กรณีไม่เจอ ให้เริ่มต้นค่าใหม่
Else
txtOwner.Text = "ทองก้อนอิเล็กทรอนิกส์ (อดีตช่างในตำนาน)"
txtAddress.Text = "123/456 ถ.กลางเมือง ต.เมืองเก่า อ.เมือง จ.ขอนแก่น โทร.043-XXX-XXX"
txtRemark1.Text = " กรุณาตรวจสอบและทดสอบอุปกรณ์ให้ครบถ้วนก่อนออกจากร้าน"
txtRemark2.Text = " สินค้ารับประกันการซ่อมยาวนาน 7 ชั่วโคตร"
End If
End Sub
' / --------------------------------------------------------------------------------
'// บันทึกไฟล์ INI
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
WriteIni(strFileINI, "Config", "Owner", txtOwner.Text)
WriteIni(strFileINI, "Config", "Address", txtAddress.Text)
WriteIni(strFileINI, "Config", "Remark1", txtRemark1.Text)
WriteIni(strFileINI, "Config", "Remark2", txtRemark2.Text)
'//
MessageBox.Show("บันทึกการตั้งค่าระบบเรียบร้อย.", "รายงานสถานะ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub frmSetting_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Me.Dispose()
End Sub
End Class
มาดูโค้ดในส่วนของ ActiveReports ...
' / --------------------------------------------------------------------------------
' / Developer : Mr.Surapon Yodsanga (Thongkorn Tubtimkrob)
' / eMail : thongkorn@hotmail.com
' / URL: http://www.g2gnet.com (Khon Kaen - Thailand)
' / Facebook: https://www.facebook.com/g2gnet (For Thailand)
' / Facebook: https://www.facebook.com/commonindy (Worldwide)
' / Purpose: Print bill on paper size is A4/A5.
' / Microsoft Visual Basic .NET (2010) & MS Excel 2003+
' /
' / This is open source code under @CopyLeft by Thongkorn Tubtimkrob.
' / You can modify and/or distribute without to inform the developer.
' / --------------------------------------------------------------------------------
Imports DataDynamics.ActiveReports
Imports DataDynamics.ActiveReports.Document
Public Class arPrintBillA4A5
' ตัวแปรนี้ต้องประกาศเป็นแบบ Public (เฉพาะ arPrintBillA4A5) เพื่อให้ส่วนของ Detail1_Format และ FetchData มองเห็นด้วย
Private ItemNo As Integer
Private GrandTotal As Double
'// เลือกจากแถวในตารางกริด
Private sRow As Integer
Private Sub arRoomReciept_FetchData(sender As Object, eArgs As DataDynamics.ActiveReports.ActiveReport.FetchEventArgs) Handles Me.FetchData
ItemNo += 1
If ItemNo > frmPrintBillA4A5.dgvData.RowCount Then
' หากหมดแล้วก็จบการพิมพ์
eArgs.EOF = True
Exit Sub
' ยังไม่หมดข้อมูล
Else
eArgs.EOF = False
End If
End Sub
Private Sub arRoomReciept_ReportStart(sender As Object, e As System.EventArgs) Handles Me.ReportStart
' การตั้งค่าหน้ากระดาษ
With PageSettings
' หน่วยวัดเป็นนิ้ว
.Margins.Left = CmToInch(1) ' แปลงค่า 1.0 ซม. เป็นนิ้ว
.Margins.Right = 0.1
.Margins.Top = 0.5
.Margins.Bottom = 0.2
' ตั้งค่ากระดาษแนวตั้ง
.Orientation = PageOrientation.Portrait
' กระดาษขนาด A4
'.PaperKind = Drawing.Printing.PaperKind.A4
' กรณีที่กำหนดขนาดกระดาษเอง
.PaperKind = Drawing.Printing.PaperKind.Custom
.PaperWidth = CmToInch(21) ' 21 ซม.
'// เลือกขนาดกระดาษ A5
If frmPrintBillA4A5.rdoA5.Checked Then
.PaperHeight = CmToInch(14.8)
'// กระดาษ A4
Else
.PaperHeight = CmToInch(29.5)
End If
End With
' ปกติต้องเคลียร์ค่าต่างๆของ TextBox ก่อนการพิมพ์
txtItem.Text = ""
txtDesc.Text = ""
txtUnitPrice.Text = ""
txtQTY.Text = ""
txtAmount.Text = ""
txtGrandTotal.Text = ""
txtOwner.Text = ""
txtAddress.Text = ""
lblRemark1.Text = ""
lblRemark2.Text = ""
txtDate.Text = ""
txtInvoiceNo.Text = ""
'// ตั้งค่าเริ่มต้นในการนับจำนวนหลัก
ItemNo = 0
'// แถวเริ่มต้น
sRow = 0
'// แสดงกิจการและที่อยู่ โดยการอ่านค่าจาก INI (Initialized File)
Dim strFileINI As String = MyPath(Application.StartupPath) & "Config.ini"
If My.Computer.FileSystem.FileExists(strFileINI) Then
txtOwner.Text = ReadIni(strFileINI, "Config", "Owner", "")
txtAddress.Text = ReadIni(strFileINI, "Config", "Address", "")
lblRemark1.Text = ReadIni(strFileINI, "Config", "Remark1", "")
lblRemark2.Text = ReadIni(strFileINI, "Config", "Remark2", "")
'// กรณีไม่เจอ ให้เริ่มต้นค่าใหม่
Else
txtOwner.Text = "ทองก้อนอิเล็กทรอนิกส์ (อดีตช่างในตำนาน)"
txtAddress.Text = "123/456 ถ.กลางเมือง ต.เมืองเก่า อ.เมือง จ.ขอนแก่น โทร.043-XXX-XXX"
lblRemark1.Text = " กรุณาตรวจสอบและทดสอบอุปกรณ์ให้ครบถ้วนก่อนออกจากร้าน"
lblRemark2.Text = " สินค้ารับประกันการซ่อมยาวนาน 7 ชั่วโคตร"
End If
End Sub
Private Sub Detail1_Format(sender As Object, e As System.EventArgs) Handles Detail1.Format
'// ItemNo หรือลำดับที่ โดยจะเริ่มจาก 1
txtItem.Text = ItemNo & "."
With frmPrintBillA4A5
'// หลักแรกของ DataGridView
txtDesc.Text = .dgvData.Rows(sRow).Cells(0).Value
'// หลักที่ 2
txtQTY.Text = .dgvData.Rows(sRow).Cells(1).Value
'// หลักที่ 3
txtUnitPrice.Text = Format(CDbl(.dgvData.Rows(sRow).Cells(2).Value), "#,##0.00")
'// จะดึงข้อมูลมาจากหลักที่ 4 ใน DataGridView เลยก็ได้
txtAmount.Text = Format(CDbl(txtUnitPrice.Text) * CInt(txtQTY.Text), "#,##0.00")
End With
' รวมจำนวนเงินผ่านทางตัวแปร
GrandTotal = GrandTotal + CDbl(txtAmount.Text)
'// เลื่อนตำแหน่งแถวการพิมพ์ (ไม่ใช้ตัวแปรนี้ก็ได้ ใช้ ItemNo แทน โดยให้ลดค่า ItemNo - 1)
'// แต่แยกให้เห็นจะได้ทำความเข้าใจง่ายๆครับผม
sRow += 1
End Sub
Private Sub PageHeader1_Format(sender As Object, e As System.EventArgs) Handles PageHeader1.Format
txtCname.Text = frmPrintBillA4A5.txtCustomer.Text
txtCPhone.Text = frmPrintBillA4A5.txtCPhone.Text
txtInvoiceNo.Text = frmPrintBillA4A5.txtInvoiceNo.Text
txtDate.Text = FormatDateTime(Now(), DateFormat.GeneralDate)
End Sub
Private Sub GroupFooter1_Format(sender As Object, e As System.EventArgs) Handles GroupFooter1.Format
txtGrandTotal.Text = "รวมเงิน: " & Format(GrandTotal, "#,##0.00") & " บาท."
End Sub
End Class
มาดูโค้ดในส่วนของโมดูลฟังค์ชั่น ...
Module modFunction
' / --------------------------------------------------------------------------------
' / Initialized Management
Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringW" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String _
) As Int32
Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" ( _
ByVal lpApplicationName As String, _
ByVal lpKeyName As String, _
ByVal lpDefault As String, _
ByVal lpReturnedString As String, _
ByVal nSize As Int32, _
ByVal lpFileName As String _
) As Int32
' / --------------------------------------------------------------------------------
' / --------------------------------------------------------------------------------
Public Sub WriteIni(ByVal iniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamVal As String)
Dim Result As Integer = WritePrivateProfileString(Section, ParamName, ParamVal, iniFileName)
End Sub
Public Function ReadIni(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As String
Dim ParamVal As String = Space$(1024)
Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)
ReadIni = Left$(ParamVal, LenParamVal)
End Function
' / --------------------------------------------------------------------------------
' / Get my project path
' / AppPath = C:\My Project\bin\debug
' / Replace "\bin\debug" with "\"
' / Return : C:\My Project\
Function MyPath(ByVal AppPath As String) As String
'/ MessageBox.Show(AppPath);
AppPath = AppPath.ToLower()
'/ Return Value
MyPath = AppPath.Replace("\bin\debug", "\").Replace("\bin\release", "\").Replace("\bin\x86\debug", "\")
'// If not found folder then put the \ (BackSlash) at the end.
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
End Function
' / --------------------------------------------------------------------------------
' / ฟังค์ชั่นในการป้อนเฉพาะค่าตัวเลขได้เท่านั้น
Function CheckDigitOnly(ByVal index As Integer) As Boolean
Select Case index
Case 48 To 57 ' เลข 0 - 9
CheckDigitOnly = False
Case 8, 13 ' Backspace = 8, Enter = 13
CheckDigitOnly = False
Case Else
CheckDigitOnly = True
End Select
End Function
End Module
ดาวน์โหลดโค้ดต้นฉบับชุดเต็ม VB.NET (2010) ได้ที่ ...
ขอบพระคุณอย่างสูงครับ อาจารย์
หน้า:
[1]