0

I'm getting the error "Loop without do". I can't figure out why since all my if statements are ended with end if.

Maybe you guys can help me to check where it's not closed (if it is not closed)

Here's my code

Do until Int(uitgevoerd)=Int(aantal_cat)
    Do until Not IsEmpty(request.form("categorie" & i)) 
        i=i+1
    loop
    Select Case True
        cbvcode = request.form("cbvcode" & i)

        ' Case Instr(cbvcode, "cbvcode") > 0
        if Instr(cbvcode, "cbvcode") > 0 then
            'objConProjecten.Execute(finanSQL)
            uitgevoerd=uitgevoerd+1 
            i=i+1   
        else
            bedragdeelnemer = request.form("bedragdeelnemer"& i)
            cat_id = request.form("categorie" & i)
            huidig_cat_id = request.form("huidig_cat_id_" & i)
            volgnummer = request.form("volgnummer" & i)
            'cbvcode = request.form("cbvcode" & i)

            'kijk of bedragdeelnemer leeg is. Zoniet doe een update of een insert.
            if bedragdeelnemer = "" then
                bedragdeelnemer = 0
            end if

            FOR c=1 to 5
                if Int(categorieen(c))=Int(cat_id) then
                    catgebruikt = TRUE 
                    categorieen(c)=null
                end if
            NEXT        
            response.write("<br>")
            response.write(i)
            response.write("<br>")
            if catgebruikt then
                finanSQL =  _
                    "UPDATE intakeformulieren_financien " & _
                    "SET bedragdeelnemer=" & replace(bedragdeelnemer, ",", ".") & _
                        ", volgnummer=" & volgnummer & _
                        ", cbvcode='" & cbvcode & _
                        "' WHERE formuliernr = " & formnummer & _
                        " AND cat_id = " & cat_id
                        response.write(finanSQL)
                        catgebruikt = FALSE
            else
                finanSQL =  _
                    "INSERT INTO " & _
                    "intakeformulieren_financien (formuliernr, bedragdeelnemer, cat_id, volgnummer, cbvcode) " & _
                    "VALUES ("& & _
                         formnummer & "," & _
                         replace(bedragdeelnemer, ",", ".") & "," & _
                         cat_id & "," & _
                         volgnummer & ",'" & _
                         cbvcode & "')"
                response.write(finanSQL)
            end if
            objConProjecten.Execute(finanSQL)
            uitgevoerd=uitgevoerd+1 
            i=i+1
        end if
Loop
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Benny Niemeijer
  • 349
  • 1
  • 3
  • 15
  • It doesn't help that your code isn't properly indented. – Paul Dec 11 '15 at 11:42
  • 2
    Your problem is that there's a `Select Case True` in there without an `End Select` or any `Case` statements within. Try removing that first, and please, *please* format your code properly. – Paul Dec 11 '15 at 11:52

2 Answers2

0

This is how I did it in the end. And it works :) Thanks!

Do until Int(uitgevoerd)=Int(aantal_cat)
    Do until Not IsEmpty(request.form("categorie" & i)) 
        i=i+1
    loop
    cbvcode = request.form("cbvcode" & i)
    Select Case True

    Case Instr(cbvcode, "-1") > 0
        'objConProjecten.Execute(finanSQL)
        uitgevoerd=uitgevoerd+1 
        i=i+1   
    Case else
       ...
       ...
    End Select
