This topic is locked

For Next in ASP Runner 5.2

2/24/2009 11:03:52 AM
ASPRunnerPro General questions
M
marcove author

Hi,
Why, using For Next . .. after exit cicle, it doesn't execute instruction below?
Do I need to put For Next in a Sub or Function?
Thank You

Sergey Kornilov admin 2/24/2009

Post your code here. It's hard to get what exactly is the question.

M
marcove author 2/26/2009

Hi here is the code applied in BeforeEdit Event
After "NEXT" no lines are executed.
***

dim kval(10)

dim testm

dim idfop

dim kct(32)

dim kctl

dim maxmese
kct(1)=dict("Data1")

kct(2)=dict("Data2")

kct(3)=dict("Data3")

kct(4)=dict("Data4")

kct(5)=dict("Data5")

kct(6)=dict("Data6")

kct(7)=dict("Data7")

kct(8)=dict("Data8")

kct(9)=dict("Data9")

kct(10)=dict("Data10")

kct(11)=dict("Data11")

kct(12)=dict("Data12")

kct(13)=dict("Data13")

kct(14)=dict("Data14")

kct(15)=dict("Data15")

kct(16)=dict("Data16")

kct(17)=dict("Data17")

kct(18)=dict("Data18")

kct(19)=dict("Data19")

kct(20)=dict("Data20")

kct(21)=dict("Data21")

kct(22)=dict("Data22")

kct(23)=dict("Data23")

kct(24)=dict("Data24")

kct(25)=dict("Data25")

kct(26)=dict("Data26")

kct(27)=dict("Data27")

kct(28)=dict("Data28")

kct(29)=dict("Data29")

kct(30)=dict("Data30")

kct(31)=dict("Data31")
BeforeEdit = True
for k=1 to 31

response.write(kct(k))

response.write(" ")

if (kct(k) > maxmese) then

kctl=1

BeforeEdit = False

exit for

end if

next
response.write(" ")

response.write(kctl)

response.write(" -- ")
strSQLInsert = "update PresenzeUnigest set edit=1 where ID=" & kval(1)

dbConnection.Execute strSQLInsert
strSQLExists = "select ID from Sost where IDS=" & kval(5)

set rsExists = CreateObject("ADODB.Recordset")

rsExists.Open strSQLExists, dbConnection

idfop=rsExists("ID")

rsExists.Close : set rsExists = Nothing
strSQLDelete = "delete from dbo.Pre where IDPre="& kval(1) &" and Mese='"& kval(3) &"' and Anno ="& kval(2) &" and IDPre="& kval(4) &" and IDOp="& idfop

'response.write(strSQLDelete)

dbConnection.Execute strSQLDelete

Sergey Kornilov admin 2/26/2009

You can post your application to Demo Account and open a ticket at http://support.xlinesoft.com

R
Roger 2/27/2009

Hi Marco, so new at asprunner, but as far as vbscript goes two things jump out at me:

  1. vbscrip arrays start with index[0] so your code will miss the first element,
  2. your code:

    for k=1 to 31

    [indent]response.write(kct(k))[/indent]

    [indent]response.write(" ")[/indent]

    [indent]if (kct(k) > maxmese) then -> here we don't know what MAXMESE is set to, see note below[/indent]

    [indent][indent]kctl=1[/indent][/indent]

    [indent][indent]BeforeEdit = False[/indent][/indent]

    [indent][indent]exit for[/indent][/indent]

    [indent]end if[/indent]

    next
    NOTE: in this case, maxmese is DIMmed VARIANT (by default) with no casting or value, so it is initialized to an empty STRING. Therefore, the first pass thru the loop will EXIT as the EXIT FOR statement indicates. IN other works (according to your array), the test by KCT(1) [first iteration] would be greater than ZERO (vbscript would attemtp to typecast an empty string/null string to satisfy the condition) and therefore exit.


    I created a test loop as above and dimmed vars accordingly and it seemed to work fine.
    Just a few thoughts, I hope this helps.

Sergey Kornilov admin 2/27/2009

Roger,
I think you are right. This code uses some of uninitialized variables so it's probably errors out at some point.