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%
IfFileExists problems or Operator Error
Moderators: Dorian (MJT support), JRL
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
I see a couple of problems, can point them out, but no time to test right now. My comments are in blue
General caution: also be sure to remove any Trailing Spaces from your script lines, especially when referring to labels, variables.'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%
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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!
Bob
A humble man and PROUD of it!
Does this look any better?
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Some other quick observations......
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> ?
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.
You are missing a parameter on both your WriteLn commands. Should be:WriteLn>R:\CustomData\Temp\test.txt,%name%
WriteLn>R:\CustomData\Temp\test.txt,%name%-1
You are still trying to math in last parameter? %name%-1 ?WriteLn>R:\CustomData\Temp\test.txt,result,%name%
WriteLn>R:\CustomData\Temp\test.txt,result,%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!
Bob
A humble man and PROUD of it!
I suck at this
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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!
Bob
A humble man and PROUD of it!
Thanks you
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
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