execute() not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iulian.ilea@gmail.com

    execute() not working

    Hello,

    I have this code:
    _______________ _______________ _______________ ___________

    if VarType(eval("i nTotal" & arr(4,i1)))=0 then
    response.write "ok, dim"
    execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
    arr_(i1,i2))
    'it is working, I have variable
    else
    execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
    arr_(i1,i2))
    'here is not working any more.
    end if
    _______________ _______________ _______________ ___________

    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /test.asp, line 308

    What should be the problem?

  • Anthony Jones

    #2
    Re: execute() not working


    <iulian.ilea@gm ail.comwrote in message
    news:1160731752 .508386.129980@ k70g2000cwa.goo glegroups.com.. .
    Hello,
    >
    I have this code:
    _______________ _______________ _______________ ___________
    >
    if VarType(eval("i nTotal" & arr(4,i1)))=0 then
    response.write "ok, dim"
    execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
    arr_(i1,i2))
    'it is working, I have variable
    else
    execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
    arr_(i1,i2))
    'here is not working any more.
    end if
    _______________ _______________ _______________ ___________
    >
    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    /test.asp, line 308
    >
    What should be the problem?
    >
    The problem is your using Execute and Eval. Stop using them. Make inTotal
    into an array then you don't need them. If arr(4, i1) returns a string then
    use a Scripting.Dicti onary object to store a name/value pairs.

    Slap this in a VBS file and take a look at how it works:-

    Dim arr_(2,2)
    Dim temp
    Dim Key
    Dim i, j
    Dim inTotal

    For i = 0 to 2
    arr_(0,i) = "ListOfValu es" & i
    arr_(1,i) = i
    arr_(2,i) = i * 2
    Next

    Set inTotal = CreateObject("S cripting.Dictio nary")

    For i = LBound(arr_, 2) to UBound(arr_, 2)
    temp = 0
    For j = 1 To UBound(arr_, 1)
    temp = temp + arr_(j, i)
    Next
    inTotal(arr_(0, i)) = inTotal(arr_(0, i)) + temp
    Next

    For Each Key In inTotal
    MsgBox Key & " Total = " & inTotal(Key)
    Next

    Anthony.



    Comment

    • iulian.ilea@gmail.com

      #3
      Re: execute() not working

      I have to use those two (eval and execute), I have no other way to
      resolve this because I can have 20 variables or more, just one or none.
      So, obviously that I don't know what variables to define. I use option
      explicit so it is mandatory to define them.

      Another solution is to define an array with n elements (i.e.: arr(58))
      and use only some of them (i.e.: arr(1), arr(32)) but in this case I
      load in memory a full array. Is not a very good solution.

      By the way: I made it work in the way I wanted.

      Anthony Jones wrote:
      <iulian.ilea@gm ail.comwrote in message
      news:1160731752 .508386.129980@ k70g2000cwa.goo glegroups.com.. .
      Hello,

      I have this code:
      _______________ _______________ _______________ ___________

      if VarType(eval("i nTotal" & arr(4,i1)))=0 then
      response.write "ok, dim"
      execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
      arr_(i1,i2))
      'it is working, I have variable
      else
      execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
      arr_(i1,i2))
      'here is not working any more.
      end if
      _______________ _______________ _______________ ___________

      Error Type:
      Microsoft VBScript compilation (0x800A0401)
      Expected end of statement
      /test.asp, line 308

      What should be the problem?
      >
      The problem is your using Execute and Eval. Stop using them. Make inTotal
      into an array then you don't need them. If arr(4, i1) returns a string then
      use a Scripting.Dicti onary object to store a name/value pairs.
      >
      Slap this in a VBS file and take a look at how it works:-
      >
      Dim arr_(2,2)
      Dim temp
      Dim Key
      Dim i, j
      Dim inTotal
      >
      For i = 0 to 2
      arr_(0,i) = "ListOfValu es" & i
      arr_(1,i) = i
      arr_(2,i) = i * 2
      Next
      >
      Set inTotal = CreateObject("S cripting.Dictio nary")
      >
      For i = LBound(arr_, 2) to UBound(arr_, 2)
      temp = 0
      For j = 1 To UBound(arr_, 1)
      temp = temp + arr_(j, i)
      Next
      inTotal(arr_(0, i)) = inTotal(arr_(0, i)) + temp
      Next
      >
      For Each Key In inTotal
      MsgBox Key & " Total = " & inTotal(Key)
      Next
      >
      Anthony.

      Comment

      • Anthony Jones

        #4
        Re: execute() not working


        <iulian.ilea@gm ail.comwrote in message
        news:1160759384 .724751.134070@ e3g2000cwe.goog legroups.com...
        I have to use those two (eval and execute), I have no other way to
        resolve this because I can have 20 variables or more, just one or none.
        So, obviously that I don't know what variables to define. I use option
        explicit so it is mandatory to define them.
        >
        Another solution is to define an array with n elements (i.e.: arr(58))
        and use only some of them (i.e.: arr(1), arr(32)) but in this case I
        load in memory a full array. Is not a very good solution.
        >
        By the way: I made it work in the way I wanted.
        Each to his own. But arr(58) would've been better it equates to ;ess than
        1KB of memory and will significantly out perform Executes and Evals.

        >
        Anthony Jones wrote:
        <iulian.ilea@gm ail.comwrote in message
        news:1160731752 .508386.129980@ k70g2000cwa.goo glegroups.com.. .
        Hello,
        >
        I have this code:
        _______________ _______________ _______________ ___________
        >
        if VarType(eval("i nTotal" & arr(4,i1)))=0 then
        response.write "ok, dim"
        execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
        arr_(i1,i2))
        'it is working, I have variable
        else
        execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
        arr_(i1,i2))
        'here is not working any more.
        end if
        _______________ _______________ _______________ ___________
        >
        Error Type:
        Microsoft VBScript compilation (0x800A0401)
        Expected end of statement
        /test.asp, line 308
        >
        What should be the problem?
        >
        The problem is your using Execute and Eval. Stop using them. Make
        inTotal
        into an array then you don't need them. If arr(4, i1) returns a string
        then
        use a Scripting.Dicti onary object to store a name/value pairs.

        Slap this in a VBS file and take a look at how it works:-

        Dim arr_(2,2)
        Dim temp
        Dim Key
        Dim i, j
        Dim inTotal

        For i = 0 to 2
        arr_(0,i) = "ListOfValu es" & i
        arr_(1,i) = i
        arr_(2,i) = i * 2
        Next

        Set inTotal = CreateObject("S cripting.Dictio nary")

        For i = LBound(arr_, 2) to UBound(arr_, 2)
        temp = 0
        For j = 1 To UBound(arr_, 1)
        temp = temp + arr_(j, i)
        Next
        inTotal(arr_(0, i)) = inTotal(arr_(0, i)) + temp
        Next

        For Each Key In inTotal
        MsgBox Key & " Total = " & inTotal(Key)
        Next

        Anthony.
        >

        Comment

        • Jon Paal

          #5
          Re: execute() not working

          obviously we can't help as we don't know what line 308 is.....


          <iulian.ilea@gm ail.comwrote in message news:1160731752 .508386.129980@ k70g2000cwa.goo glegroups.com.. .
          Hello,
          >
          I have this code:
          _______________ _______________ _______________ ___________
          >
          if VarType(eval("i nTotal" & arr(4,i1)))=0 then
          response.write "ok, dim"
          execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
          arr_(i1,i2))
          'it is working, I have variable
          else
          execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
          arr_(i1,i2))
          'here is not working any more.
          end if
          _______________ _______________ _______________ ___________
          >
          Error Type:
          Microsoft VBScript compilation (0x800A0401)
          Expected end of statement
          /test.asp, line 308
          >
          What should be the problem?
          >

          Comment

          • iulian.ilea@gmail.com

            #6
            Re: execute() not working


            Anthony Jones wrote:
            <iulian.ilea@gm ail.comwrote in message
            news:1160759384 .724751.134070@ e3g2000cwe.goog legroups.com...
            I have to use those two (eval and execute), I have no other way to
            resolve this because I can have 20 variables or more, just one or none.
            So, obviously that I don't know what variables to define. I use option
            explicit so it is mandatory to define them.

            Another solution is to define an array with n elements (i.e.: arr(58))
            and use only some of them (i.e.: arr(1), arr(32)) but in this case I
            load in memory a full array. Is not a very good solution.

            By the way: I made it work in the way I wanted.
            >
            Each to his own. But arr(58) would've been better it equates to ;ess than
            1KB of memory and will significantly out perform Executes and Evals.
            >
            >

            Anthony Jones wrote:
            <iulian.ilea@gm ail.comwrote in message
            news:1160731752 .508386.129980@ k70g2000cwa.goo glegroups.com.. .
            Hello,

            I have this code:
            _______________ _______________ _______________ ___________

            if VarType(eval("i nTotal" & arr(4,i1)))=0 then
            response.write "ok, dim"
            execute("dim inTotal" & arr(4,i1) & ":inTotal" & arr(4,i1) & "=" &
            arr_(i1,i2))
            'it is working, I have variable
            else
            execute("inTota l" & arr(4,i1) & " = inTotal" & arr(4,i1) & " + " &
            arr_(i1,i2))
            'here is not working any more.
            end if
            _______________ _______________ _______________ ___________

            Error Type:
            Microsoft VBScript compilation (0x800A0401)
            Expected end of statement
            /test.asp, line 308

            What should be the problem?

            >
            The problem is your using Execute and Eval. Stop using them. Make
            inTotal
            into an array then you don't need them. If arr(4, i1) returns a string
            then
            use a Scripting.Dicti onary object to store a name/value pairs.
            >
            Slap this in a VBS file and take a look at how it works:-
            >
            Dim arr_(2,2)
            Dim temp
            Dim Key
            Dim i, j
            Dim inTotal
            >
            For i = 0 to 2
            arr_(0,i) = "ListOfValu es" & i
            arr_(1,i) = i
            arr_(2,i) = i * 2
            Next
            >
            Set inTotal = CreateObject("S cripting.Dictio nary")
            >
            For i = LBound(arr_, 2) to UBound(arr_, 2)
            temp = 0
            For j = 1 To UBound(arr_, 1)
            temp = temp + arr_(j, i)
            Next
            inTotal(arr_(0, i)) = inTotal(arr_(0, i)) + temp
            Next
            >
            For Each Key In inTotal
            MsgBox Key & " Total = " & inTotal(Key)
            Next
            >
            Anthony.
            Anthony, if I use arr(n) is more efficiently than using execute("dim
            var...") ?

            Comment

            • Bob Barrows [MVP]

              #7
              Re: execute() not working

              iulian.ilea@gma il.com wrote:
              Anthony, if I use arr(n) is more efficiently than using execute("dim
              var...") ?
              Absolutely. Execute should be avoided like the plague.




              --
              Microsoft MVP - ASP/ASP.NET
              Please reply to the newsgroup. This email account is my spam trap so I
              don't check it very often. If you must reply off-line, then remove the
              "NO SPAM"


              Comment

              Working...