Message 1 of 5
Help simplifying code.

Not applicable
10-07-2009
06:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All,
I'm trying to automate some things at work and I have this code which works but I don't like looking at how long it is. How do I shorten this simple code so that I can have the string length vary between 5 & 12 characters. Actually it can be much more than that, I just did not want to copy and paste over and over again.
Here is my code:
{code}
Public Sub Saveas_DXF15()
Dim strDrawingFullName As String
Dim MyString As String
Dim StringLength As Integer
MyString = ThisDrawing.Name
StringLength = Len(MyString)
If StringLength = 8 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 5))
End If
If StringLength = 9 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 6))
End If
If StringLength = 10 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 7))
End If
If StringLength = 11 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 8))
End If
If StringLength = 12 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 9))
End If
If StringLength = 13 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 10))
End If
If StringLength = 14 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 11))
End If
If StringLength = 15 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 12))
End If
ThisDrawing.saveas strDrawingFullName, acR15_dxf
'SET FILEDIA TO "1"
sysVarName = "FILEDIA"
ThisDrawing.SetVariable sysVarName, 1
ThisDrawing.Close
End Sub
{code}
All help is greatly appreciated.
Thanks,
Shawn
I'm trying to automate some things at work and I have this code which works but I don't like looking at how long it is. How do I shorten this simple code so that I can have the string length vary between 5 & 12 characters. Actually it can be much more than that, I just did not want to copy and paste over and over again.
Here is my code:
{code}
Public Sub Saveas_DXF15()
Dim strDrawingFullName As String
Dim MyString As String
Dim StringLength As Integer
MyString = ThisDrawing.Name
StringLength = Len(MyString)
If StringLength = 8 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 5))
End If
If StringLength = 9 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 6))
End If
If StringLength = 10 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 7))
End If
If StringLength = 11 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 8))
End If
If StringLength = 12 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 9))
End If
If StringLength = 13 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 10))
End If
If StringLength = 14 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 11))
End If
If StringLength = 15 Then
strDrawingFullName = Right(ThisDrawing.Path & "-", Len(ThisDrawing.Path) - 66) & (Left(ThisDrawing.Name, Len(ThisDrawing.Name) - 12))
End If
ThisDrawing.saveas strDrawingFullName, acR15_dxf
'SET FILEDIA TO "1"
sysVarName = "FILEDIA"
ThisDrawing.SetVariable sysVarName, 1
ThisDrawing.Close
End Sub
{code}
All help is greatly appreciated.
Thanks,
Shawn