IfFileExists problems or Operator Error

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Mirdurern
Newbie
Posts: 11
Joined: Mon Sep 27, 2004 5:46 pm

IfFileExists problems or Operator Error

Post by Mirdurern » Tue Sep 28, 2004 11:49 am

Hello all, I am new to making macros and ran into a problem on iffileexists command. Any help on how to fix this problem would be great. What I want to do is scan (wand in) serial numbers then confirms if that file exists in a specific path. Here is what I came up with. In addition, any books that you could suggest on how to learn VB or VB scripting would be great.

Thanks
Mike

here is the code.

VBSTART
Function GetName

GetName = InputBox("Enter Serial Number : ")

End Function
VBEND

VBEval>GetName,name

'Write a Serial Number to text file
WriteLn>R:\CustomData\Temp\test.txt,%name%
WriteLn>R:\CustomData\Temp\test.txt,%name%-1


ReadLn>R:\CustomData\Temp\test.txt,1,SN
ReadLn>R:\CustomData\Temp\test.txt,2,SNA


Let>path=R:\CustomData\WeekTEST
Let>file=ConCat>path,name


IfFileExists>file,End

Label>Start

SetFocus>Microsoft Word*
'WindowAction>1,Microsoft Word*


Press CTRL
Send Character/Text>o
Release CTRL
Send Character/Text>R:\CustomData\Temp\
Send Character/Text>DataSheet
Press Enter


Label>end
MessageModal>Your Serial Number was not found : %name%

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Sep 28, 2004 3:01 pm

I see a couple of problems, can point them out, but no time to test right now. My comments are in blue
'Write a Serial Number to text file
WriteLn>R:\CustomData\Temp\test.txt,%name%

//Cannot do math on variable like you are doing here.
WriteLn>R:\CustomData\Temp\test.txt,%name%-1
//Try something like this instead:
Sub>name,1
WriteLn>R:\CustomData\Temp\test.txt,%name%



ReadLn>R:\CustomData\Temp\test.txt,1,SN
ReadLn>R:\CustomData\Temp\test.txt,2,SNA

Let>path=R:\CustomData\WeekTEST

//Cannot combine functions in same line like trying here. Also need to include "\"
Let>file=ConCat>path,name
//Try something like this instead:
ConCat>path,\%name%
Let>file=path



//Labels are case sensitive. "End" does not exist, "end" does exist.
IfFileExists>file,End

Label>Start

SetFocus>Microsoft Word*
//Looks like extra character at beginning of line?
'WindowAction>1,Microsoft Word*


Press CTRL
Don't know if it applies, but some programs are Case Sensitive with CTRL/ALT characters.
Send Character/Text>o
Release CTRL
Send Character/Text>R:\CustomData\Temp\
Send Character/Text>DataSheet
Press Enter


Label>end
MessageModal>Your Serial Number was not found : %name%
General caution: also be sure to remove any Trailing Spaces from your script lines, especially when referring to labels, variables.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Sep 28, 2004 3:38 pm

You can also try this web site as an on-line reference for VB scripting.
http://msdn.microsoft.com/library/defau ... Script.asp

And MJT Net also has this page for VB Script support:
http://www.mjtnet.com/resources.htm

And this page: http://www.mjtnet.com/scripts.hts has a number of script examples with Macro Scheduler.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mirdurern
Newbie
Posts: 11
Joined: Mon Sep 27, 2004 5:46 pm

Does this look any better?

Post by Mirdurern » Tue Sep 28, 2004 5:42 pm

I now rewrote the macro and it appears to get the right file name but my ifFileExis still doesnt work. What happens is that it still give me both boxes. Maybe the problem is that I dont understand how Label> and Goto> works. Again thanks for all of the help.

Mike


VBSTART
Function GetName

GetName = InputBox("Enter Serial Number : ")

End Function
VBEND

VBEval>GetName,name

'Write Serial Number to text file
WriteLn>R:\CustomData\Temp\test.txt,%name%
WriteLn>R:\CustomData\Temp\test.txt,%name%-1

'Reads the Text file for the serial number
ReadLn>R:\CustomData\Temp\test.txt,1,SN
ReadLn>R:\CustomData\Temp\test.txt,2,SNA


Let>path=R:\CustomData\WeekTEST

ConCat>path,\%name%
Let>file=path

MessageModal>Your Serial Number was not found : %file%

IfFileExists>file,nofile

Label>MainLoop
MessageModal>Your file was found: %file%

Goto>end

Label>nofile

MessageModal>Your Serial Number was not found %file%

Goto>end

Label>end
Press Enter

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Sep 28, 2004 6:01 pm

Some other quick observations......
WriteLn>R:\CustomData\Temp\test.txt,%name%
WriteLn>R:\CustomData\Temp\test.txt,%name%-1
You are missing a parameter on both your WriteLn commands. Should be:
WriteLn>R:\CustomData\Temp\test.txt,result,%name%
WriteLn>R:\CustomData\Temp\test.txt,result,%name%-1
You are still trying to math in last parameter? %name%-1 ?
If YES, see my earlier posting. If NO, then ignore it, but %name%-1 looks like math.

Instead of using VB Script, how about using Input> ?
Input>name,Enter Serial Number :


You will always get "Your Serial Number was not found : %file%" because you have the MessageModal before all of the IF commands.

STRONG SUGGESTION:
Try single stepping through your macro with Debug, and Show Watch List to see what the variables are doing, step by step.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mirdurern
Newbie
Posts: 11
Joined: Mon Sep 27, 2004 5:46 pm

I suck at this

Post by Mirdurern » Wed Sep 29, 2004 4:31 am

Hello,

Thank you for all of your help. Maybe it would just be easier for me to tell you what I want to do and see how some of you write the code to do this process. Being that I feel for some reason I do not understand how to get these arguments to work. Here is what I would like to do.

Go out to a networking drive (assume it map to your local computer)
Enter a file name
Get a message this file exists and open it in MS Word
or
If the file doesn’t exist get a message and a wave file stating so.

Could you use If and Goto statements for some reason I am not getting them to work.

Again thank you for all of your help, I am very new to programming.

Mike

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Sep 29, 2004 7:28 am

Macro Scheduler can do what you have described.

You have already described the flow very well. Make a flow chart before writing the script.

You will learn more by doing this yourself. Do one section at a time. Check the Help examples.

Submit your code for help here. Use SingleStep and Watch List to troubleshoot. Remove all Trailing Spaces.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Mirdurern
Newbie
Posts: 11
Joined: Mon Sep 27, 2004 5:46 pm

Thanks you

Post by Mirdurern » Sat Oct 02, 2004 1:26 am

Here is what I came up with. Thank you all for the help !

VBSTART
Function GetName

GetName = InputBox("Enter Serial Number : ")

End Function
VBEND

VBEval>GetName,name

Label>Start
Let>Filename=C:\%name%.txt
MessageModal>%Filename%

IfFileExists>Filename,end
MessageModal>Your File Doesnt Exist %Filename%

Goto>Final

Label>end
MessageModal>Your File Exist: %Filename%

Label>Final

Thanks Again
Mike

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts