Author Topic: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?  (Read 4351 times)

DavidOfMA

  • Sr. Member
  • **
  • Posts: 253
  • Writer/Photographer/Therapist
IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« on: July 02, 2014, 04:02:16 PM »
I'm trying to update an IMatch 3 script I use for file renaming to IMatch 5. It bombs on an attempt to use IMFileOperationResult. What's the IMatch 5 way of returning an error?

Here's the relevant subroutine:

'
' add the current error to the list of all errors - eventually, this will be displayed to the user
'
Sub addToFileList( Name As String, Err As IMFileOperationResult, msg As String)
   Debug.Print("err: " & Name )

   Dim errcat As Category
   Dim errMsg As String
   errMsg = ""

   If (Len(msg) > 0) Then
      errMsg = msg
   Else
      Select Case Err
      Case imforSuccess
         errMsg = "success"
      Case imforGeneralFailure
         errMsg = "unknown error"
      Case imforFileDoesNotExist
         errMsg = "file does not exist"
      Case imforFileIsReadOnly
         errMsg = "File is ReadOnly"
      Case imforFileOperationFailed
         errMsg = "Windows Error"
      Case imforDatabaseFailure
         errMsg = "Database Error"
      Case imforFileExists
         errMsg = "File exists"
      Case Else
         errMsg = "Unknown Error"
      End Select
   End If

Thanks.

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #1 on: July 02, 2014, 07:30:08 PM »
According the the help on the Database.RenameFile method, the method throws an exception when it fails. Just use exception handling with On Error Goto etc. in your script to handle this.

DavidOfMA

  • Sr. Member
  • **
  • Posts: 253
  • Writer/Photographer/Therapist
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #2 on: July 03, 2014, 03:46:57 AM »
Sorry, I work mainly by modifying existing code. I'm no programmer. I take it there's no "ImFileOperationResult" equivalent in IMatch 5, and I'd have to redesign the logic of the scipt?

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #3 on: July 03, 2014, 07:29:12 AM »
IMatch 5 uses different concepts for several feature areas. This is one. Instead of a return code, the method throws an exception in case of an error. Use the standard scripting OnError Goto logic (see the scripting help available in the script editor) for details on how to use On Error, Err.Msg, Err.Code etc.

JohnZeman

  • Global Moderator
  • *****
  • Posts: 1451
  • I'm too damn old to act my age.
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #4 on: July 03, 2014, 03:40:39 PM »
FWIW Below is a sample from one of my scripts.

Code: [Select]
Sub Main
On Error GoTo ERROR_HANDLER

(your script continues here)

ScriptShutDown:
Set Q_Folder = Nothing
Set DNG_Folder = Nothing
Exit All

ERROR_HANDLER:
Debug.Print "  Err="; Err & " Description: " & Err.Description & " what happened? " & Err.Source
Err.Clear
Resume Next
End Sub

DavidOfMA

  • Sr. Member
  • **
  • Posts: 253
  • Writer/Photographer/Therapist
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #5 on: July 04, 2014, 05:55:37 AM »
Can't find it in the Help searching for "Error," "On Error" and other topics. What is the actual Help topic in the Index for error handling in IMatch 5?

DavidOfMA

  • Sr. Member
  • **
  • Posts: 253
  • Writer/Photographer/Therapist
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #6 on: July 04, 2014, 06:11:22 AM »
Never mind. I see that rewriting this script will require me to learn what is basically a whole new scripting language, and that's beyond my skill level.

Yakwin

  • New Members
  • *
  • Posts: 11
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #7 on: July 04, 2014, 08:17:28 AM »
It took me hours to get my most used script to work with IMatch 5 and there is a lot of potential to make it even better. I don't know if I have time to convert my other scripts too  :(

Mario

  • IMatch Developer
  • Administrator
  • *****
  • Posts: 29760
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #8 on: July 04, 2014, 08:39:13 AM »
Never mind. I see that rewriting this script will require me to learn what is basically a whole new scripting language, and that's beyond my skill level.
The scripting language in IMatch 5 is just a newer version of the scripting engine used for IMatch 3. It is the same scripting engine as used for IMatch 3.6.0.118.
The On Error Goto logic is a core concept of the Basic programming language. If you need help about Basic programming, the built-in Basic methods etc. , please open the Basic help file from within the Scripting Editor. It explains all concepts available in the scripting language.

The IMatch 5 object model differs in some areas from the IMatch 3 object model. After keeping the object model stable for almost 10 years I used the switch from IMatch 3 to IMatch 5 to modernize it, and get rid of ballast and outdated things. It's not hard to migrate scripts, usually only a bit reading the help, try a few things out and do a copy/replace if the script you are using is affected by changes in the object model. The Basic language is the same as before - except that we now can also use the modern .NET variant to access all the functionality available in Windows itself.

sinus

  • Global Moderator
  • *****
  • Posts: 4464
  • IMatch-User since 2001 (IMatch 3.6)
Re: IMatch 5 replacement for IMatch 3 "IMFileOperationResult"?
« Reply #9 on: July 04, 2014, 09:41:28 AM »
It took me hours to get my most used script to work with IMatch 5 and there is a lot of potential to make it even better. I don't know if I have time to convert my other scripts too  :(

My experience with converting scripts from IM3 to IM5:

If they are not very complex, I can handle to convert such a script.
If a script is VERY complex, I was not able to convert it. But here is to say, complex means also "not very good".

So I wrote a script completely new in IM5 and because I had the old one, I could work with snippets from there and for some problems users helped me here and finally I had a completely new script - and even much! better than the old one.

And surprisingely it took not that long.
And what is true also: some scripts are not more necessary in IM5, simply because it is integrated natively, like the renamer or the relations.
Best wishes from Switzerland! :-)
Markus