Salve a tutti, avendo la neccessita di recuperare dei dati da un file csv etrasferirli in un altro file.sql che contiene la procedura di importazione dei dati nelle tabelle con comandi in sql.. ho riscontrato che se il file csv ha circa 190 records da trattare non viè nessun problema tutto funziona alla perfezione, mentre se il file è più grande la procedura inizia ma poi mi viene restituito un errore di Runtime:6 Overflow questo è il codice che ho creato:
strfile_exp_count = (App.path & "\Archivio\") & "DATI-COMPLETI-19-12-2020" & (".csv")
Open strfile_exp_count For Input As #1
n = 0
Do While Not EOF(1)
Line Input #1, s
n = n + 1
Loop
Close #1
totale_righe.Caption = n
Dim totalnum As Integer
totalnum = n
Dim I As Long
I = 1
ProgressBar1.Min = 0
ProgressBar1.Max = n
Do
autoinc.Caption = I
Dim pulito As String
Dim strfile_exp As String
strfile_exp = (App.path & "\Archivio\") & "DATI-COMPLETI-19-12-2020" & (".csv")
Open strfile_exp For Input As #1
mostra.Text = Input$(LOF(1), #1)
Medio.Text = udf_ReadLine(mostra.Text, I) ' read line #1
pulito = Replace(Medio.Text, "'", "''")
Dim stmp As String
stmp = pulito
b = Split(pulito, ";")
mod_data_modifica = Format(b(10), "mm/dd/yyyy")
mod_data_nascita = Format(b(3), "mm/dd/yyyy")
SQLView.Text = "update ADMIN.LTA_ANAGRAFICA set LTA_DATAMODIFICA = TO_DATE('" & mod_data_modifica & " " & b(11) & "', 'MM/DD/YYYY HH24:MI:SS')," & "LTA_NOME = '" & b(0) & "'||' '||'" & b(1) & "', LTA_SESSO = '" & b(2) & "', LTA_NASCITA = TO_DATE('" & mod_data_nascita & " " & "00:00:00', 'MM/DD/YYYY HH24:MI:SS'), LTA_COMUNE_NASCITA='" & b(4) & "',LTA_INDIRIZZO = '" & b(8) & "', LTA_CITTA = '" & b(7) & "', LTA_CF = '" & b(6) & "' where lta_anag_id = (select ltr_anag_id from admin.ltr_richiesta where ltr_num_rich='" & b(12) & "');"
Close #1
strFilereport = (App.path & "\export\") & "Esportazione-SQL" & "-" & (Day(Date) & "-" & Month(Date) & "-" & Year(Date) & ".sql")
intFile3 = FreeFile
Open strFilereport For Append As #intFile3
Print #intFile3, SQLView.Text
Close #intFile3
If ProgressBar1.Value < I Then
ProgressBar1.Value = ProgressBar1.Value + 1
End If
I = I + 1
Loop Until I > totalnum
Label3.Caption = I
questa è la funzione Readline:
Private Function udf_ReadLine(ByVal sDataText As String, ByVal nLineNum As Long) As String
Dim sText As String, nI As Long, nJ As Long, sTemp As String
On Error GoTo ErrHandler
sText = ""
nI = 1
nJ = 1
sTemp = ""
While (nI <= Len(sDataText))
Select Case Mid(sDataText, nI, 1)
Case vbCr
If (nJ = nLineNum) Then
sText = sTemp
End If
Case vbLf
nJ = nJ + 1
sTemp = ""
Case Else
sTemp = sTemp & Mid(sDataText, nI, 1)
End Select
nI = nI + 1
Wend
If (nJ = nLineNum) Then
sText = sTemp
End If
udf_ReadLine = sText
Exit Function
ErrHandler:
udf_ReadLine = ""
End Function
Non riesco a capire perchè va in overflow... , forse dovrei usare un altro oggetto per memorizzarsi temporaneamente tutta la stringa elaborata?