Loop
Benny Niemeijer
  • 349
  • 1
  • 3
  • 15
  • 2
    That is not how you use `Select Case`. Replace it with an `If..Then..Else`. – Ansgar Wiechers Dec 11 '15 at 12:37
  • Ansgar : you beat me up. This is one of the cases where Select case true is overkill. – gazzz0x2z Dec 11 '15 at 12:40
  • @AnsgarWiechers The thing about `Select Case` over `If` is it's easy to extend into a multiple outcome scenario. Yes I know you can use `ElseIf` but prefer not to. – user692942 Dec 11 '15 at 13:06
  • 1
    @Lankymart Each of the three control structures is intended for a different scenario. Just because you *can* abuse them to work in other scenarios doesn't mean you *should*. – Ansgar Wiechers Dec 11 '15 at 13:11
  • @AnsgarWiechers That is your opinion *(I wouldn't call it abuse though)*. It is a [contentious issue](http://stackoverflow.com/q/794036/692942) *(linked article is very interested with arguments for and against, not strictly VBScript but it still applies)* some prefer `Select Case True` while others prefer `ElseIf` personally I'm in the `Select Case True` camp. Unless there is some performance reason why using `Select Case True` is bad or a compelling argument not to use it then I'd reconsider. – user692942 Dec 11 '15 at 13:41
  • Ideally though I will use `Select Case ` rather then `Select Case True` when the situation warrants it. – user692942 Dec 11 '15 at 13:59
  • 2
    @Lankymart Let's agree to disagree. I don't think SO isn't the right place for an extended discussion of this matter. – Ansgar Wiechers Dec 12 '15 at 00:47
  • @Ansgar Wiechers thank you. I'm not following it anyway. – Benny Niemeijer Dec 12 '15 at 07:36
  • @Lankymart: The primary argument for `Select Case True` in the article you posted was readability. Even then, when I first saw the construct used like it was, I had to read over it a few times to make sure I'd got the gist of it. So even readability comes at a slight cost. Everyone knows what an `If...ElseIf...End If` statement is and why it's there. And it just feels plain wrong to do it like this, as if you're moving the comparison emphasis away from the actual `Select Case` line and into the `Case` statements (hence the loose abuse). – Paul Dec 14 '15 at 10:12
  • 1
    @BennyNiemeijer: Perhaps you have the wrong handle on what this site actually is. The whole point of SO is to discuss the best options for *other* readers, not just you. Please don't be so rude. – Paul Dec 14 '15 at 10:23
  • 1
    @Paul Seems to be more and more of them recently. – user692942 Dec 14 '15 at 10:24
-2

This is a problem :

    finanSQL =  "INSERT INTO intakeformulieren_financien (formuliernr, bedragdeelnemer, cat_id, volgnummer, cbvcode) " &_
                "VALUES ("& formnummer & "," & replace(bedragdeelnemer, ",", ".") & "," & cat_id & "," & volgnummer & ",'" & cbvcode & "')"

because you have "&_" instead of "& _". The underscore MUST be isolated. It probably breaks things in your code.

The other problem I see is your Select Case True. I love Select Case true, but you don't have anything behind that makes use of it. You don't have any end select, neither any Case that isn't commented out. Try deleting the whole line.

And try again, post your new code, and tell us if it still does not work. Ah, and please make a better indentation.

gazzz0x2z
  • 326
  • 2
  • 12
  • Select Case True is basically bad practice. – Paul Dec 11 '15 at 11:53
  • Thanks! You helpt me a lot. I'm not very into classic ASP jet, but I needed to adjust this piece of code for my internship. In the end I did make use of the _select case true_ I just didn't know much about _select case_ jet so my hole code was a mess.. See my answer to how I did it. – Benny Niemeijer Dec 11 '15 at 11:53
  • 1
    In reference to `Select Case True`, you simply need to be aware that, unlike C like languages, where you have a `break` to exit out of the associated `case`, you don't with VB Script. With VB Script the first occurrence of the given condition is accepted. So, if you have several complex `Case` statements all evaluating to true, make sure you get them a. in the right order, and b. in the right `Case` statement! – Paul Dec 11 '15 at 12:06
  • 1
    Select case True is a bad practice when misapplied(when a simple if or a simple Select Case could do the job, both solutions covering most cases). But when you have to follow a decision list, in a specific order, with exotic & non-homogenic data access, it's a readable way to follow the specs. Here, specifically, there is no need. – gazzz0x2z Dec 11 '15 at 12:41
  • @gazzz0x2z: I have to say that I agree with Ansgar Wiechers in his comments above - `Select Case` has its place and it shouldn't be abused. I have used `Select Case True` before and can appreciate its readability factor, however, I prefer `If...Then..ElseIf` structures. – Paul Dec 11 '15 at 15:32
  • @Paul The key here is choice but to say it's abuse I feel is a step too far. Like I said to Ansgar if there was some tangible argument for not using it I would consider it. – user692942 Dec 12 '15 at 03:10
  • Just a quick comment about the answer to. The first part is nonsense having `&_` works fine, personally I prefer a space but it is not a code breaker. – user692942 Dec 12 '15 at 03:14