Private Sub Command2_Click()
Result.Text = "" 'Cleaning textbox
CommonDialog1.Filter = "Text files|*.txt"
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1 'Apre il file in lettura
'Variables declaration
Dim Take As String
Dim scanrate As Double
Dim Estart As Double
Dim Eend As Double
Dim Eswitch As Double
Dim potential() As Double
Dim current() As Double
Dim ndata As Integer
ndata = 0
Dim counter1 As Integer
counter1 = 0
Dim time() As Double
Dim deltat As Double
'Reading cycle
Do Until EOF(1)
Line Input #1, Take 'N.B.: Takes the whole line in input, otherwise takes just the first
'characters before the first space!
If InStr(Take, "v (V/s):") > 0 Then
b = Split(Take, ": ") 'The line is divided in an array b(i) at each comma.
scanrate = b(1)
End If
If InStr(Take, "Estart (V):") > 0
b = Split(Take, ": ") 'The line is divided in an array b(i) at each comma.
Estart = b(1)
End If
If InStr(Take, "Eswitch (V):") > 0
b = Split(Take, ": ") 'The line is divided in an array b(i) at each comma.
Eswitch = b(1)
End If
If InStr(Take, "Eend (V):") > 0
b = Split(Take, ": ") 'The line is divided in an array b(i) at each comma.
Eend = b(1)
End If
If InStr(Take, "number of E(V), I(A) couples:") > 0 Then 'For Echem Files
b = Split(Take, ": ") 'The line is divided in an array b(i) at each comma.
ndata = b(1)
ReDim potential(ndata) As Double
ReDim current(ndata) As Double
ReDim time(ndata) As Double
End If
If InStr(Take, ",") > 0 And InStr(Take, "e-") > 0 Then
b = Split(Take, ",") 'The line is divided in an array b(i) at each comma.
potential(counter1) = b(0)
current(counter1) = b(1)
counter1 = counter1 + 1
End If
Loop
Close #1 'Closes the file *.txt
'Tensformation of E scale to time scale
counter1 = 0
deltat = 0.001 / scanrate
For counter1 = 0 To ndata - 1
time(counter1) = counter1 * deltat
Next
'Calculation of convolute convolute current
Dim curconv() As Double
ReDim curconv(ndata) As Double
counter1 = 0 'equal to K
Dim counter2 As Double 'equal to J
counter2 = 1
Dim calc1 As Double
Dim calc2 As Double
calc1 = 0
calc2 = 0
For counter1 = 0 To ndata - 1
calc2 = 0
For counter2 = 1 To counter1
calc1 = ((deltat ^ 0.5) * current(counter2)) / ((counter1 - counter2 + 0.5) ^ 0.5)
calc2 = calc2 + calc1
Next counter2
calc2 = (3.14 ^ -0.5) * calc2
curconv(counter1) = calc2
Next counter1
'Write on text box the results
counter1 = 0
Result.Text = Result & "Estart (V): " & Estart & vbCrLf
Result.Text = Result & "Eswitch (V): " & Eswitch & vbCrLf
Result.Text = Result & "Eend (V): " & Eend & vbCrLf
Result.Text = Result & "v (V/s): " & scanrate & vbCrLf
Result.Text = Result & "Diffusion Coefficient (cm/s): " & Text1 & vbCrLf & vbCrLf
For counter1 = 0 To ndata - 1
Result.Text = Result & potential(counter1) & " , " & current(counter1) & " , " & curconv(counter1) & vbCrLf
Next counter1
End If
End Sub