473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Yield Keyword in VB.NET 2.0

What the heck - I can't find it. A bit shocked to see it missing though.

So "Does VB.NET have the yield keyword, or any equivalent of it" ?
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------
Nov 17 '05 #1
54 2654
Sahil,

Please to give better posibilities to research and therefore a better
product, use this newsgroups for Net 2.0 and related products.

Lab
http://lab.msdn.microsoft.com/vs2005/community/

I hope this helps,

Cor
Nov 17 '05 #2
Cor,

I checked that place - no help there.

I must say, I am incredibly frustrated and very annoyed that something as
important as the "yield" keyword would be missed out of VB.NET.

Now try writing a SQLCLR TVF and the 3 lines it takes to accomplish it in C#
translate to 3 pages of buggy VB.NET code. Highly Highly Highly Highly
stupid to miss that out IMO.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Ow**************@TK2MSFTNGP09.phx.gbl...
Sahil,

Please to give better posibilities to research and therefore a better
product, use this newsgroups for Net 2.0 and related products.

Lab
http://lab.msdn.microsoft.com/vs2005/community/

I hope this helps,

Cor

Nov 17 '05 #3
Sahil,

I think that this reaches where you are looking for. This old Visual Basic
keyword is probably one of the reasons why what is in C language called
Static is called in VBNet Shared.

http://msdn.microsoft.com/library/de...ialization.asp

I hope this helps,

Cor
Nov 17 '05 #4
Cor,

I'm not talking about "Static/Shared" .. I am talking about "Yield".
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uf**************@tk2msftngp13.phx.gbl...
Sahil,

I think that this reaches where you are looking for. This old Visual Basic
keyword is probably one of the reasons why what is in C language called
Static is called in VBNet Shared.

http://msdn.microsoft.com/library/de...ialization.asp

I hope this helps,

Cor

Nov 17 '05 #5
>So "Does VB.NET have the yield keyword, or any equivalent of it" ?

No. Different languages have different features.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 17 '05 #6
Thanks Mattias. Finally a direct answer to a simple question.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uY*************@TK2MSFTNGP09.phx.gbl...
So "Does VB.NET have the yield keyword, or any equivalent of it" ?


No. Different languages have different features.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 17 '05 #7
Sahil,
I'm not talking about "Static/Shared" .. I am talking about "Yield".

I assume that you do not know what Static is in VBNet, therefore I gave you
the link to the page.

If you want a mercedes with a chevrolet logo, than you have to put that logo
on it yourself, Mercedes does not do that for you.

However I find the Mercedes logo is not bad at all

static d as integer
For each a in b
d += 1
Next

This gives you at the end of your program the total result of loops or if
you set it conditional to zero let you go on where you was in the loop.

I am not busy with 2005, however short reading gave me the idea that this
was the idea.

I hope this helps,

Cor

Nov 17 '05 #8
Cor Ligthert wrote:
Sahil,
I'm not talking about "Static/Shared" .. I am talking about "Yield".

I assume that you do not know what Static is in VBNet, therefore I
gave you the link to the page.

If you want a mercedes with a chevrolet logo, than you have to put
that logo on it yourself, Mercedes does not do that for you.

However I find the Mercedes logo is not bad at all

static d as integer
For each a in b
d += 1
Next

This gives you at the end of your program the total result of loops
or if you set it conditional to zero let you go on where you was in
the loop.

I am not busy with 2005, however short reading gave me the idea that
this was the idea.


yield is a keyword which is only valid in custom enumerator routines
('iterators'), something which is C# 2.0 only if I'm not mistaken. It's
therefore logical VB.NET doesn't have a yield equivalent, as it doesn't
support custom iterator creation (though it's my understanding it does
support consuming them). At least, that's my understanding, but I might
have overlooked something.

Therefore, babbling about static/shared is erm... completely
irrelevant ;)

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #9
Sahil Malik [MVP] wrote:
What the heck - I can't find it. A bit shocked to see it missing
though.

So "Does VB.NET have the yield keyword, or any equivalent of it" ?


yield is a keyword for custom iterators, which IMHO is something
which is C# only.

However, it's not hard to work around it. After all, we all write code
today which works OK right? :)

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #10
Frans,

Therefore, babbling about static/shared is erm... completely
irrelevant ;)

Do you know what the static keyword means in VBNet? (This message is
crossposted sent to the language.vb newsgroup).

It has nothing (slightly because it is Static) to do with shared, as I told
in my first reply. What I only told to keep out confusing from C biased
persons. However ......................:-(

I have as well not said it is the same,

Although this text on MSDN gives me the idea that it is a static object.

Using the new yield keyword, your program can return values back to the
foreach statement that called the iterator. The next time the foreach
statement loops and calls the iterator again, the iterator begins its
execution where the previous yield statement left off

Cor
Nov 17 '05 #11
Frans,

Maybe I show it with a sample what my idea was that yield does and why there
is no need for it in VBNet because there is the static keyword.

\\\
Private Sub Whatever
Dim myarray() As String = {"1", "2", "3", "4"}
myproc(myarray, "First")
myproc(myarray, "Second")
End Sub
Private Sub myproc(ByVal myarray() As String, _
ByVal fase As String)
Static i As Integer
For i = i To myarray.Length
Dim y As Integer
If y = 2 Then Exit For
y += 1
Console.Write(i.ToString & " " & fase & vbCrLf)
Next
End Sub
///

Cor
Nov 17 '05 #12
You will always see simple errors in quick made code.

It thought it did work however that is strange, it has to be
\\\
Private Sub Whatever
Dim myarray() As String = {"1", "2", "3", "4"}
myproc(myarray, "First")
myproc(myarray, "Second")
End Sub
Private Sub myproc(ByVal myarray() As String, _
ByVal fase As String)
Static i As Integer
Dim y As Integer
For i = i To myarray.Length
If y = 2 Then Exit For
y += 1
Console.Write(i.ToString & " " & fase & vbCrLf)
Next
End Sub
///
Nov 17 '05 #13
As Frans mentions, Custom iterators are not supported in VB.NET. So it does
not have/need an yield equivalent.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"Sahil Malik [MVP]" wrote:
What the heck - I can't find it. A bit shocked to see it missing though.

So "Does VB.NET have the yield keyword, or any equivalent of it" ?
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

Nov 17 '05 #14
"Cor Ligthert" <no************@planet.nl> schrieb:
Maybe I show it with a sample what my idea was that yield does and why
there is no need for it in VBNet because there is the static keyword.

\\\
Private Sub Whatever
Dim myarray() As String = {"1", "2", "3", "4"}
myproc(myarray, "First")
myproc(myarray, "Second")
End Sub
Private Sub myproc(ByVal myarray() As String, _
ByVal fase As String)
Static i As Integer
For i = i To myarray.Length
Dim y As Integer
If y = 2 Then Exit For
y += 1
Console.Write(i.ToString & " " & fase & vbCrLf)
Next
End Sub
///


This samples doesn't show how to workaround the missing 'yield' keyword in
VB. The sample below is taken from the Beta documentation of Whidbey (C#):

\\\
public class List
{
public static IEnumerable Power(int number, int exponent)
{
int counter = 0;
int result = 1;
while(counter++ < exponent)
{
result = result * number;
yield return result;
}
}

static void Main()
{
// Display powers of 2 up to the exponent 8:
foreach(int i in Power(2, 8))
Console.Write("{0} ", i);
}
}
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #15
Herfried,

I have used this from MSDN.

In the following example, the foreach loop that calls this iterator will
execute three times, each time receiving the strings in the order specified
by the previous three yield statements:
List list = new List();
foreach(string s in list)
{
Console.WriteLine(s);
}
If you want the program to implement the iterator to traverse the elements
in the list, you would modify the iterator to step across the array of
elements using a foreach loop, yielding each item in the array in every
iteration:

public class List
{
internal object[] elements;
internal int count;

public object foreach()
{
foreach(object o in elements)
{
yield o;
}
}
}
However it is not worth the discussion.

It was more that some people where suggesting that static in VBNet is the
same as in C#.

It seems for me that they don't know this VBNet 2003 keyword that has no
equivalent in C# and it seems still in not.

Cor

Nov 17 '05 #16
Cor Ligthert wrote:
Frans,

Therefore, babbling about static/shared is erm... completely
irrelevant ;)
Do you know what the static keyword means in VBNet? (This message is
crossposted sent to the language.vb newsgroup).


Is this a popquiz? No I don't know what 'Static' means in VB.NET, I
don't use VB.NET. But I've looked it up, and it seems similar to
'static' in C if you define a static var in a C-routine. I also fail to
see what the particular relevance of 'Static vars' are in a method, as
they can lead to very unpredictable code, and IF you need to preserve
per-method call values for local vars, I can only think of 1 situation:
recursion. Now, you can better use the stack for that, don't you think?
:)
It has nothing (slightly because it is Static) to do with shared, as
I told in my first reply. What I only told to keep out confusing from
C biased persons. However ......................:-(
Great, but what's the relevance to yield ?
I have as well not said it is the same,

Although this text on MSDN gives me the idea that it is a static
object.

Using the new yield keyword, your program can return values back to
the foreach statement that called the iterator. The next time the
foreach statement loops and calls the iterator again, the iterator
begins its execution where the previous yield statement left off


No, it would be a method using object-level static values, and thus
use 'shared' elements, not 'static' elements.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #17
Cor Ligthert wrote:
You will always see simple errors in quick made code.

It thought it did work however that is strange, it has to be
\\\
Private Sub Whatever
Dim myarray() As String = {"1", "2", "3", "4"}
myproc(myarray, "First")
myproc(myarray, "Second")
End Sub
Private Sub myproc(ByVal myarray() As String, _
ByVal fase As String)
Static i As Integer
Dim y As Integer
For i = i To myarray.Length
If y = 2 Then Exit For
y += 1
Console.Write(i.ToString & " " & fase & vbCrLf)
Next
End Sub
///


What are you trying to do in this routine? The second call to myproc i
will be myarray.Length so the loop fails. The static keyword keeps the
value of 'i'. Though take a step back and look at the code you wrote.
No-one will use this kind of code in production software, because there
are far better ways to accomplish the same thing, which ARE more
readable as you can determine what a variable's contents is when the
routine is started (i.e. deterministic code, vs. your non-deterministic
code).

You could mimic an iterator using a wrapper class, and which calls a
delegate on each iteration (to make it generic). Though to set this up
is not transparent, i.e.: it requires work, something which is
transparent for the user of a .NET 2.0 iterator: just iterate over the
structure, whatever the structure represents.

Iterators are just to make foreach loops possible. So you can for
example foreach over a linked list, now that's a bit problematic, (not
undoable). Though there is always a way to do it differently, for
example by using the structures characteristics, in my example of the
linked list, you could use a While Not node.Next Is Nothing (C#:
while(node.Next!=null) {} ). That won't change in .NET 2.0. With
iterators, you just can create another way to iterate over a structure,
one which is usable in foreach. So if you step away from 'I want to use
foreach' and look at the code and just implement what gets the job
done, you will see iterators aren't a requirement, but a convenience
(and a convenience to the user if I'd might add ;))

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #18
Frans,

Have a nice day, maybe it is better that you walk to the end of the 'pier'
take a deep breath and ask yourself: "Is this the tone I have to write in a
newsgroup".

Cor
Nov 17 '05 #19
> What are you trying to do in this routine? The second call to myproc i
will be myarray.Length so the loop fails.
It runs, you did obvious not try it, it gives as result
0 first
1 first
2 second
3 second
Though take a step back and look at the code you wrote.
No-one will use this kind of code in production software, because there
are far better ways to accomplish the same thing,


Did I say that, I don't like the static keyword. It is to much hidden. That
is one of the things that Jon Skeet and I very much agree about.

By the way, based on the view things that I now have read about the 'yield',
have I on first sights the idea about that last as well.

For the rest of your message I don't see the sense therefore I keep it with
this.

Cor
Nov 17 '05 #20
"Cor Ligthert" <no************@planet.nl> schrieb:
What are you trying to do in this routine? The second call to myproc i
will be myarray.Length so the loop fails.


It runs, you did obvious not try it, it gives as result
0 first
1 first
2 second
3 second


Yeah, but it has nothing to do with iterators ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 17 '05 #21
Cor Ligthert wrote:
Frans,

Have a nice day, maybe it is better that you walk to the end of the
'pier' take a deep breath and ask yourself: "Is this the tone I have
to write in a newsgroup".


err, what's the problem? I just pointed out that what you tried to
explain is something completely different than yield.

Besides that, it's way too hot on the beach now.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #22
Cor Ligthert wrote:
What are you trying to do in this routine? The second call to
myproc i will be myarray.Length so the loop fails.


It runs, you did obvious not try it, it gives as result
0 first
1 first
2 second
3 second


oh due to the if y=2 then break blah. OK, overlooked that one, in my
blindness caused by the Static keyword. I didn't try the code.

I fail to see what it has to illustrate though.
Though take a step back and look at the code you wrote.
No-one will use this kind of code in production software, because
there are far better ways to accomplish the same thing,


Did I say that, I don't like the static keyword. It is to much
hidden. That is one of the things that Jon Skeet and I very much
agree about.


I just wanted to explain that code like you wrote is hard to read,
thus not what you want. This was mainly caused by the static keyword.
I.o.w.: static is IMHO a keyword you should better avoid (like goto),
and thus IF iterators would be programmable using static, like you
suggested, it wouldn't be a big win, on the contrary, you'd better opt
for a different approach.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #23
Herfried,

I only tried to give Sahil an alternative for his 'yield'.

The static is the one that comes in my idea the most near at it.

And than I got reply that was in my opinion about a shared class and his
members.

I am quiet sure that the yield is not exactly the same as a VB static,
otherwise I had given an example with a foreach.

Although in my idea is it not imposible that it will act internal not much
less than a VB static variable. You cannot keep values in memory and in the
same time let them go out of scope.

However that I cannot oversee, and was as well not the meaning of my answer.

Cor
Nov 17 '05 #24
Cor,

What the hell are you talking about? Anyway, I got my answer from Mattias.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:eU**************@TK2MSFTNGP10.phx.gbl...
Sahil,
I'm not talking about "Static/Shared" .. I am talking about "Yield".

I assume that you do not know what Static is in VBNet, therefore I gave
you the link to the page.

If you want a mercedes with a chevrolet logo, than you have to put that
logo on it yourself, Mercedes does not do that for you.

However I find the Mercedes logo is not bad at all

static d as integer
For each a in b
d += 1
Next

This gives you at the end of your program the total result of loops or if
you set it conditional to zero let you go on where you was in the loop.

I am not busy with 2005, however short reading gave me the idea that this
was the idea.

I hope this helps,

Cor

Nov 17 '05 #25
Cor,

Frans is completely right in this regard. I asked you about yield, you are
telling me about static/shared - seriously are you just trying to get your
post count up?

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ep****************@TK2MSFTNGP14.phx.gbl...
Frans,

Have a nice day, maybe it is better that you walk to the end of the 'pier'
take a deep breath and ask yourself: "Is this the tone I have to write in
a newsgroup".

Cor

Nov 17 '05 #26
> Yeah, but it has nothing to do with iterators ;-).

E-X-A-C-T-L-Y MY POINT :-)

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eb****************@TK2MSFTNGP14.phx.gbl...
"Cor Ligthert" <no************@planet.nl> schrieb:
What are you trying to do in this routine? The second call to myproc i
will be myarray.Length so the loop fails.


It runs, you did obvious not try it, it gives as result
0 first
1 first
2 second
3 second


Yeah, but it has nothing to do with iterators ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #27
Well I did write up an enumerator class myself. It's not a super big deal,
but just annoying that something I could have done in 3 lines of code in VB
requires me to implement another class. Anyway, that is something what is
done behind the scenes by yield anyway - and I beleive it is threadsafe
code, so yield isn't too shabby IMO.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
Sahil Malik [MVP] wrote:
What the heck - I can't find it. A bit shocked to see it missing
though.

So "Does VB.NET have the yield keyword, or any equivalent of it" ?


yield is a keyword for custom iterators, which IMHO is something
which is C# only.

However, it's not hard to work around it. After all, we all write code
today which works OK right? :)

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------

Nov 17 '05 #28
Sahil,
Frans is completely right in this regard. I asked you about yield, you are
telling me about static/shared -


Maybe it is wise that you buy this book before you go on in that one that
you are endless telling in these newsgroup that you are writting now.

http://www.nbcindia.com/Descriptions.asp?title_id=2545

I hope this helps,

Cor
Nov 17 '05 #29
> or any equivalent of it" ?

"Sahil Malik [MVP]" <co*****************@nospam.com> schreef in bericht
news:ur**************@tk2msftngp13.phx.gbl...
Yeah, but it has nothing to do with iterators ;-).


E-X-A-C-T-L-Y MY POINT :-)

Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
What the heck - I can't find it. A bit shocked to see it missing though.

or any equivalent of it" ?
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

Nov 17 '05 #30
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
I only tried to give Sahil an alternative for his 'yield'.
As I say, your sample is /not/ an alternative.
The static is the one that comes in my idea the most near at it.
It doesn't. Take a look at the C# sample I posted in the other reply.
And than I got reply that was in my opinion about a shared class and his
members.

I am quiet sure that the yield is not exactly the same as a VB static,
otherwise I had given an example with a foreach.

Although in my idea is it not imposible that it will act internal not much
less than a VB static variable. You cannot keep values in memory and in
the same time let them go out of scope.


Static variables in VB.NET won't help much. The trick behind the 'yield' is
that it returns the value to the iterator but doesn't exit the method. This
behavior can be faked using delegates, as mentioned in another reply.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #31
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> schrieb:
I just wanted to explain that code like you wrote is hard to read,
thus not what you want. This was mainly caused by the static keyword.
I.o.w.: static is IMHO a keyword you should better avoid (like goto),


I disagree. There are certain cases where 'Static' makes perfect sense and
additionally leads to better-encapsulated code than using a private (shared)
field. Note that this should not encourage the use of 'Static' where it
doesn't make much sense ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #32
"Cor Ligthert" <no************@planet.nl> schrieb:
Frans is completely right in this regard. I asked you about yield, you
are telling me about static/shared -


Maybe it is wise that you buy this book before you go on in that one that
you are endless telling in these newsgroup that you are writting now.

http://www.nbcindia.com/Descriptions.asp?title_id=2545


Cor, try to keep it outside the groups.

"A real man can admit when he makes a mistake."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #33
Maybe a feeble attempt at humor will ligthen things up. My buddy Roland
once gave me this expression and I loved it becuase, well, it's practically
my personal motto "
Doe maar gewoon, dan doe je al gek genoeg"

http://rolandboon.net/WSBeanRSS/Webl...y=2004-12-30/1

This is probably a good time for us all to listen to good old Roland ;-)

Also , remind me to tell you about our discussion after the user's group
about business objects.
--
W.G. Ryan, MVP
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Sahil Malik [MVP]" <co*****************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
What the heck - I can't find it. A bit shocked to see it missing though.

So "Does VB.NET have the yield keyword, or any equivalent of it" ?
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

