Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Handling in VB Data Trouble

Status
Not open for further replies.

Twullf

Programmer
Mar 13, 2012
2
US
I have an interesting conundrum. I am parsing some data reading it as strings and turning it to integers and using it in the program. My data looked good, it was all numbers but it kept creating an error saying the numbers were in the wrong format. When I formatted the data in excel to number format with enough decimal places it works fine.

I want to create a handle, preferably to fix the data and use it anyway, but I'm not entirely sure what the problem or why it is a problem. So I'm not sure how to fix it. Here is the sub as currently written.

Code:
   Public Sub CreateBotSurfaceSpline( byRef strDir as String, transform As Transform, byRef lineChord as Line, _
      byRef lineTE as Line, byRef counter as Integer )

      '------------------------------------------------------------------------------------------
      '   Import spline2 using points from file
      '------------------------------------------------------------------------------------------

      Dim strTFileName        As String = "S" & counter & "BOT.dat"
      Dim fileExist           As Boolean         
      Dim splinePoints( -1 )  As Point
      Dim botSpline           As Spline
      Dim readLine            As String
      Dim count               As Integer
      Dim strings             As String ()
      fileExist = true
         
      Try
         sr = File.OpenText( strDir & "\" & strTFileName )            
      Catch    'E As Exception
         'MessageBox.Show(E.Message)
         fileExist = false
      End Try

      '------------------------------------------------------------------------------------------
      '   If then statement, if spline file exists continue, if it does not, exit SubRoutine
      '------------------------------------------------------------------------------------------

      If fileExist = True

         '------------------------------------------------------------------------------------------
         '   Read Line, parse line, translate points, and place points in an array
         '------------------------------------------------------------------------------------------

         Try
            readLine = sr.ReadLine()
            count = 0
            While Not readLine is Nothing
               Dim pt1 As Point3d
               Dim pt2 as Point3d

               Try
                  strings = readLine.Split( vbTab )
                  pt1.x = Double.Parse(strings(0))
                  pt1.y = Double.Parse(strings(1))
                  pt1.z = Double.Parse(strings(2))

               Catch
                  MessageBox.Show( "Spline data file " & strTFileName & " must be tab deliminted. and located in " _
                     & strDir, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error )
                  Exit Sub
               End Try



               Try           
                  pt2 = Transform.Apply( New Point3d( pt1.x, pt1.y, pt1.z ))
               Catch
                  MessageBox.Show( "File data needs to be in full numerical format, no special characters.", _
                     "Error", MessageBoxButtons.OK, MessageBoxIcon.Error )
                  Exit Sub
               End Try

               '----------------------------------------------------------------------------------------
               '   Create an array of points, each array value containing a single point
               '----------------------------------------------------------------------------------------

               ReDim Preserve SplinePoints(count)
               SplinePoints(count) = workPart.Points.createPoint(pt2)

               '----------------------------------------------------------------------------------------
               '   Increase count value by 1, Read the next line of the file and continue While statement
               '----------------------------------------------------------------------------------------

               count = count + 1
                             
               readLine = sr.ReadLine()
            End While
         Finally
            sr.Close()
         End Try

         '------------------------------------------------------------------------------------------
         '   Place spline
         '------------------------------------------------------------------------------------------

         CreateSketchSpline( splinePoints, botSpline )

         '------------------------------------------------------------------------------------------
         '   Constrain botSpline to Uniform Scale
         '------------------------------------------------------------------------------------------

         Dim conGeom1 As Sketch.ConstraintGeometry

         conGeom1.Geometry = botSpline
         conGeom1.PointType = Sketch.ConstraintPointType.None
         conGeom1.SplineDefiningPointIndex = 0
         Dim sketchGeometricConstraint1 As SketchGeometricConstraint
         sketchGeometricConstraint1 = theSession.ActiveSketch.CreateUniformScaledConstraint(conGeom1)

         '------------------------------------------------------------------------------------------
         '   Constrain Botspline startpoint to be coincident with lineChord startpoint
         '------------------------------------------------------------------------------------------

         Dim geom1_1 As Sketch.ConstraintGeometry

         geom1_1.Geometry = BotSpline
         geom1_1.PointType = Sketch.ConstraintPointType.EndVertex
         geom1_1.SplineDefiningPointIndex = 0

         Dim geom2_1 As Sketch.ConstraintGeometry

         geom2_1.Geometry = lineChord
         geom2_1.PointType = Sketch.ConstraintPointType.StartVertex
         geom2_1.SplineDefiningPointIndex = 0
         Dim sketchGeometricConstraint2 As SketchGeometricConstraint
         sketchGeometricConstraint2 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_1, geom2_1)

         '------------------------------------------------------------------------------------------
         '   Constrain botSpline endpoint to be coincident with lineTE StartPoing
         '------------------------------------------------------------------------------------------
            
         Dim geom1_2 As Sketch.ConstraintGeometry

         geom1_2.Geometry = botSpline
         geom1_2.PointType = Sketch.ConstraintPointType.StartVertex
         geom1_2.SplineDefiningPointIndex = 0
         Dim geom2_2 As Sketch.ConstraintGeometry

         geom2_2.Geometry = lineTE
         geom2_2.PointType = Sketch.ConstraintPointType.StartVertex
         geom2_2.SplineDefiningPointIndex = 0
         Dim sketchGeometricConstraint3 As SketchGeometricConstraint
         sketchGeometricConstraint3 = theSession.ActiveSketch.CreateCoincidentConstraint(geom1_2, geom2_2)

      End If
   End Sub

Thanks for the help
 
Got the problem fixed. Was a space at the end of the file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top