I have a fairly simple program in VB. I would like someone to spend an hour explaining how it works. I used to write some VBA macros but I am not familiar with some of the stuff in this program.
The input for the program is a csv file and the output will also be a csv file. I will paste it in below.
Thanks!
Public Class Form1
Dim finput As String = "input.csv"
Dim groupdata As String = "groupdata.csv"
Dim output As String = "output.csv"
Dim data(205, 27) As Double
Dim va(205), vb(205), v As Double
Dim gr(205), g As Byte
Private Sub button1_Click(ByVal sender As [login to view URL], ByVal e As [login to view URL]) Handles [login to view URL]
inp()
run()
out()
End Sub
Public Sub run()
Dim a, b As Integer
Dim tmp As Double
For a = 1 To 205
va(a) = calaver(a, gr(a))
For b = 1 To g
If b <> gr(a) Then
tmp = calaver(a, b)
If tmp < vb(a) Or vb(a) = 0 Then
vb(a) = tmp
End If
End If
Next
v = v + (vb(a) - va(a)) / max(vb(a), va(a))
Next
v = v / 205
End Sub
Function max(ByVal v1 As Double, ByVal v2 As Double) As Double
If v1 >= v2 Then
max = v1
Else
max = v2
End If
End Function
Function calaver(ByVal fr As Integer, ByVal ds As Integer) As Double
Dim a, b, n As Integer
Dim tmpv, result As Double
result = 0
n = 0
For a = 1 To 205
If gr(a) = ds And a <> fr Then
tmpv = 0
For b = 1 To 27
tmpv = tmpv + (data(fr, b) - data(a, b)) ^ 2
Next
tmpv = tmpv ^ 0.5
n = n + 1
result = result + tmpv
End If
Next
result = result / n
calaver = result
If n = 0 Then calaver = 0
End Function
Public Sub inp()
Dim fn, a, b As Integer
fn = FreeFile()
FileOpen(fn, finput, [login to view URL])
For a = 1 To 205
For b = 1 To 27
Input(fn, data(a, b))
Next
Next
FileClose(fn)
FileOpen(fn, groupdata, [login to view URL])
For a = 1 To 205
Input(fn, gr(a))
If gr(a) > g Then
g = gr(a)
End If
Next
FileClose(fn)
End Sub
Public Sub out()
Dim fn, a As Integer
fn = FreeFile()
FileOpen(fn, output, [login to view URL])
For a = 1 To 205
WriteLine(fn, va(a), vb(a), (vb(a) - va(a)) / max(vb(a), va(a)))
Next
Write(fn, v)
FileClose(fn)
End Sub
Private Sub Button2_Click(ByVal sender As [login to view URL], ByVal e As [login to view URL]) Handles [login to view URL]
End
End Sub
End Class