execute() not working

Discussion in 'ASP General' started by iulian.ilea@gmail.com, Oct 13, 2006.

  1. Guest

    Hello,

    I have this code:
    ________________________________________________________

    if VarType(eval("inTotal" & 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("inTotal" & 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?
     
    , Oct 13, 2006
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    > Hello,
    >
    > I have this code:
    > ________________________________________________________
    >
    > if VarType(eval("inTotal" & 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("inTotal" & 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.Dictionary 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) = "ListOfValues" & i
    arr_(1,i) = i
    arr_(2,i) = i * 2
    Next

    Set inTotal = CreateObject("Scripting.Dictionary")

    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 Jones, Oct 13, 2006
    #2
    1. Advertising

  3. Guest

    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:
    > <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have this code:
    > > ________________________________________________________
    > >
    > > if VarType(eval("inTotal" & 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("inTotal" & 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.Dictionary 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) = "ListOfValues" & i
    > arr_(1,i) = i
    > arr_(2,i) = i * 2
    > Next
    >
    > Set inTotal = CreateObject("Scripting.Dictionary")
    >
    > 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.
     
    , Oct 13, 2006
    #3
  4. <> wrote in message
    news:...
    > 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:
    > > <> wrote in message
    > > news:...
    > > > Hello,
    > > >
    > > > I have this code:
    > > > ________________________________________________________
    > > >
    > > > if VarType(eval("inTotal" & 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("inTotal" & 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.Dictionary 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) = "ListOfValues" & i
    > > arr_(1,i) = i
    > > arr_(2,i) = i * 2
    > > Next
    > >
    > > Set inTotal = CreateObject("Scripting.Dictionary")
    > >
    > > 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 Jones, Oct 13, 2006
    #4
  5. Guest

    Anthony Jones wrote:
    > <> wrote in message
    > news:...
    > > 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:
    > > > <> wrote in message
    > > > news:...
    > > > > Hello,
    > > > >
    > > > > I have this code:
    > > > > ________________________________________________________
    > > > >
    > > > > if VarType(eval("inTotal" & 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("inTotal" & 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.Dictionary 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) = "ListOfValues" & i
    > > > arr_(1,i) = i
    > > > arr_(2,i) = i * 2
    > > > Next
    > > >
    > > > Set inTotal = CreateObject("Scripting.Dictionary")
    > > >
    > > > 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...") ?
     
    , Oct 22, 2006
    #5
  6. Bob Barrows [MVP], Oct 22, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    665
    Ratman
    Sep 14, 2004
  2. Brian Miller
    Replies:
    6
    Views:
    2,941
    Brian Miller
    Nov 27, 2004
  3. Martin Heuckeroth
    Replies:
    5
    Views:
    684
    JiangZemin
    Apr 1, 2005
  4. nadz
    Replies:
    4
    Views:
    819
    Alf P. Steinbach
    Apr 20, 2006
  5. Savas Ates
    Replies:
    1
    Views:
    287
    Patrice
    Aug 17, 2004
Loading...

Share This Page