私は単純なマッチングアルゴリズムに取り組んでいます。私はプログラミングが初めてで、エラーが発生することをよく理解していません。
File.txt には、次の形式のデータが含まれています (各行の間にスペースはありません)。
5,Name,9,9,9,9
4,Name,4,8,0,3
3,Name,4,7,3,5
2,Name,3,5,6,3
1,Name,5,8,2,9
0,Name,2,5,3,2
「タイプ 'System.InvalidCastException' の初回例外が Microsoft.VisualBasic.dll で発生しました
追加情報: 文字列 "" から型 'Integer' への変換は無効です。"
「CustomNrOld = splits(0)」でエラーが発生し、その理由がわかりません。
どんな種類の助けでも嬉しいです!!
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim CustomNrNew As Integer
Dim NameIDnew As String
Dim Alphanew As Integer
Dim Betanew As Integer
Dim Gammanew As Integer
Dim Deltanew As Integer
Dim CustomNrOld As Integer
Dim NameIDold As String
Dim Alphaold As Integer
Dim Betaold As Integer
Dim Gammaold As Integer
Dim Deltaold As Integer
Dim R1 As Integer
Dim R2 As Integer
Dim R3 As Integer
Dim R4 As Integer
Using sr As New StreamReader("C:\\Users\\Paul\\Documents\\Weever\\file.txt")
Dim splits As String() = sr.ReadLine.Split(","c)
CustomNrNew = splits(0)
NameIDnew = splits(1)
Alphanew = splits(2)
Betanew = splits(3)
Gammanew = splits(4)
Deltanew = splits(5)
End Using
Using sr As New StreamReader("C:\\Users\\Paul\\Documents\\Weever\\file.txt")
sr.ReadLine()
Do While Not sr.EndOfStream
Dim splits As String() = sr.ReadLine.Split(","c)
CustomNrOld = splits(0)
NameIDold = splits(1)
Alphaold = splits(2)
Betaold = splits(3)
Gammaold = splits(4)
Deltaold = splits(5)
If Alphanew >= Alphaold = True Then
R1 = (Alphaold / Alphanew) * 100
Else
R1 = (Alphanew / Alphaold) * 100
End If
If Betanew >= Betaold = True Then
R2 = (Betaold / Betanew) * 100
Else
R2 = (Betanew / Betaold) * 100
End If
If Gammanew >= Gammaold = True Then
R3 = (Gammaold / Gammanew) * 100
Else
R3 = (Gammanew / Gammaold) * 100
End If
If Deltanew >= Deltaold = True Then
R4 = (Deltaold / Deltanew) * 100
Else
R4 = (Deltanew / Deltaold) * 100
End If
Dim Result As Integer
Result = ((R1 + R2 + R3 + R4) / 4)
My.Computer.FileSystem.WriteAllText("C:\\Users\\Paul\\Documents\\Weever\\" & NameIDnew & ".txt",
Result & "%" & " - " & NameIDold & " " & R1 & "% / " & R2 & "% / " & R3 & "% / " & R4 & "% " & Environment.NewLine, True)
My.Computer.FileSystem.WriteAllText("C:\\Users\\Paul\\Documents\\Weever\\" & NameIDold & ".txt",
Result & "%" & " - " & NameIDnew & " " & R1 & "% / " & R2 & "% / " & R3 & "% / " & R4 & "% " & Environment.NewLine, True)
Loop
End Using