Testing for a Property?

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Testing for a Property?

Re: Testing for a Property?

by Bex » Wed Jan 07, 2009 1:06 pm

@ZvezdanD
It works well here. But since the property was introduced in 1208, that's the earliest VersionBuild you can check for.

Re: Testing for a Property?

by Owyn » Wed Jan 07, 2009 12:49 pm

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?

by Bex » Wed Jan 07, 2009 12:45 pm

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?

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

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?

by ZvezdanD » Wed Jan 07, 2009 12:39 pm

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?

by Owyn » Wed Jan 07, 2009 12:33 pm

Thanks. That should do the trick. Off to test it.

Re: Testing for a Property?

by Bex » Wed Jan 07, 2009 12:19 pm

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

Testing for a Property?

by Owyn » Wed Jan 07, 2009 12:15 pm

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?

Top