Page 1 of 1

Testing for a Property?

Posted: Wed Jan 07, 2009 12:15 pm
by Owyn
Build 1208 provides a new property "SDB.VersionBuild".

This works just fine in 1208, but will raise an error if used in builds prior to 1208.

Is there a safe way to test if a property is available without raising an error?

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:19 pm
by Bex
Yes, that should be possible. I haven't done it yet but will do so soon.
Check out this article:
http://blogs.msdn.com/ericlippert/archi ... t-one.aspx

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:33 pm
by Owyn
Thanks. That should do the trick. Off to test it.

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:39 pm
by ZvezdanD
Well, nothing special. Just put On Error Resume Next before and On Error GoTo 0 after problematic statement. Of course, you could test if error occurs with If Err Then. Why don't you look some existing script like Magic Nodes or RegExp Find and Replace which use such error handling a lot?

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:42 pm
by Owyn

Code: Select all

  ' Get Version 
  Dim strMMVersion : strMMVersion = SDB.VersionString
  ON ERROR RESUME NEXT
  strMMVersion = strMMVersion & "." & SDB.VersionBuild
  ON ERROR GOTO 0
Worked on 1208. Will test it on 1190 shortly.

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:45 pm
by Bex
Yes, it was really simple. E.g. this works:

Code: Select all

  On Error Resume Next 'Suppress error messages
  If SDB.VersionBuild < 1208 Then
    Msgbox "Your using an old version of MediaMonkey!"
    'Do some more stuff
  End If
  On Error Goto 0 'Unsuppress error messages

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 12:49 pm
by Owyn
Yeah. I was just looking at the problem the wrong way.

i.e. How to test for function instead of how to gracefully survive the error.

Re: Testing for a Property?

Posted: Wed Jan 07, 2009 1:06 pm
by Bex
@ZvezdanD
It works well here. But since the property was introduced in 1208, that's the earliest VersionBuild you can check for.