14 Replies - 2285 Views - Last Post: 22 February 2011 - 01:17 PM Rate Topic: -----

#1 MonkeyBoy2194  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 489
  • Joined: 09-February 09

"End with without with"

Posted 15 February 2011 - 07:49 AM

I keep getting an error message when I debug saying "End with without with"

With pobjLB
    
        Do While (True)
        
        For intI = 0 To frmChat.lstUsers.ListCount - 1
        For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1
        Do
            If frmChat.lstUsers.List(intJ) <> frmChat.lstUsers.List(intI) Then
                Exit Do
            Else
                MsgBox "Sorry but that displayname is already in use, please choose another"
            End If
    
        Loop
    Next
    Next
    
    [b]End With[/b]



But as you's can see I do have an "End With", is it to do with the positioning of it?

Help would be much appreciated :)

This post has been edited by MonkeyBoy2194: 15 February 2011 - 07:50 AM


Is This A Good Question/Topic? 0
  • +

Replies To: "End with without with"

#2 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: "End with without with"

Posted 15 February 2011 - 08:05 AM

the problem is not the end with. lets examen your code. what you do is start with "with" statement:
With pobjLB
End With



then you have a while
With pobjLB
Do While (True)

Loop
End With



then you have 2 for cycels

With pobjLB
Do While (True)
For intI = 0 To frmChat.lstUsers.ListCount - 1
For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1

Next intJ
Next intI
Loop
End With



then you have Do

With pobjLB
Do While (True)
For intI = 0 To frmChat.lstUsers.ListCount - 1
For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1
Do

Loop
Next intJ
Next intI
Loop
End With



now check how your code looks like compare to this one :)

This post has been edited by NoBrain: 15 February 2011 - 08:10 AM

Was This Post Helpful? 0
  • +
  • -

#3 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: "End with without with"

Posted 15 February 2011 - 08:08 AM

You are missing something, try this

With pobjLB
   Do While (True)
      For intI = 0 To frmChat.lstUsers.ListCount - 1
         For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1
            Do
               If frmChat.lstUsers.List(intJ) <> frmChat.lstUsers.List(intI) Then
                  Exit Do
               Else
                  MsgBox "Sorry but that displayname is already in use, please choose another"
               End If
            Loop
         Next
      Next
   Loop 'this is what was missing - EDIT: OR IS IT Wend (been quite a while with vb6)
End With



indenting your code properly will help you find the missing part...

;)

This post has been edited by motcom: 15 February 2011 - 08:10 AM

Was This Post Helpful? 1
  • +
  • -

#4 MonkeyBoy2194  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 489
  • Joined: 09-February 09

Re: "End with without with"

Posted 15 February 2011 - 08:11 AM

I don't have the "End with without With" problem, but now it's saying "Wend without while" :S I done it to the exact way you said as well. Also what it is "wend" exactly, that's the first time I've used that?
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: "End with without with"

Posted 15 February 2011 - 08:14 AM

To be honest i dont remember too :D
While-Wend, Do While - Loop i think.

EDIT: Do While- Loop :)

Its Do While - Loop sorry its not Wend my mistake

This post has been edited by NoBrain: 15 February 2011 - 08:13 AM

Was This Post Helpful? 0
  • +
  • -

#6 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: "End with without with"

Posted 15 February 2011 - 08:16 AM

It might be that your do loop is not correct either...

this is how you do a do loop

Dim i As Integer
Do
    i = i + 1
Loop While i < 100 

'notice the Loop WHILE ..somecondition..

'you just have

Do
   ....
   ....
Loop

'and no While at the end...



here is a link to loops

Loops VB6
Was This Post Helpful? 1
  • +
  • -

#7 MonkeyBoy2194  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 489
  • Joined: 09-February 09

Re: "End with without with"

Posted 15 February 2011 - 08:25 AM

Ahhh, scrap that post. I'll give the "loop while" a shot then.

Thanks very much guys :D

This post has been edited by MonkeyBoy2194: 15 February 2011 - 08:27 AM

Was This Post Helpful? 0
  • +
  • -

#8 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: "End with without with"

Posted 15 February 2011 - 04:25 PM

All right, here's the "straight skinny" on all this. Originally it was While [Condition] Wend. The Do [While/Until Condition] Loop [While/Until Condition] expanded the syntax to make the loop more flexible.

Condition is optional (MOTCOM take notice) because you can test for a condition inside the loop and preemptively exit (Exit While, Exit Do).

The reason that While and Until are both allowed is to avoid the use of the Not operator. While Not is the same as Until and vice versa.

The reason that you can put a condition at both the Do and the Loop is because you may wish to guarantee that your code will execute at least once. This is the effect of putting a condition on the end (Loop Until or Loop While), and you can't do it with the old While/Wend syntax.

HTH
Was This Post Helpful? 0
  • +
  • -

#9 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: "End with without with"

Posted 15 February 2011 - 04:58 PM

View PostMonkeyBoy2194, on 15 February 2011 - 02:49 PM, said:

I keep getting an error message when I debug saying "End with without with"

With pobjLB
    
        Do While (True)
        
        For intI = 0 To frmChat.lstUsers.ListCount - 1
        For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1
        Do
            If frmChat.lstUsers.List(intJ) <> frmChat.lstUsers.List(intI) Then
                Exit Do
            Else
                MsgBox "Sorry but that displayname is already in use, please choose another"
            End If
    
        Loop
    Next
    Next
    
    [b]End With[/b]



But as you's can see I do have an "End With", is it to do with the positioning of it?

Help would be much appreciated :)


As you point out, you really really do have a With AND and End With, so what the heck? The reason that you have this rather cryptic error is because you don't have an end to your outside loop (Do While (True)). Since that's so, it never looks as far as your With statement, as both your With and End With statements would have to be either inside or outside your Do Loop. So, it finds that error before it finds the "Do without Loop" error.
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: "End with without with"

Posted 15 February 2011 - 05:04 PM

To make it a little clearer, this will result in an "End with without With" error:
With something
     Do While something
          End With
     Loop
The point is that we are still legal until we encounter the End with statement. There had to be a With inside the do loop for there to be an end with in there.

So, any block must start and end in a single block context.
Was This Post Helpful? 0
  • +
  • -

#11 MonkeyBoy2194  Icon User is offline

  • D.I.C Regular

Reputation: 3
  • View blog
  • Posts: 489
  • Joined: 09-February 09

Re: "End with without with"

Posted 16 February 2011 - 08:04 AM

I've tried everything you's have said but it will either come up with the "End with without with" or go in to an infinite loop. Do you's think I need to a condition to the last loop?
Was This Post Helpful? 0
  • +
  • -

#12 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: "End with without with"

Posted 16 February 2011 - 09:32 AM

Well, you haven't posted your code as it stands, so I can't give you a definitive explanation. However, the answer to your question is a tentative "yes." If you just do this:
Do
     [something or other]
Loop
you will get an endless loop. (If you want to get dramatic, you can say Do While (True), Do While 1=1, or whatever, but just Do does the same thing.) So yes, if you set up an endless loop, you have to "manually" exit it by testing for a condition and exiting if met.

If, to take your code above, you put a Loop statement above your End With statement, you would stop getting errors and also get an endless loop. Presumably, that's what you've done (and undone, and done again, and scratched your head, wept, fasted, prayed, etc.--hey, we all been there). Presumably you're thinking that your Exit Do will exit to the outside of your outside loop, but it doesn't. It only exits the insidemost do loop that you're in. You'd have to do another one. Like this:
Do
   [stuff]
   Do
       [more stuff]
       Exit Do '#1
   Loop
   [exit do #1 exits to here]
   [even more stuff]
   Exit Do '#2
Loop
[exit do #2 exits to here]
[on our merry way]



By the way, I'm not sure why you are using your With statement, either. With is used to keep from having to resolve an object reference over and over again in a block of code. You're not referencing any methods or properties of pobjLB in your code block, so you could actually remove that and get the same behavior.

A typical use of the with block is when iterating a Recordset object. Check this out:
Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset
[code to set up and open cn]
Set rs = New ADODB.Recordset
With rs
    .CursorLocation = adUseClient
    .Open "select * from fairytales", cn
    If Not (.BOF And .EOF) then
        .MoveFirst
        Do
             cmbFairlyTales.AddNew !FairyTaleName '(or .Fields("FairyTaleName") or .Fields(1)--assuming FairyTaleName is second column in table)
        Loop Until .EOF
    End If
End With

Not only does this avoid repetition of the object name and make for more concise code, it's actually more efficient. Basically, "rs" represents a pointer to a memory location. To resolve that pointer to the actual memory location requires a certain amount of code overhead. If you use the with block, you only have to spend that overhead once for the with block, rather than once for each reference to the object. In this case, therefore, we have saved six resolutions of object references.

So, I recommend and use With blocks whenever possible, as best practice. However, back to this situation, I do NOT use them if I'm not using the object I'm referring to in the With block! What's the point of that? :)
Was This Post Helpful? 0
  • +
  • -

#13 I'm High.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-February 11

Re: "End with without with"

Posted 21 February 2011 - 10:26 PM

I was having similar problems thanks for helping me as well :) but could you also use the LOOP somehow with -0+0 to make it infinity?

This post has been edited by I'm High.: 21 February 2011 - 10:27 PM

Was This Post Helpful? 0
  • +
  • -

#14 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: "End with without with"

Posted 22 February 2011 - 09:02 AM

With pobjLB
   Do While (True)
      For intI = 0 To frmChat.lstUsers.ListCount - 1
         For intJ = frmChat.lstUsers.ListCount To (intI + 1) Step -1
            Do
               If frmChat.lstUsers.List(intJ) <> frmChat.lstUsers.List(intI) Then
                  Exit Do
               Else
                  MsgBox "Sorry but that displayname is already in use, please choose another"
               End If
            Loop
         Next
      Next
   Loop 'this is what was missing - EDIT: OR IS IT Wend (been quite a while with vb6)
End With


hi MonkeyBoy2194 i have some little questions to you
what is the purpose of the outer do loop and inner do loop(why do you put the inner do loop and the outer do loop)
   Do While (True)
      ........
   Loop


if you find that you can stop the infinite looping

This post has been edited by thava: 22 February 2011 - 09:05 AM

Was This Post Helpful? 0
  • +
  • -

#15 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: "End with without with"

Posted 22 February 2011 - 01:17 PM

View PostI said:

I was having similar problems thanks for helping me as well :) but could you also use the LOOP somehow with -0+0 to make it infinity?

Not sure I understand your question. But if you just write
Do
   [whatever]
Loop
you will have an infinite loop. All the rest isn't necessary.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1