Explanation of function
-
ok i ran across this vb.net 2008 code could someone explain to me what it is doing. thank you so much .
// Mapped Holes Location on wheel
CSV Structure is
01,-0.12343,1.34532
02, 0.62343,1.74532
03, 0.72343,1.34532
04, 0.62343,1.74532
05, 0.32343,1.34532
06,-0.62343,1.54532
07, 0.22343,1.84532
08,-0.62343,1.74532
....Etc to 48Public Sub New()
Try
If ORIHoles Is Nothing Then
ReDim ORIHoles(49)
Dim ff As Integer = FreeFile()
Dim tempstr As String
Dim atempstr() As String
FileOpen(ff, "postable.csv", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(ff)
tempstr = LineInput(ff)
atempstr = tempstr.Split(",")
If atempstr.GetUpperBound(0) = 2 Then
ORIHoles(CInt(atempstr(0))).Angle = CDbl(atempstr(1))
ORIHoles(CInt(atempstr(0))).Hypot = CDbl(atempstr(2))
End If
Loop
FileClose(ff)
End If
Catch ex As Exception
GeneralErrorHandler(ex.ToString)
End Try
End Sub -
ok i ran across this vb.net 2008 code could someone explain to me what it is doing. thank you so much .
// Mapped Holes Location on wheel
CSV Structure is
01,-0.12343,1.34532
02, 0.62343,1.74532
03, 0.72343,1.34532
04, 0.62343,1.74532
05, 0.32343,1.34532
06,-0.62343,1.54532
07, 0.22343,1.84532
08,-0.62343,1.74532
....Etc to 48Public Sub New()
Try
If ORIHoles Is Nothing Then
ReDim ORIHoles(49)
Dim ff As Integer = FreeFile()
Dim tempstr As String
Dim atempstr() As String
FileOpen(ff, "postable.csv", OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Do While Not EOF(ff)
tempstr = LineInput(ff)
atempstr = tempstr.Split(",")
If atempstr.GetUpperBound(0) = 2 Then
ORIHoles(CInt(atempstr(0))).Angle = CDbl(atempstr(1))
ORIHoles(CInt(atempstr(0))).Hypot = CDbl(atempstr(2))
End If
Loop
FileClose(ff)
End If
Catch ex As Exception
GeneralErrorHandler(ex.ToString)
End Try
End SubWhat an absolute mess! It's VB.NET code; but it's using the ancient and long-dead VB6 file access functions, instead of the newer, easier, and far superior .NET Framework methods. It's also performing file access within a constructor, which seems like a terrible design choice. Essentially:
- It creates an array of 50 elements of some unknown type.
- It opens the "postable.csv" file from the current working directory and reads it in line-by-line.
- It splits each line using the comma as a separator - an over-simplified CSV parser, but it should be OK for the file you've shown.
- If the line contains three values, it uses the first as the index into the array; stores the second value in the "Angle" property of that array element; and stores the third value in the "Hypot" property of that array element.
If anything goes wrong, it calls a method called
GeneralErrorHandler
. Unless that method throws a new exception, the error will be swallowed, and you'll be left with an instance of your class in an invalid state, with no way of knowing that it's not happy. If this is code you've found somewhere on the internet and you're hoping it will solve a problem you have, back away slowly and never look at this code again. If it's part of an application you're trying to maintain, find the developer responsible for this monstrosity and give them a vigorous talking-to with the clue bat.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
What an absolute mess! It's VB.NET code; but it's using the ancient and long-dead VB6 file access functions, instead of the newer, easier, and far superior .NET Framework methods. It's also performing file access within a constructor, which seems like a terrible design choice. Essentially:
- It creates an array of 50 elements of some unknown type.
- It opens the "postable.csv" file from the current working directory and reads it in line-by-line.
- It splits each line using the comma as a separator - an over-simplified CSV parser, but it should be OK for the file you've shown.
- If the line contains three values, it uses the first as the index into the array; stores the second value in the "Angle" property of that array element; and stores the third value in the "Hypot" property of that array element.
If anything goes wrong, it calls a method called
GeneralErrorHandler
. Unless that method throws a new exception, the error will be swallowed, and you'll be left with an instance of your class in an invalid state, with no way of knowing that it's not happy. If this is code you've found somewhere on the internet and you're hoping it will solve a problem you have, back away slowly and never look at this code again. If it's part of an application you're trying to maintain, find the developer responsible for this monstrosity and give them a vigorous talking-to with the clue bat.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
oh yes i understand the rigors of this code, i agree with you , but some simple c++ with those numbers hard coded into the array would work in c++ just don't know exactly were to start to get the outcome. even if i start with a small Array i can add to it later, [1] - Index [2]-Angle [3]-Hypot
01,-0.84415,0.35416
02,-0.64350,0.29412
03,-0.35877,0.25129
04,0.00000,0.23529
05,0.35877,0.25129
06,0.64350,0.29412
07,0.84415,0.35416
08,-0.68573,0.41802
09,-0.49935,0.36853
10,-0.26625,0.33535