473,889 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21 '05
54 6947
> "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******** *****@TK2MSFTNG P12.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 21 '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 21 '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 21 '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******** ******@TK2MSFTN GP10.phx.gbl...
or any equivalent of it" ?


"Sahil Malik [MVP]" <co************ *****@nospam.co m> schreef in bericht
news:ur******** ******@tk2msftn gp13.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 21 '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******** ******@TK2MSFTN GP14.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 21 '05 #45
"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> 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.Activate d
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoE vents() ' ...
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 21 '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 21 '05 #47
Herfried,
\\\
Private Sub Form1_Activated ( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activate d
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoE vents() ' ...
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 21 '05 #48
"Cor Ligthert" <no************ @planet.nl> schrieb:
\\\
Private Sub Form1_Activated ( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Activate d
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoE vents() ' ...
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 21 '05 #49
Herfried K. Wagner [MVP] wrote:
"Frans Bouma [C# MVP]" <pe************ ******@xs4all.n l> 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.Activate d
Static IsActivated As Boolean
If Not IsActivated Then
IsActivated = True
Application.DoE vents() ' ...
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 21 '05 #50

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

Similar topics

54
2739
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 - http://tinyurl.com/9bync ----------------------------------------------------------------------------
3
6942
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 experienced programmers. Visit http://diveintopython.org/ for the latest version.
0
9967
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10792
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9611
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.