Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. Explanation of function

Explanation of function

Scheduled Pinned Locked Moved Visual Studio
csharp
3 Posts 2 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ccodebase
    wrote on last edited by
    #1

    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 48

    Public 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

    Richard DeemingR 1 Reply Last reply
    0
    • C ccodebase

      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 48

      Public 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

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      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:

      1. It creates an array of 50 elements of some unknown type.
      2. It opens the "postable.csv" file from the current working directory and reads it in line-by-line.
      3. 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.
      4. 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

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      C 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        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:

        1. It creates an array of 50 elements of some unknown type.
        2. It opens the "postable.csv" file from the current working directory and reads it in line-by-line.
        3. 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.
        4. 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

        C Offline
        C Offline
        ccodebase
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups