Prev: Graphic Draw Question
Next: Redirection
From: MM on 3 Mar 2010 12:24 On Wed, 3 Mar 2010 17:02:09 +0100, "Henning" <computer_hero(a)coldmail.com> wrote: > >"MM" <kylix_is(a)yahoo.co.uk> skrev i meddelandet >news:h9iqo5pens21lrjljqfqpjgfi8at2p3ad2(a)4ax.com... >> Suppose I have: >> >> Sub AnyProc (cbo as ComboBox) >> MsgBox cbo.Name >> End Sub >> >> With Combo1 >> AnyProc ? >> End With >> >> How can I refer to the object itself to pass to AnyProc? What I need >> is a .Self property! >> >> MM > >Sorry, but I can't see why using With/End With to call AnyProc Combo1? >Setting parameters is nice inside the With/End with, but the call should IMO >be outside. With/End With has a certain functionality, we can't change that. >;) > >/Henning > I'm just looking at it with my purist's hat on. In the case of a form I can use Me in many cases. I think With/End With was an afterthought that the MS designers came up with later end with. It's not a major problem! MM
From: Karl E. Peterson on 3 Mar 2010 13:25 MM wrote: >> "ralph" <nt_consulting64(a)yahoo.net> wrote... >> >>> The With...End construct is provided only to simplify typing, >> >> All together now: "Oh no it's not!" >> >> The With/End With only makes a single call to the COM, without the With >> there would be a call for every item that is replaced by the use of With/End >> With. There are some other subtle effects but they are not really important. > > I've never actually noticed any improvement in performance, though, by > using With/End With. I just think it makes the code more readable and > looks neater. You won't see the improvement on today's hardware. But if you use your own object hierarchy, and single step through, you definitely will. -- ..NET: It's About Trust! http://vfred.mvps.org
From: ralph on 3 Mar 2010 13:49 On Wed, 3 Mar 2010 15:54:06 -0000, "Dave O." <nobody(a)nowhere.com> wrote: > >"ralph" <nt_consulting64(a)yahoo.net> wrote in message >news:btuso5pe1tgc404ekub232uh5qankce7qs(a)4ax.com... > >> The With...End construct is provided only to simplify typing, > >All together now: "Oh no it's not!" > >The With/End With only makes a single call to the COM, without the With >there would be a call for every item that is replaced by the use of With/End >With. There are some other subtle effects but they are not really important. > >Dave O. > That is a common myth. It seems reasonable enough, and like all myths did have a shade of truth in it once upon a time. It is based on the idea, as you noted, that the running program doesn't need to completely de-reference a statement each time, but rather can use a hidden temp which is then re-used with no need to re-reference. This was very handy for 'interpreted' languages as the 'compile-time' parser did little but tokenize the statements, and the 'run-time' parser did little but evaluate each statement as it went along, and had little clue of what might come next. For the simple case of ... With oJunk .AnyMethod1 .AnyMethod2 End With it did little except simpify the typing. One could argue (and some did) that it actually decreased runtime performance since you had to waste time creating the temp. Compare the following ... With oJunk Set <tmpoJunk> = oJunk <tmpoJunk>.AnyMethod1 <tmpoJunk>.AnyMethod2 End With V.S. oJunk.AnyMethod1 oJunk.AnyMethod2 But you mentioned COM and here is where the shade of truth comes in. Early VBs (let's say below VB4- but not THAT sure about VB4. It has been too long ago and I would rather not get into 16-bit or 32-bit VB4 - so I will ignore it <g>) could only use IDispatch. It was here that 'With...End With' did make a difference. With each statement VB would use its 'library' object reference to call the dispatch table, use a look-up to find the 'class' reference, and then the offset to find the method. It had no choice. With...EndWith sped that up by providing a ready-made reference. (But it still had to de-reference the offset.) [You can also see this in earlier VBAs where one was often advised to not use lengthy statements with multiple member-of operators ('.') but rather create nested references.] However, starting with VB4 (well definitely by VB5) the parser was no longer just a tokenizer, but a very active optimizer. When a file is read, or a line typed, into the VBEditor/Parser, that line is no longer simply tokenized but VB compares what it has just learned with previous information and builds or adds to its internal caches and tables. The initial pcode is called 'opcode', the VBEditor takes the opcode and all the caches and tables, and eventually converts it to 'excode', and one of the things that happens in excode is 'de-references' are often stashed away as temps (on the stack, a la Forth) and re-used. The process of converting pcode (excode) into native code (via the C compiler) provides additional optimization. [Which would lead us to 'aliasing' and its possible impact, if we really wanted to go there. But I think we don't. <g>] The end result, and the reason there is little noticeable difference between using With...End With or not - one often gets a *temp* whether one expressly asks for it or not. Therefore, from a practical standpoint in VB5/VB6 the construct is mostly a time-saving device, and in my opinion a code clearifier. -ralph
From: ralph on 3 Mar 2010 13:53 On Wed, 3 Mar 2010 17:02:09 +0100, "Henning" <computer_hero(a)coldmail.com> wrote: > >"MM" <kylix_is(a)yahoo.co.uk> skrev i meddelandet >news:h9iqo5pens21lrjljqfqpjgfi8at2p3ad2(a)4ax.com... >> Suppose I have: >> >> Sub AnyProc (cbo as ComboBox) >> MsgBox cbo.Name >> End Sub >> >> With Combo1 >> AnyProc ? >> End With >> >> How can I refer to the object itself to pass to AnyProc? What I need >> is a .Self property! >> >> MM > >Sorry, but I can't see why using With/End With to call AnyProc Combo1? >Setting parameters is nice inside the With/End with, but the call should IMO >be outside. With/End With has a certain functionality, we can't change that. >;) > >/Henning > Spoil sport. -ralph <g>
From: ralph on 3 Mar 2010 13:58
On Wed, 03 Mar 2010 10:25:25 -0800, Karl E. Peterson <karl(a)exmvps.org> wrote: >MM wrote: >>> "ralph" <nt_consulting64(a)yahoo.net> wrote... >>> >>>> The With...End construct is provided only to simplify typing, >>> >>> All together now: "Oh no it's not!" >>> >>> The With/End With only makes a single call to the COM, without the With >>> there would be a call for every item that is replaced by the use of With/End >>> With. There are some other subtle effects but they are not really important. >> >> I've never actually noticed any improvement in performance, though, by >> using With/End With. I just think it makes the code more readable and >> looks neater. > >You won't see the improvement on today's hardware. But if you use your >own object hierarchy, and single step through, you definitely will. And that's the key. "Single Step" where? In VB stepping through opcode? Using a debugger to step through running excode? Or using a debugger to step through running native code? The VB debugger often shows you exactly what you expect to see. -ralph |