Hello!
I was wondering if someone could help me with a problem im having. I'm trying to get specific data from a text file. I need de order no. and Short discription from a text file (See below). I've got it to work with only the first thing it see but it won't read the whole text file. I would also like it to count how many there are of the same "order no.:" so you get a count number next to it.
I hope someone can help me!
Best regards,
John
"Here is the text file"
UR
-Rack
(0)
Short description: UR
Order no.: 6ES7 390-1???0-0AA0
Designation: UR
Rack
(0),
Slot
1
Short description: PS 307 2A
Order no.: 6ES7 307-1BA01-0AA0
Designation: PS 307 2A
Width: 1
Comment: ---
Rack
(0),
Slot
2
Short description: CPU 314C-2 PN/DP
Firmware version: V3.3
Order no.: 6ES7 314-6EH04-0AB0
Designation: CPU 314C-2 PN/DP
Width: 1
Comment:
Inputs
Start: 4
End: 7
Rack
(0),
Slot
6
Short description: DO8xDC24V/2A
Order no.: 6ES7 322-1BF01-0AA0
Designation: DO8xDC24V/2A
Digital channels: 8 Outputs
Width: 1
Comment: Valves output
Addresses
Outputs
Start: 8
End: 8
Rack
(0),
Slot
7
Short description: DO8xDC24V/2A
Order no.: 6ES7 322-1BF01-0AA0
Designation: DO8xDC24V/2A
Digital channels: 8 Outputs
Width: 1
Comment: Valves output
Addresses
Outputs
Start: 12
End: 12
Rack
(0),
Slot
8
Short description: DO8xDC24V/2A
Order no.: 6ES7 322-1BF01-0AA0
Designation: DO8xDC24V/2A
Digital channels: 8 Outputs
Width: 1
Comment: Valves output
Addresses
"What i have till now"
VB:
Sub Button1_Click()
'Add column headers
Range("A1").Value = "Order Number:"
Range("B1").Value = "Short Discription:"
'Show open file dialog box
myFile = Application.GetOpenFilename()
'Open file
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
orderNumber = InStr(text, "Order no.:")
shortDiscription = InStr(text, "Short description:")
ActiveCell.Offset(row_number, 0) = Mid(text, orderNumber + 11, 20)
ActiveCell.Offset(row_number, 1) = Mid(text, shortDiscription + 19, 3)
row_number = row_number + 1
Loop
'Fitting column width
Sheet1.Cells.EntireColumn.AutoFit
'Close file
Close #1
End Sub
Bookmarks