Nov 17 '05 #34
Herfried,

As I said, I have to little information about the yield. I gave my answer as
a maybe equivalent of it.

Where I wrote "I think that this reaches where you are looking for".

The answer on this message was
\\\
I'm not talking about "Static/Shared" .. I am talking about "Yield".
///

This answer could have been as well in a decent way, however it gave me the
idea that the OP did/does (still) not know what static means VB as special
keyword inside a procedure. Therefore I tried to explain it by samples.

You always learns in these newsgroup.

:-))

Cor

Nov 17 '05 #35
Herfried,

Cor, try to keep it outside the groups.
As you know I try forever, however sometimes I get angry when the mud is to
much.
However you are right in this one.

If you look at the last replies from Frans than you see what I tried to
tell.
(The one you have replied now that you disagreed. And do that than because
of that as well with me).
"A real man can admit when he makes a mistake."

I am not mistaking in this. In my opinion have I nowhere written what you
probably think that you read from the answers from others.

See my other message to your thread written before I could read this one.

Cor

Nov 17 '05 #36
Bill,
Doe maar gewoon, dan doe je al gek genoeg"

I have the idea, if Frans tell that I am not than I will agree.

Dit slaat als een tang op een varken.

:-)))

Cor
Nov 17 '05 #37
Herfried K. Wagner [MVP] wrote:
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> schrieb:
I just wanted to explain that code like you wrote is hard to read,
thus not what you want. This was mainly caused by the static
keyword. I.o.w.: static is IMHO a keyword you should better avoid
(like goto),


I disagree. There are certain cases where 'Static' makes perfect
sense and additionally leads to better-encapsulated code than using a
private (shared) field. Note that this should not encourage the use
of 'Static' where it doesn't make much sense ;-).


Now I'm interested in what these situations are. Could you give an
explanation where it will give much BETTER code than when you wouldn't
have the Static keyword?

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #38
I actually got that phrase from Rolan Boon. I have a LONG way to go
learning Dutch before I make it over there at the end of the year.

Mijn Nederlands is slecht, maar ik denk ik begrijp
What I was hoping to say is that My dutch isn't all that good, but I think I
understood your point.
--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Bill,
Doe maar gewoon, dan doe je al gek genoeg"

I have the idea, if Frans tell that I am not than I will agree.

Dit slaat als een tang op een varken.

:-)))

Cor

Nov 17 '05 #39
Cor Ligthert wrote:
Bill,
Doe maar gewoon, dan doe je al gek genoeg"
I have the idea, if Frans tell that I am not than I will agree.


wat is dit voor steenkolen-engels, man :)
Dit slaat als een tang op een varken.


indeed :)

FB
Nov 17 '05 #40
> "A real man can admit when he makes a mistake."

Cor should "yield" when he is being "static" ? LOL

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------
---------------


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uf*************@TK2MSFTNGP12.phx.gbl...
"Cor Ligthert" <no************@planet.nl> schrieb:
Frans is completely right in this regard. I asked you about yield, you
are telling me about static/shared -


Maybe it is wise that you buy this book before you go on in that one that you are endless telling in these newsgroup that you are writting now.

http://www.nbcindia.com/Descriptions.asp?title_id=2545


Cor, try to keep it outside the groups.

"A real man can admit when he makes a mistake."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #41

"Frans Bouma [C# MVP]" <
>

I have the idea, if Frans tell that I am not than I will agree.


wat is dit voor steenkolen-engels, man :)


Indeed :-)

Cor
Nov 17 '05 #42
Bill,

Mijn Nederlands is slecht, maar ik denk dat ik het begrijp


If it is not Bablefish than it was very good.

The English meaning of

Het slaat als een tang op een varken

That fits as a flag on a broomstick

:-)

Cor
Nov 17 '05 #43
Static is not an equivalent of Yield.

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:On**************@TK2MSFTNGP10.phx.gbl...
or any equivalent of it" ?


