3 Replies Latest reply on Feb 13, 2009 8:46 AM by (bogdan_cosmin)

    [VB] Like operator not functioning?

      I'm trying to create the following statement in my VB code, but I'm getting a "Sub or Function not defined" error. My question is, how do you use the Like operator with InDesign scripting? InDesign doesn't seem to recognize the Like operator.

      "myCurrentString" contains a letter.

      If myCurrentString Like "[A-z]" Then
      End If

      I'm also trying to do the following:

      If myCurrentDigit Like "[0-9]" Then
      End If
        • 1. Re: [VB] Like operator not functioning?
          'You can do this in VBScript...

          Dim re
          Set re = New RegExp
          With re
          .Pattern = "[A-Z]"
          .Global = True
          .IgnoreCase = False
          End With
          targetString = "A"
          msgbox re.Test(targetString)

          '8 lines more than you'd like.

          'Ben
          • 2. Re: [VB] Like operator not functioning?
            Level 1
            I couldn't find "RegExp" in the InDesign script model--could you give a bit more information about what this is? I don't know how to iterate through the contents of an XMLElement as individual character objects, so I'm iterating throught XML.contents, putting each character in a basic string variable. I need a way to put strings into a With statement, or a Like operator. I haven't had success with either technique.

            Here's an example:

            strTime = myCurrentXMLElement.contents
            strTime = Trim(strTime)
            strLength = Len(strTime)
            For counter = 1 to strLength
            strTemp = Mid(strTime, counter, 1)
            [This is where I need to find out if strTemp is a letter or a digit]

            Next
            • 3. Re: [VB] Like operator not functioning?
              Level 1
              RegExp is not part of the Indesign Script Model but a Visual Basic class that handles regular expressions, equivalent of System.Text.RegularExpressions.Regex(pattern, regex_options) in VB.Net.