tags:

views:

30

answers:

1

I am trying to replace the double quotes in a string with a single quote, got the following code but get error message saying "Object Required strLocation"

Sub UpdateAdvancedDecisions(strLocation)
  Dim d
  Dim strLLength

  strLLength = Len(strLocation) - 1

  For d = 0 To strLLength
    alert strLocation

    strValue = strLocation.Substring(2,3)

    If strLocation.substring(d,d+1)=" " " Then   
      strLLength = strLLength.substring(0, d) + "'" + strLLength.substring(d + 1,strLLength.length)

  Next
End Sub
+1  A: 

As Helen said, you want to use Replace, but her example assigned the result to your weird strLLength variable. Try this instead:

strLocation = Replace(strLocation, """", "'")

This one line does the job you asked about and avoids all the code currently in your given subroutine.

Other things that are problems in the code you posted:

  • a variable holding a number like the length of a string would not have a "str" prefix, so strLLength is misleading

  • strings in VBScript are indexed from 1 through length, not 0 through length-1

  • there is no "alert" keyword in VBScript

  • you assign a value to strValue, then never use it again

  • you need to use Mid to get a substring, there is no "substring" string method in VBScript

    c = Mid(strLocation, d, 1) ' gets one character at position d
    

The more I look at this, the more clear it is that its some JavaScript that you're trying to run as VBScript but are not translating at all correctly.

Use a reference for VBScript like one of the following:

Todd