"Sahil Malik [MVP]" <co*****************@nospam.com> schreef in bericht
news:ur**************@tk2msftngp13.phx.gbl...
Yeah, but it has nothing to do with iterators ;-).


E-X-A-C-T-L-Y MY POINT :-)

Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
What the heck - I can't find it. A bit shocked to see it missing though.

or any equivalent of it" ?
--

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------


Nov 17 '05 #44
Cor,

Lets try one more time now -

"I asked about "Yield" and you told me about Static."

Get it?

- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
----------------------------------------------------------------------------

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ec**************@TK2MSFTNGP14.phx.gbl...
Sahil,
Frans is completely right in this regard. I asked you about yield, you
are telling me about static/shared -


Maybe it is wise that you buy this book before you go on in that one that
you are endless telling in these newsgroup that you are writting now.

http://www.nbcindia.com/Descriptions.asp?title_id=2545

I hope this helps,

Cor

Nov 17 '05 #45
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> schrieb:
> I just wanted to explain that code like you wrote is hard to read,
> thus not what you want. This was mainly caused by the static
> keyword. I.o.w.: static is IMHO a keyword you should better avoid
> (like goto),


I disagree. There are certain cases where 'Static' makes perfect
sense and additionally leads to better-encapsulated code than using a
private (shared) field. Note that this should not encourage the use
of 'Static' where it doesn't make much sense ;-).


Now I'm interested in what these situations are. Could you give an
explanation where it will give much BETTER code than when you wouldn't
have the Static keyword?


I never said that it will give /much/ better code! One of the Windows Forms
FAQs is how to execute certain code only the first time a Windows Forms form
is activated. There are many different solutions to the problem which have
different advantages and disadvantages. Sure, you could create a private
field instead of the static variable below, but I think that a static
variable encapsulates the whole functionality more tightly:

