×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Error Handling in VB Data Trouble

Error Handling in VB Data Trouble

Error Handling in VB Data Trouble

(OP)
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.
Replies continue below

Recommended for you

RE: Error Handling in VB Data Trouble

You might want to visit the sister site to this: Tek-Tips.com  That is where the computer geeks live and die!!

RE: Error Handling in VB Data Trouble

What error message does your code return?

I notice you have commented out the messages returned by the exception objects, try turning them back on (or adding them as necessary); the information they return will help track down the problem(s).

www.nxjournaling.com

RE: Error Handling in VB Data Trouble

(OP)
The problem was occurring at the Parse functions.  It was saying the data was in the wrong format.  But the files looked fine, in notepad they were in numerical format.

When I manually told UG to put the splines in no problem, they worked, when I used excel to go into the files and make the column format numerical, no problem.  I figure there has to be something more that is being done to the data to format the data, that I'm not calling in my code.

I know it is the Parse functions cause I pulled them out of the Try Catch block and got the error about wrong formatting.

RE: Error Handling in VB Data Trouble

Is there any example data you could post for testing purposes?

www.nxjournaling.com

RE: Error Handling in VB Data Trouble

(OP)
The error message states:
System.FormatException:Input string was not in a correct format
at system.Number.StringtoNumber(String str, NumberStyles options, NumberBuffer_number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.Parse Double(string value, NumberStyles options, NumberFormatInfo numfmt)
at System.DoubleParse(String s, NumberStyles style, NumberFormatInfo info)
at NXJournal.CreateTopSurfaceSpline(String strDir, Transform transform, LIne lineChord, Line lineTE, Int32_counter) in [dir location]

RE: Error Handling in VB Data Trouble

You get an error because there is a blank line at the end of the file. Here is a small code snippet I used to loop through your file and check for blank lines:

CODE

Dim readLine            As String
Dim strings             As String ()
Dim pt1 As Point3d

Dim sr As IO.StreamReader = IO.File.OpenText("C:\Temp\S10BOT.dat")
Try
    Do While sr.Peek >= 0
    readLine = sr.ReadLine
        if Len(Trim(readLine)) > 0 then
            strings = readLine.Split( vbTab )
            msgbox(strings(0) & ", " & strings(1) & ", " & strings(2))
            pt1.x = Double.Parse(strings(0))
            pt1.y = Double.Parse(strings(1))
            pt1.z = Double.Parse(strings(2))
        end if
    Loop
Catch ex As Exception
    MsgBox("Wrong data format")
End Try
Blank lines will be skipped, and you'll get the "Wrong data format" message if the line cannot be parsed into doubles.

www.nxjournaling.com

RE: Error Handling in VB Data Trouble

(OP)
I should have checked that.  Thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close