I have an text file that i use as a template
QTY ITM INVO MAT
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
how do i get each row to an excel sheet and keep adding to the end of last row?
Public Class Form1
Dim ofd As OpenFileDialog
Dim WithEvents txtFile As TextBox
Dim WithEvents btnOpen As Button
Dim WithEvents btnWriteFile As Button
Const LogFile As String = "Bill Of Material Log"
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ofd = New OpenFileDialog
ofd.Filter = "Text Files|*.txt|All files (*.*)|*.*"
ofd.Multiselect = True
txtFile = New TextBox
txtFile.Left = 12
txtFile.Top = 24
txtFile.Width = 160
txtFile.ReadOnly = True
Me.Controls.Add(txtFile)
btnOpen = New Button
btnOpen.Text = "Select A file"
btnOpen.Width = 75
btnOpen.Height = Me.txtFile.Height
btnOpen.Left = Me.txtFile.Left + Me.txtFile.Width + 4
btnOpen.Top = Me.txtFile.Top
Me.Controls.Add(btnOpen)
AddHandler btnOpen.Click, AddressOf OpenFileButtonClick
btnWriteFile = New Button
btnWriteFile.Width = 150
btnWriteFile.Text = "Transfer B.O.M To Text "
btnWriteFile.Top = Me.txtFile.Top + Me.txtFile.Height + 6
btnWriteFile.Left = 12
Me.Controls.Add(btnWriteFile)
AddHandler btnWriteFile.Click, AddressOf WriteFileButtonClick
End Sub
Private Sub OpenFileButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.txtFile.Text = ""
ofd.ShowDialog()
Me.txtFile.Text = ofd.FileName
End Sub
Private Sub WriteFileButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
ofd.ShowDialog()
If Not Me.txtFile.Text.Trim = "" Then
'Read the existing file
Dim FileText As String = ""
FileText = System.IO.File.ReadAllText(Me.txtFile.Text)
'Write to the log file
System.IO.File.AppendAllText(LogFile, FileText)
Timer1.Start()
Timer1.Enabled = True
MessageBox.Show("B.O.M Transfered")
Else
MessageBox.Show("Please select a file.")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PB1.Increment(50)
If PB1.Value = PB1.Maximum Then
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strTextLine As String
Dim strArray() As String
Dim i As Short = 0
FileOpen(1, "C:\Users\spritchard\Desktop\Atec Text Extractor\Application Files\Bill Of Material Master log File\Bill Of Material Log.txt", OpenMode.Input)
FileOpen(2, "C:\Users\spritchard\Desktop\Atec Text Extractor\saw.xls", OpenMode.Output)
FileOpen(3, "C:\Users\spritchard\Desktop\Atec Text Extractor\burn.xls", OpenMode.Output)
FileOpen(4, "C:\Users\spritchard\Desktop\test.txt", OpenMode.Output)
Do While Not EOF(1)
strTextLine = LineInput(1)
strArray = Split(strTextLine, " ")
Select Case UCase(strArray(1))
Case "C", "FB", "L", "PL", "RB", "S", "SB", "TS", "SW"
PrintLine(2, strTextLine)
Case "PL", "SHT", "SR"
PrintLine(3, strTextLine)
Case Else
PrintLine(4, strTextLine)
End Select
Loop
FileClose(4)
FileClose(3)
FileClose(2)
FileClose(1)
MessageBox.Show("Lines Seperated and sent to Excel Spreedsheet")
'sort array here for left over records,
'write to text file left over records
End Sub
End Class
QTY ITM INVO MAT
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
1 a 23 ir
how do i get each row to an excel sheet and keep adding to the end of last row?
Public Class Form1
Dim ofd As OpenFileDialog
Dim WithEvents txtFile As TextBox
Dim WithEvents btnOpen As Button
Dim WithEvents btnWriteFile As Button
Const LogFile As String = "Bill Of Material Log"
Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ofd = New OpenFileDialog
ofd.Filter = "Text Files|*.txt|All files (*.*)|*.*"
ofd.Multiselect = True
txtFile = New TextBox
txtFile.Left = 12
txtFile.Top = 24
txtFile.Width = 160
txtFile.ReadOnly = True
Me.Controls.Add(txtFile)
btnOpen = New Button
btnOpen.Text = "Select A file"
btnOpen.Width = 75
btnOpen.Height = Me.txtFile.Height
btnOpen.Left = Me.txtFile.Left + Me.txtFile.Width + 4
btnOpen.Top = Me.txtFile.Top
Me.Controls.Add(btnOpen)
AddHandler btnOpen.Click, AddressOf OpenFileButtonClick
btnWriteFile = New Button
btnWriteFile.Width = 150
btnWriteFile.Text = "Transfer B.O.M To Text "
btnWriteFile.Top = Me.txtFile.Top + Me.txtFile.Height + 6
btnWriteFile.Left = 12
Me.Controls.Add(btnWriteFile)
AddHandler btnWriteFile.Click, AddressOf WriteFileButtonClick
End Sub
Private Sub OpenFileButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.txtFile.Text = ""
ofd.ShowDialog()
Me.txtFile.Text = ofd.FileName
End Sub
Private Sub WriteFileButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
ofd.ShowDialog()
If Not Me.txtFile.Text.Trim = "" Then
'Read the existing file
Dim FileText As String = ""
FileText = System.IO.File.ReadAllText(Me.txtFile.Text)
'Write to the log file
System.IO.File.AppendAllText(LogFile, FileText)
Timer1.Start()
Timer1.Enabled = True
MessageBox.Show("B.O.M Transfered")
Else
MessageBox.Show("Please select a file.")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PB1.Increment(50)
If PB1.Value = PB1.Maximum Then
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strTextLine As String
Dim strArray() As String
Dim i As Short = 0
FileOpen(1, "C:\Users\spritchard\Desktop\Atec Text Extractor\Application Files\Bill Of Material Master log File\Bill Of Material Log.txt", OpenMode.Input)
FileOpen(2, "C:\Users\spritchard\Desktop\Atec Text Extractor\saw.xls", OpenMode.Output)
FileOpen(3, "C:\Users\spritchard\Desktop\Atec Text Extractor\burn.xls", OpenMode.Output)
FileOpen(4, "C:\Users\spritchard\Desktop\test.txt", OpenMode.Output)
Do While Not EOF(1)
strTextLine = LineInput(1)
strArray = Split(strTextLine, " ")
Select Case UCase(strArray(1))
Case "C", "FB", "L", "PL", "RB", "S", "SB", "TS", "SW"
PrintLine(2, strTextLine)
Case "PL", "SHT", "SR"
PrintLine(3, strTextLine)
Case Else
PrintLine(4, strTextLine)
End Select
Loop
FileClose(4)
FileClose(3)
FileClose(2)
FileClose(1)
MessageBox.Show("Lines Seperated and sent to Excel Spreedsheet")
'sort array here for left over records,
'write to text file left over records
End Sub
End Class