I need some help with the following. The script below is part of a larger script that reads the window name which contains a file name. It extracts the file name only and converts it to upper case. It does what I want 99% of the time but it has a little quirk.
If the file name begins with "cr" it does not work. It appears to transform it into a Cariage Return which is not what I want. I say this because the script locked up when using the Upper VB Script Command (it gave a VB script error) so I disabled the VB Script part. I inserted a Message box to see what I was getting and instead of an Upper Case CR i get a single bar in its place. However, if the "cr" is in the middle of the string it works fine. It also works fine with everything else I tested it with. So if it is a Carriage Return that it is converting it to, can it be fixed? If it isn't a Cariage Return what is it and any ideas on how it can be fixed?
Thanks in advance for any ideas.
Let>filename=Pitch - [crumbly.ext]
/////////////Remove Brackets
Let>Bracket1=]
Let>Bracket2=[
Let>k=0
Length>%filename%,lv
Let>NewVal=
Label>Trim22
Let>k=k+1
if>k>lv,Done22
MidStr>filename,k,1,char
If>char=%Bracket1%,Trim22
If>char=%Bracket2%,Trim22
ConCat>NewVal,char
Goto>Trim22
Label>Done22
Let>filename=NewVal
////////////////////////
Length>filename,len
Let>endpos=%len%
Sub>%endpos%,3
Let>filestringlen=%endPos%
Sub>%filestringlen%,9
MidSTR>%filename%,9,%filestringlen%,LoanNumber
Let>space=
Let>k=0
Length>LoanNumber,lv
Let>NewVal=
Label>Trim2
Let>k=k+1
if>k>lv,Done2
MidStr>LoanNumber,k,1,char
If>char=%space%,Trim2
ConCat>NewVal,char
Goto>Trim2
Label>Done2
Let>LoanNumber=NewVal
////////////Convert to Upper//////////////
/VBSTART
/VBEND
/VBEval>UCase("%LoanNumber%"),LoanNumber
MDL>%LoanNumber%
Script reads "cr" as Cariage Return instead of as
Moderators: JRL, Dorian (MJT support)
I can see why. Because you are going through the string char by char when you get cr together it works as a carriage return.
Your method is longwinded and cumbersome and you can avoid this problem easily. Here are two ways to do what you want. The first works in 7.3, the other in all older versions:
//Using Complex Expressions (7.3)
Let>filename=Pitch - [crumbly.ext]
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
MessageModal>LoanNumber
//Old Way
Let>filename=Pitch - [crumbly.ext]
Position>[,filename,1,pb
Let>pb=pb+1
Length>filename,lenf
MidStr>filename,pb,lenf,filename
Position>.,filename,1,pd
Let>pd=pd-1
MidStr>filename,1,pd,LoanNumber
VBSTART
VBEND
VBEval>UCase("%LoanNumber%"),LoanNumber
MessageModal>LoanNumber
Hope this helps.
Your method is longwinded and cumbersome and you can avoid this problem easily. Here are two ways to do what you want. The first works in 7.3, the other in all older versions:
//Using Complex Expressions (7.3)
Let>filename=Pitch - [crumbly.ext]
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
MessageModal>LoanNumber
//Old Way
Let>filename=Pitch - [crumbly.ext]
Position>[,filename,1,pb
Let>pb=pb+1
Length>filename,lenf
MidStr>filename,pb,lenf,filename
Position>.,filename,1,pd
Let>pd=pd-1
MidStr>filename,1,pd,LoanNumber
VBSTART
VBEND
VBEval>UCase("%LoanNumber%"),LoanNumber
MessageModal>LoanNumber
Hope this helps.
MJT Net Support
[email protected]
[email protected]
Remove the spaces
Thank you for your help. However, if I use either of these examples it appears that the spaces will still be in the filename. I need to remove the spaces (forgot to mention that) as the new file name will be used to create a barcode that dosen't allow spaces. That is one reason I did it like I did and the other is I'm still working on getting good at this. Can I get rid of the spaces without reading the line charctor by character and ending up with the Cariage Return?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
How about using VB to replace the space?
Untested sample:
Untested sample:
VBSTART
VBEND
Let>filename=Pitch - [crumbly.ext]
VBEval>Replace("%filename%"," ",""),newfilename
MessageModal>%filename%%CRLF%%CRLF%has been changed to %CRLF%%CRLF%%newfilename%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
VBSTART
VBEVAL
//Using Complex Expressions (7.3)
Let>filename=Pitch - [crumbly.ext]
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
MessageModal>LoanNumber
VBEval>Replace("%LoanNumber%"," ",""),LoanNumber
This extracts the part after the [ and before the . and then removes spaces.
T
VBEVAL
//Using Complex Expressions (7.3)
Let>filename=Pitch - [crumbly.ext]
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
MessageModal>LoanNumber
VBEval>Replace("%LoanNumber%"," ",""),LoanNumber
This extracts the part after the [ and before the . and then removes spaces.
T
MJT Net Support
[email protected]
[email protected]
Final Script that works with or without brackets
Another catch is that depending upon what window is open the file name displays diferently. I added a couple of lines for this and below is the finished working script. Now I just need to figure out why it works so well and thank you all.
VBSTART
VBEND
//Using Complex Expressions (7.3)
Position>%filename%,[,1,Bracket
If>%Bracket>0
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
Else
Let>LoanNumber={Upper(copy(%filename%,9,pos(".",%filename%)-1))}
Endif
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
VBEval>Replace("%LoanNumber%"," ",""),LoanNumber
MessageModal>LoanNumber
VBSTART
VBEND
//Using Complex Expressions (7.3)
Position>%filename%,[,1,Bracket
If>%Bracket>0
Let>LoanNumber={copy(%filename%,pos("[",%filename%)+1,length(%filename%))}
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
Else
Let>LoanNumber={Upper(copy(%filename%,9,pos(".",%filename%)-1))}
Endif
Let>LoanNumber={Upper(copy(%LoanNumber%,1,pos(".",%LoanNumber%)-1))}
VBEval>Replace("%LoanNumber%"," ",""),LoanNumber
MessageModal>LoanNumber