ปรึกษา VB6 แยกไฟล์แต่ละบรรทัดออกเป็นไฟล์ย่อยอีกทีครับ
ปรึกษา VB6 หน่อยครับ
มีไฟล์ test.txt ข้างในมีข้อมูลด้านล่างอ่ะคับ ต้องการให้แยกข้อมูลออกเป็นของใครของมันสามารถทำได้ไหมครับ
2,"J1(B1",27,"R","","test1"
2,"J1(B1",27,"R","","test2"
2,"J1(B1",28,"R","","test3"
2,"J1(B2",27,"N","","test4"
2,"J1(B2",27,"N","","test5"
2,"J1(B3",29,"N","","test6"
2,"J1(B3",29,"N","","test7"
2,"J1(B3",30,"N","","test8"
2,"J1(B3",30,"N","","test9"
2,"J1(B3",32,"N","","test10"
2,"J1(B3",32,"N","","test11"
2,"J1(B3",33,"N","","test12"
2,"J1(B3",33,"N","","test13"
2,"J1(B3",33,"N","","test14"
แยกเป็นชื่อใหม่
ไฟล์ 1.txt ข้างในก็จะมีแต่
2,"J1(B1",27,"R","","test1"
2,"J1(B1",27,"R","","test2"
2,"J1(B1",28,"R","","test3"
ไฟล์ 2.txt ข้างในก็จะมีแต่
2,"J1(B2",27,"N","","test4"
2,"J1(B2",27,"N","","test5"540
ไฟล์ 3.txt ข้างในก็จะมีแต่
2,"J1(B3",29,"N","","test6"
2,"J1(B3",29,"N","","test7"
2,"J1(B3",30,"N","","test8"
2,"J1(B3",30,"N","","test9"
2,"J1(B3",32,"N","","test10"
2,"J1(B3",32,"N","","test11"
2,"J1(B3",33,"N","","test12"
2,"J1(B3",33,"N","","test13"
2,"J1(B3",33,"N","","test14"
ขอบคุณครับTag : VB.NET
Date :
2014-09-02 13:33:27
By :
yuttanahk
View :
933
Reply :
4
โทษทีครับ ไฟล์ test.txt ไม่ได้เรียงข้อมูลเหมือนด้านบนมันสลับกันมั่วเลยครับ
เช่นต้องการแยก B1,B2,B3 ออกเป็นไฟล์ของใครของมันครับ
2,"J1(B3",33,"N","","test13"
2,"J1(B1",27,"R","","test2"
2,"J1(B1",28,"R","","test3"
2,"J1(B3",29,"N","","test6"
2,"J1(B2",27,"N","","test4"
2,"J1(B3",32,"N","","test10"
2,"J1(B2",27,"N","","test5"
2,"J1(B3",29,"N","","test7"
2,"J1(B3",30,"N","","test8"
2,"J1(B1",27,"R","","test1"
2,"J1(B3",30,"N","","test9"
2,"J1(B3",32,"N","","test11"
2,"J1(B3",33,"N","","test12"
2,"J1(B3",33,"N","","test14"
ขอบคุณครับ
Date :
2014-09-02 13:43:14
By :
yuttanahk
ก็มั่วๆ กันไป
Code (VBScript)
Dim FSO As FileSystemObject
Dim TS As TextStream
Dim TempS As String
Dim B1 As String
Dim B2 As String
Dim B3 As String
Set FSO = New FileSystemObject
Set TS = FSO.OpenTextFile("C:\source.txt", ForReading)
Do Until TS.AtEndOfStream
TempS = TS.ReadLine
If Mid(TempS, 7, 2) = "B1" Then
B1 = B1 & TempS & vbCrLf
ElseIf Mid(TempS, 7, 2) = "B2" Then
B2 = B2 & TempS & vbCrLf
Else
B3 = B3 & TempS & vbCrLf
Loop
Set TS = FSO.OpenTextFile("C:\B1.txt", ForWriting, True)
TS.Write B1
TS.Close
Set TS = FSO.OpenTextFile("C:\B2.txt", ForWriting, True)
TS.Write B2
TS.Close
Set TS = FSO.OpenTextFile("C:\B3.txt", ForWriting, True)
TS.Write B3
TS.Close
Set TS = Nothing
Set FSO = Nothing
TS.Close
Date :
2014-09-02 16:52:09
By :
ห้ามตอบเกินวันละ 2 กระทู้
พี่คับ error ทัด Dim FSO As FileSystemObject ฟ้องว่า User-Defined Type Not Defined เกิดจากอะไรหรอครับ ต้องขอขอบคุณนะครับที่ช่วยเขียนโค๊ดให้ครับ
Date :
2014-09-02 17:43:43
By :
yuttanahk
ได้แล้วครับ ขอบคุณมากๆเลยครับ คุณGuest
Date :
2014-09-02 19:37:48
By :
yuttanahk
Load balance : Server 00