DECLARE SUB leggistringa (a$, ID$, dat$, sostanza$, valore!)
Rem tabella batta
Dim sosta$(20)
Dim vettore(20), flag(20) As Single
Data "Al", "As", "B", "Cd", "Co", "Cond", "Cr_tot", "Cr_VI", "Fe", "Mn", "Hg", "Ni", "pH", "Pb", "Pot_Redox", "Cu", "Se", "SO4", "Temp", "Zn"
For i = 1 To 20
READ sosta$(i)
Next i
dire$ = "F:dosatta"
nome$ = "dati"
nomeinp$ = dire$ + nome$ + ".csv"
nomeout$ = dire$ + nome$ + ".dat"
Open nomeinp$ For Input As #1
Open nomeout$ For Output As #2
Line Input #1, a$
oldid$ = "null"
For i = 1 To 20
flag(i) = 0
vettore(i) = 0
Next i
Do Until EOF(1)
Line Input #1, a$
Call leggistringa(a$, ID$, dat$, sost$, valore)
If oldid$ = "null" Then
oldid$ = ID$
olddat$ = dat$
End If
If ID$ = oldid$ Then
For i = 1 To 20
If flag(i) = 0 Then
If InStr(sosta$(i), sost$) = 1 Then
vettore(i) = valore
flag(i) = 1
Else
vettore(i) = -9999
End If
End If
Next i
Else
Rem costruisce la stringa
cc$ = oldid$ + ";" + olddat$ + ";"
Print #2, cc$;
For i = 1 To 20
Print #2, vettore(i);
Print #2, ";";
Next i
Print #2, vettore(20)
oldid$ = ID$
olddat$ = dat$
For i = 1 To 20
flag(i) = 0
vettore(i) = 0
Next i
For i = 1 To 20
If flag(i) = 0 Then
If InStr(sosta$(i), sost$) = 1 Then
flag(i) = 1
vettore(i) = valore
Else
vettore(i) = -9999
End If
End If
Next i
End If
Rem PRINT a$
Loop
Close #2
Close #1
End
Sub leggistringa(a$, ID$, dat$, sostanza$, valore)
lung = Len(a$)
If Mid$(a$, lung, 1) <> ";" Or Mid$(a$, lung, 1) <> "," Then
lung = lung + 1
a$ = a$ + ";"
End If
Index = 0
b$ = ""
For i = 1 To lung
c$ = Mid$(a$, i, 1)
If c$ = ";" Or c$ = "," Then
Index = Index + 1
Select Case Index
Case 1
ID$ = b$
b$ = ""
Case 2
dat$ = b$
b$ = ""
Case 3
sostanza$ = b$
b$ = ""
Case 8
valore = Val(b$)
b$ = ""
Case Else
b$ = ""
End Select
Else
b$ = b$ + c$
End If
Next i
End Sub |