|
|
|
Импортирование *.txt
|
|||
|---|---|---|---|
|
#18+
Вопрос глупый. Импортирую из txt-шника в таблицу. Есть 2 кода. Первый работае, второй - нет. Они относятся к разным типам импортируемых файлов, но в общем являются аналогичными. Подскажите в чем ошибка. И еще : во втором коде строка вида : ААА "ИИИ" сохраняется в массиве только в виде ААА. Когда же в строке нет кавычек - все нормально. Правильно работающий код: ====== Private Sub ImportUSBank(theSourcePath, theSourceFile, theTableName) Dim tblImpName, rst As New ADODB.Recordset, theDate, theDocNum, theCounter, theArrayTemp(50), strJoined, theArrayFinal tblImpName = "imp_USBank" With rst .Open "SELECT * FROM [Text;DATABASE=" & theSourcePath & "\]." & theSourceFile, CurrentProject.Connection, adOpenKeyset, adLockOptimistic .Find "[" & .Fields(0).Name & "] Like '*(-C-)*'", , adSearchForward Do While Not .EOF theDate = DateSerial(Mid(.Fields(0), 33, 4), Mid(.Fields(0), 30, 2), Mid(.Fields(0), 27, 2)) theDocNum = Mid(.Fields(0), 45) .MoveNext: theCounter = 0 Do While Trim(.Fields(0)) <> "" theArrayTemp(theCounter) = Trim(Left(.Fields(0), 10) & Replace(.Fields(0), ":", " ", 11)) .MoveNext: theCounter = theCounter + 1 Loop strJoined = Join(theArrayTemp, "") theArrayFinal = Split(strJoined, ":") dbTransfer.Execute "Insert Into " & tblImpName & " (A, b, c, d, e, f, g, h) " & _ "Values ('" & theDate & "', '" & theDocNum & "', " & Replace(Replace(theArrayFinal(1), "(RUR)", ""), ",", "") & ", '" & theArrayFinal(3) & "', '" & theArrayFinal(5) & "', '" & theArrayFinal(7) & "', '" & theArrayFinal(9) & "', '" & theArrayFinal(11) & "')" Erase theArrayTemp .Find "[" & .Fields(0).Name & "] Like '*(-C-)*'", 1, adSearchForward Loop End With dbTransfer.Execute "Insert Into " & theTableName & " IN '" & dbMainName & "' " & dbTransfer.QueryDefs("qdf_" & Mid(tblImpName, 5)).SQL dbTransfer.Execute "DELETE * FROM [" & tblImpName & "]" End Sub Второй (плохой) код : ===== Private Sub ImportUSBank(theSourcePath, theSourceFile, theTableName) Dim tblImpName, rst As New ADODB.Recordset, theDate, theDocNum, theCounter, theArrayTemp(100), strJoined, theArrayFinal tblImpName = "imp_USBank" With rst .Open "SELECT * FROM [Text;DATABASE=" & theSourcePath & "\]." & theSourceFile, CurrentProject.Connection, adOpenKeyset, adLockOptimistic .Find "[" & .Fields(0).Name & "] Like 'Iiia?*'", , adSearchForward Do While Not .EOF theDocNum = Mid(.Fields(0), 7) .MoveNext theDate = DateSerial(Mid(.Fields(0), 12, 2), Mid(.Fields(0), 9, 2), Mid(.Fields(0), 6, 2)) .MoveNext: theCounter = 0 Do While Trim(Left(.Fields(0), 5)) <> "Iiia?" theArrayTemp(theCounter) = Trim("=" & .Fields(0)) .MoveNext: theCounter = theCounter + 1 Loop strJoined = Join(theArrayTemp, "") theArrayFinal = Split(strJoined, "=") dbTransfer.Execute "Insert Into " & tblImpName & " (A, b, c, d, e, f, g, h) " & _ "Values ('" & theDate & "', '" & theDocNum & "', '" & theArrayFinal(2) & "' , '" & theArrayFinal(10) & "'" & "'" & theArrayFinal(14) & "'" & "'" & theArrayFinal(22) & "', '" & theArrayFinal(24) & "', '" & theArrayFinal(44) & "', '" & theArrayFinal(42) & "'" & "'" & theArrayFinal(48) & "'" & "'" & theArrayFinal(52) & "', '" & theArrayFinal(60) & "')" Erase theArrayTemp Loop End With dbTransfer.Execute "Insert Into " & theTableName & " IN '" & dbMainName & "' " & dbTransfer.QueryDefs("qdf_" & Mid(tblImpName, 5)).SQL dbTransfer.Execute "DELETE * FROM [" & tblImpName & "]" End Sub Заранее спасибо ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 05.02.2007, 22:24 |
|
||
|
Импортирование *.txt
|
|||
|---|---|---|---|
|
#18+
У вас ошибка в 17-й строке. P.S. Вы правда думаете, что кто-то кинется разбираться в вашей куче даже не отформатированного кода, дабы понять суть фразы "не работает". Что не работает? Ошибка есть? ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.02.2007, 09:48 |
|
||
|
Импортирование *.txt
|
|||
|---|---|---|---|
|
#18+
Такая диссертация,чтобы поднять текстовый файл? Это же делается одной командой. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 06.02.2007, 09:49 |
|
||
|
|

start [/forum/topic.php?fid=60&msg=34308397&tid=2164557]: |
0ms |
get settings: |
8ms |
get forum list: |
14ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
164ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
30ms |
get tp. blocked users: |
1ms |
| others: | 229ms |
| total: | 464ms |

| 0 / 0 |
