logo logo

The next-generation blog, news, and magazine theme for you to start sharing your stories today!

The Blogzine

Save on Premium Membership

Get the insights report trusted by experts around the globe. Become a Member Today!

View pricing plans

New York, USA (HQ)

750 Sing Sing Rd, Horseheads, NY, 14845

Call: 469-537-2410 (Toll-free)

hello@blogzine.com
.Net

Cách ghi, đọc, xóa file trong VB.NET

Hôm nay sau một hồi tìm kiếm trên mạng thì mình đã đã tạo ra được một ứng dụng lưu trử thông tin dữ liệu rất tốt cho các coder hiện này, cần lưu trử link thủ thuật hay gì đó mà không sợ mất :). Bên d…

avatar
Hung.Pro.VN

Developer Windows


  • 10/11/2017
  • Views

Hôm nay sau một hồi tìm kiếm trên mạng thì mình đã đã tạo ra được một ứng dụng lưu trử thông tin dữ liệu rất tốt cho các coder hiện này, cần lưu trử link thủ thuật hay gì đó mà không sợ mất :). Bên dười là full đoạn code cho bạn nào cần nhé :)

Imports System.IO

Public Class Form1
Private Const FileName As String = "QuanLyLink"

Private _QLINK As New ArrayList
Private Function GhiFile(ByVal filename As String) As Boolean
Dim sw As StreamWriter = New StreamWriter(filename, True)
Try
sw.WriteLine(txtNam.Text + vbTab + TextBox2.Text)

Catch ex As Exception
Return False
Finally
sw.Close()
End Try
Return True

End Function

Private Function DocFile(ByVal filename As String) As Boolean

Try
Dim sr As StreamReader = New StreamReader(filename)
_QLINK.Clear()
While Not sr.EndOfStream
_QLINK.Add(sr.ReadLine)
End While
sr.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function

Private Function Editdata() As Boolean

Try
Dim index As Integer = DataGridView1.CurrentRow.Index

DataGridView1.Rows(index).Cells("txtNam").Value = txtNam.Text
DataGridView1.Rows(index).Cells("TextBox2").Value = TextBox2.Text
Catch ex As Exception
Return False
End Try
Return True
End Function

Private Function GhiFile(ByVal filename As String, ByVal dg As DataGridView) As Boolean
Dim sw As StreamWriter = New StreamWriter(filename, False)
Try
'lệnh ghi
sw.WriteLine(txtNam.Text + vbTab + TextBox2.Text)

Catch ex As Exception
Return False
Finally
sw.Close()
End Try
Return True

End Function

Private Sub LoadDataOnGird()
If DocFile(FileName) Then
DataGridView1.Rows.Clear()
For i As Integer = 0 To _QLINK.Count - 1
DataGridView1.Rows.Add(_QLINK(i).ToString.Split(vbTab))

Next
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If GhiFile(FileName) Then
' MessageBox.Show("Thêm Thành Công", "Thông Báo")
ToolStripStatusLabel2.Text = " Add SuccessFull"
LoadDataOnGird()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If DataGridView1.Rows.Count > 0 Then
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
GhiFile(FileName, DataGridView1)
ToolStripStatusLabel2.Text = "Delete SuccessFull"
Else

End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ToolStripStatusLabel3.Text = TimeOfDay.TimeOfDay.ToString
End Sub

Private Sub ReloadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReloadToolStripMenuItem.Click
MessageBox.Show("Đang Cập Nhật...", "Info")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadDataOnGird()
End Sub
End Class

Nhìn sơ qua đoạn code trên các bạn sẽ không hiểu lắm ;) Nhưng mà những người trong nghề thì lại rất đơn giản :)

VIDEO DEMO:



Các bạn có thể tải về để TEST thử :)


Pass Giải Nén:
bomkhung.info

Các bạn nhớ ghi nguồn khi copy bài từ blog này nhé :)

Related post


avatar

Hung.Pro.VN

Nhà thiết kế Web
View Articles

Tôi là admin trang Hung.Pro.VN là một người có đam mê với Blogspot, kinh nghiệm 5 năm thiết kế ra hàng trăm mẫu Template blogpsot như" Bán hàng, bất động sản, landing page, tin tức...

Nhận xét

Share this article