\\\
Private Sub Form1_Activated( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activated
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoEvents() ' ...
MsgBox("Form activated for the first time!")
End If
End Sub
///

Today's code often suffers from the problem that private variables holding
values used in a method or property semantically belong to a certain method
or property, and /not/ to the whole class. For methods this problem can be
reduced by using static variables. Similar functionality for properties
would be great, for example, something like the code below:

\\\
Public Property TheFoo() As Foo
Dim TheFooValue As Foo
Get
Return TheFooValue
End Get
Set(ByVal Value As Foo)
TheFooValue = Value
End Set
End Property
///

However, this is currently not supported.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 17 '05 #46
Sahil,
Static is not an equivalent of Yield.

Now I see it, probably do I not understand the word "Any" (that word that
you wrote and now consequently are changing for "an").

I did not know that in English "any" is an equivalent for "exactly"

While I did not say, "it is". I wrote that I thought ("think" was what I
wrote) that it reached that.

Ah, I see it; "thinking" is probably the same in English as "telling"

Sorry, I assume that is the problem,

Thank you for learning me this

Cor
Nov 17 '05 #47
Herfried,
\\\
Private Sub Form1_Activated( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activated
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoEvents() ' ...
MsgBox("Form activated for the first time!")
End If
End Sub
///

For me this is BS (not angry meant only for the discussion). I have even
seen that people use for this a tag in a control, because it is always
global, my opinion is than to set it just global. In VB it is that even
shorter to write if you use "Dim" (what I don't do if it is global) than
"Static". The technical result is probably (you know that most probably
better) the same.

Where I have seen static used nice, was where your friend (Fergus) used in
to keep track of the last used mouse pointers inside a procedure. That was
the reason why I direct made a relation to an iterator.

However it is for me something very special in VB. Therefore I don't like
it. I have to search that static variable (I don't expect it as static) and
make than easily the same mistake as Frans made with my sample.

Cor
Nov 17 '05 #48
"Cor Ligthert" <no************@planet.nl> schrieb:
\\\
Private Sub Form1_Activated( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activated
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoEvents() ' ...
MsgBox("Form activated for the first time!")
End If
End Sub
///

For me this is BS (not angry meant only for the discussion). I have even
seen that people use for this a tag in a control, because it is always
global, my opinion is than to set it just global. In VB it is that even
shorter to write if you use "Dim" (what I don't do if it is global) than
"Static". The technical result is probably (you know that most probably
better) the same.


I feel sorry, but I don't have a cue what you are talking about...

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 17 '05 #49
Herfried K. Wagner [MVP] wrote:
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> schrieb:
> I just wanted to explain that code like you wrote is hard to read, >> > thus not what you want. This was mainly caused by the
static >> > keyword. I.o.w.: static is IMHO a keyword you should
better avoid >> > (like goto),
I disagree. There are certain cases where 'Static' makes perfect
sense and additionally leads to better-encapsulated code than
using a >> private (shared) field. Note that this should not
encourage the use >> of 'Static' where it doesn't make much sense ;-).

Now I'm interested in what these situations are. Could you give an
explanation where it will give much BETTER code than when you
wouldn't have the Static keyword?


I never said that it will give much better code! One of the Windows
Forms FAQs is how to execute certain code only the first time a
Windows Forms form is activated. There are many different solutions
to the problem which have different advantages and disadvantages.
Sure, you could create a private field instead of the static variable
below, but I think that a static variable encapsulates the whole
functionality more tightly:

\\\
Private Sub Form1_Activated( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activated
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoEvents() ' ...
MsgBox("Form activated for the first time!")
End If
End Sub
///


Though the 'form' is activated so isn't it more appropriate to simply
keep a member variable? After all, the data of the activation of the
form belongs to the form, at least that's my understanding, but that's
nittpicking about the example. I think in a more procedural
environment, where the code is stored in a class but you want to run
the code just one time, not multiple times, and the code can;t really
rely on the class it is in as the class is just a container of the
code, it might make sense, but IMHO those situations are pretty rare
(as in: in an OO world, you can always write the code differently so
you dont' need it)
Today's code often suffers from the problem that private variables
holding values used in a method or property semantically belong to a
certain method or property, and not to the whole class. For methods
this problem can be reduced by using static variables. Similar
functionality for properties would be great, for example, something
like the code below:

\\\
Public Property TheFoo() As Foo
Dim TheFooValue As Foo
Get
Return TheFooValue
End Get
Set(ByVal Value As Foo)
TheFooValue = Value
End Set
End Property
///

However, this is currently not supported.


and rightfully so. properties belong to the semantic unit represented
by the class to set/get class related (private) fields. All code in a
class is there because it is behavior belonging to the type(s) the
class represents and to serve the data the class holds. It requires
that procedural thinking should take a backseat. Personally I can't
think of a situation where local scoped data has to be stored in a
class member because the method ends and it's semantically wrong to
place the data in a variable outside the method.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
Nov 17 '05 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Tobiah | last post by:
def maker(): for i in range(100): yield i foo:4: Warning: 'yield' will become a reserved keyword in the future File "foo", line 4 yield i ^ SyntaxError: invalid syntax
3
by: km | last post by:
Hi all, i didnt understand the purpose of 'yield' keyword and the concept of 'generators' in python. can someone explain me with a small example how generators differ from normal function...
54
by: Sahil Malik [MVP] | last post by:
What the heck - I can't find it. A bit shocked to see it missing though. So "Does VB.NET have the yield keyword, or any equivalent of it" ? -- - Sahil Malik Upcoming ADO.NET 2.0 book -...
22
by: Mateuszk87 | last post by:
Hi. may someone explain "yield" function, please. how does it actually work and when do you use it? thanks in forward mateusz
2
by: cartoper | last post by:
I am coming to VB.Net from C#. One feature I really like about C# is the yield contextual keyword. Here is what MSDN says about it: -------------- Used in an iterator block to provide a value...
3
by: Ehsan | last post by:
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.