Import dan mengolah text document bag.2


Codeng pada form import

Public Class import
Inherits System.Windows.Forms.Form
Dim mykonek As New acces.datacon
Dim insert As New acces.datainsrt
Sub import()-------------------------
Try
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim EntireFile, LineIn, tempfile As String
Dim pro As Integer = 0
If txtfile.Text.Trim = "" Then
MsgBox("Cari file terlebih dahulu", MsgBoxStyle.Information, "Pesan kesalahan")
Exit Sub
End If
oRead = oFile.OpenText(txtfile.Text.Trim)
While oRead.Peek <> -1
LineIn = oRead.ReadLine()
Dim level As String = LineIn.Substring(0, 4)
Dim item As String = LineIn.Trim
insert.insrt(level, item)
Label1.Text = oRead.Peek.MaxValue
pro = pro + 1
End While
oRead.Close()
MsgBox("Import data berhasil", MsgBoxStyle.Information, "Pesan keberhasilan")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical)
mykonek.close()
End Try
End Sub
Button open file dialog-----------------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.Filter = "CSV (Comma delimited) (*.csv) *.csv Text Documents(*.txt) *.txt All Files (*.*) *.*"
OpenFileDialog1.FilterIndex = 0
OpenFileDialog1.FileName = ""
Dim result As DialogResult
OpenFileDialog1.ShowDialog()
txtfile.Text = OpenFileDialog1.FileName
End Sub
Button import---------------------------------

Private Sub btnimport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnimport.Click
import()
End Sub

0 komentar: