×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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

Visual Basic, Logic Problem

Visual Basic, Logic Problem

Visual Basic, Logic Problem

(OP)
I know the problem in here has to be the logic, but for the life of me I can't find it.  Any help would be appreciated.

CODE

strSValue = "s" & svalue             'Set strSValue to s#
      strSValue2 = "s" & svalue & "="      'Set strSvalue2 to s#=
      strExpFile = "expressions test.exp"
      
      OpenFile( strDir, strExpFile )


      line = sr.ReadLine()
      '------------------------------------------------------------------------------------------
      '    While the file still has lines continue with if statements to compare lines with Strings
      '------------------------------------------------------------------------------------------

      while Not line is Nothing

         '------------------------------------------------------------------------------------------
         '     Ensure before comparison that the line is not empty
         '------------------------------------------------------------------------------------------
         If Len( line ) > 2

            '------------------------------------------------------------------------------------------
            '     Take the read line from the file, and set strExp equal to the string starting at the
            '         fourth character and reading the following 3
            '------------------------------------------------------------------------------------------
            strExp = line.substring( 4, 3 )

            '------------------------------------------------------------------------------------------
            '     Check that the value of strExp equals strSValue (s#) or strSValue(s#=)
            '         if yes, increment # and reset the string values exit if statement
            '------------------------------------------------------------------------------------------
            If ( strExp = strSValue or strExp = strSvalue2 ) Then
               sValue = sValue + 1
               strSValue = "s" & svalue
               strSValue2 = strSValue & "="
         
         'ElseIf strExp = strSvalue2 Then
            'sValue = sValue + 1
            'strSValue = "s" & sValue
            'strSValue2 = strSValue & sValue
            End If
         End If
         '------------------------------------------------------------------------------------------
         '     Read next line of file and return to beginning of while statement
         '------------------------------------------------------------------------------------------
         line = sr.readline()
      End while

I am trying to read a file that looks as follows, but I only want to know how many s# values there are, I do not wish to count the s#_chord etc.

[degrees]Tool=11.00
[mm]BladeLength=26475.00
[mm]BladeDef=1450.00
[mm]S1=0.00
[mm]S2=700.00
[mm]S3=6135.00
[mm]S4=7485.00
[mm]S5=10185.00
[mm]S6=12885.00
[mm]S7=15585.00
[mm]S8=18285.00
[mm]S9=20985.00
[mm]S10=23685.00
[mm]S11=24765.00
[mm]S12=25305.00
[mm]S13=25845.00
[mm]S14=26115.00
[mm]S15=26385.00
[mm]S16=26475.00
[mm]S1_Chord=1250.00
[mm]S2_Chord=1250.00

Again I appreciate any help.

RE: Visual Basic, Logic Problem

This is the type of problem that regular expressions excel at. This site on regular expressions was (and is) a great help to me. Below is a quick example journal based on your data. I used an arraylist for testing, just take the important bits and integrate it into your file read loop.

CODE

Option Strict Off
Imports System
Imports System.Collections
Imports System.Text.RegularExpressions
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

Dim lw As ListingWindow = theSession.ListingWindow
Dim i as Integer = 0
Dim myValueList as New ArrayList()
myValueList.Add("[degrees]Tool=11.00")
myValueList.Add("[mm]BladeLength=26475.00")
myValueList.Add("[mm]BladeDef=1450.00")
myValueList.Add("[mm]S1=0.00")
myValueList.Add("[mm]S2=700.00")
myValueList.Add("[mm]S3=6135.00")
myValueList.Add("[mm]S4=7485.00")
myValueList.Add("[mm]S5=10185.00")
myValueList.Add("[mm]S6=12885.00")
myValueList.Add("[mm]S7=15585.00")
myValueList.Add("[mm]S8=18285.00")
myValueList.Add("[mm]S9=20985.00")
myValueList.Add("[mm]S10=23685.00")
myValueList.Add("[mm]S11=24765.00")
myValueList.Add("[mm]S12=25305.00")
myValueList.Add("[mm]S13=25845.00")
myValueList.Add("[mm]S14=26115.00")
myValueList.Add("[mm]S15=26385.00")
myValueList.Add("[mm]S16=26475.00")
myValueList.Add("[mm]S1_Chord=1250.00")
myValueList.Add("[mm]S2_Chord=1250.00")

'the pattern is set to look for S
'  followed by 1 or more digits (\d+),
'  followed by =
Dim re as New RegEx("S\d+=")

lw.Open
For Each myExp as String in myValueList
    if re.IsMatch(myExp) then
        i += 1
    end if
Next

lw.WriteLine(i.ToString & " items matched the specified regular expression")

lw.Close

End Sub
End Module

www.nxjournaling.com

RE: Visual Basic, Logic Problem

You might want to visit Tek-Tips, a sister to this site where the computer geeks live and hang out..

RE: Visual Basic, Logic Problem

(OP)
I ended up stumbling across this and it worked with the current program.

Dim douExp  As double = val(line.substring(5))

It skipped the [mm]s of each line and read until it came to a non number value, which made things quite a bit simpler.  

Posted just in case this is looked at by a person needing help in the future.

Thanks for the tip Mike, I'll check that site out.

RE: Visual Basic, Logic Problem

Why don't you change this line

CODE

If ( strExp = strSValue or strExp = strSvalue2 ) Then
to

CODE

If ( strExp = strSvalue2 ) Then

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