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.
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.
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
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
CODE
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
RE: Visual Basic, Logic Problem
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
CODE
CODE