|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
How do I get a text box to clear itself when I switch from one tab to
another. The TextBox is poulated using selections from the tabs, but when I switch to a different tab, the information in the textbox is still there. -- Have a great day! Drew Leon "Drew Leon" <DrewL***@discussions.microsoft.com> wrote in message textbox1.text = ""news:ED36AC3F-8618-4C19-A94D-924C445CDCC7@microsoft.com... > How do I get a text box to clear itself when I switch from one tab to > another. The TextBox is poulated using selections from the tabs, but when I > switch to a different tab, the information in the textbox is still there. > -- > Have a great day! > Drew Leon Or textbox1.text = String.Empty
not sure I heard somewhere that this improves performance... something having to do with inline literals NOT being efficiently "interned" in the string table. I dunno. But, in VB.Classic this was indeed true: 10 ""'s in your code meant 10 empty strings and their size descriptor were put into the Vtable of your EXE.... this was and is a little known fact. Show quoteHide quote "Hal Rosser" <hmros***@bellsouth.net> wrote in message news:g5VDf.425$_i2.266@bignews3.bellsouth.net... > > "Drew Leon" <DrewL***@discussions.microsoft.com> wrote in message > news:ED36AC3F-8618-4C19-A94D-924C445CDCC7@microsoft.com... >> How do I get a text box to clear itself when I switch from one tab to >> another. The TextBox is poulated using selections from the tabs, but when > I >> switch to a different tab, the information in the textbox is still there. >> -- >> Have a great day! >> Drew Leon > > textbox1.text = "" > > "CMM" <cmm@nospam.com> wrote in message Interesting - I would have thought ms would have 'in-lined' it either way innews:%235O3XTuJGHA.1728@TK2MSFTNGP14.phx.gbl... > Or textbox1.text = String.Empty > > not sure I heard somewhere that this improves performance... something > having to do with inline literals NOT being efficiently "interned" in the > string table. I dunno. But, in VB.Classic this was indeed true: 10 ""'s in > your code meant 10 empty strings and their size descriptor were put into the > Vtable of your EXE.... this was and is a little known fact. > the compile process. > Hal it is, at end in the optimized code there is no difference. In this > Interesting - I would have thought ms would have 'in-lined' it either way > in > the compile process. > newsgroup to clean a string, is after long and endless discussions, by most of us including me chosen for "". Cor I have standardized on String.Empty because I use it it to ALWAYS initialize
a string. (Dim s As String = String.Empty). Try using s.Length on an un-initialized string and you'd see why this is very good practice! Obviously this is much better than having As String = "" in dozens sometimes hundreds(!) of places in your code (each one creating a *new* object). So if I use it in that in the Dim, why not use it everywhere else (like comparisons)? That's just my practice. :-) Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:ONoECrwJGHA.964@tk2msftngp13.phx.gbl... > > >> Interesting - I would have thought ms would have 'in-lined' it either way >> in >> the compile process. >> > Hal it is, at end in the optimized code there is no difference. In this > newsgroup to clean a string, is after long and endless discussions, by > most of us including me chosen for "". > > Cor > CMM,
It is not consistent with what we have spoken as standard in this newsgroup. For me everybody can use as he wants. :-) CorIt's easier to use "" ... and very intuitive too. I know. I have to catch
myself all the time too. However, is it a standard (with frequenters of this "newsgroup") to *initialize* strings as well? Dim s As String = "" I started doing this as a general practice after discovering that (in .NET 1.1) if you passed a non-initialized string to certain ADO.NET methods it would cause an exception (and elsewhere like using s.Length). IMHO if you have a lot of these (Dim s As String = "")... (for instance, if you have big business objects with lots of string fields)... it is very bad and inneficient to use "" instead of the String.Empty constant (because of the object references being created and (and discarded) with the former). CMM
.... > It's easier to use "" ... and very intuitive too. I know. I have to catch This is C style behaviour because there is a warning thrown, it is the > myself all the time too. However, is it a standard (with frequenters of > this "newsgroup") to *initialize* strings as well? > Dim s As String = "" > standard here not to initialize aninthing with a value what is standard done. (However it gives you now that impossible not true warning). Dim s As String = "" gives more instructions than needed. However a string is a strange thing in VBNet. It behaves as a value and at the same time it is an object. There is a difference between String Is Nothing (Is a real empty string which can exist if it is not yet used) String = Nothing (This one catches IS Nothing and = "") However there can be some situations where you want to know Is Nothing. Cor > However a string is a strange thing in VBNet. It behaves as a value and at Like a photon. :-)> the same time it is an object. > This is C style behaviour because there is a warning thrown, it is the Well, I guess that's OK if you don't expect to call ANY member method of the > standard here not to initialize aninthing with a value what is standard > done. string (.ToLower, .StartsWith, .Length, etc.)...which would cause and exception!... and you're VERY SURE any subroutines (yours, framework, 3rd party, whatever) you pass the string to won't do it also (like ADO.NET... which by the way will). Bad bad bad design.... how does one become an MVP? (in jest) ;-) > There is a difference between String Is Nothing (Is a real empty string Yeah. That's only because the comparison operators for a string are > which can exist if it is not yet used) String = Nothing (This one catches > IS Nothing and = "") overloaded to treat <Nothing> as ""... it doesn't mean that the string really is "" Dim s As String MsgBox(a.Length.ToString()) <--- Exception! Why doesn't it return 0? ha ha ha jokes on you! MsgBox(a.ToLower) '<--- Exception thrown... why oh why??? Obviously, I'm being facetious. "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message Like a photon. :-)news:uGgr3e8JGHA.3932@TK2MSFTNGP15.phx.gbl... > CMM > This is C style behaviour because there is a warning thrown, it is the > standard here not to initialize aninthing with a value what is standard > done. (However it gives you now that impossible not true warning). > However a string is a strange thing in VBNet. It behaves as a value and at > the same time it is an object. Show quoteHide quote > > However there can be some situations where you want to know Is Nothing. > > Cor > > > "CMM" <cmm@nospam.com> schrieb Why do you call it on 'Nothing'? I could swear you forgot an Else block> > However a string is a strange thing in VBNet. It behaves as a > > value and at the same time it is an object. > > Like a photon. :-) > > > This is C style behaviour because there is a warning thrown, it is > > the standard here not to initialize aninthing with a value what is > > standard done. > > Well, I guess that's OK if you don't expect to call ANY member > method of the string (.ToLower, .StartsWith, .Length, etc.)...which > would cause and exception!... before. > and you're VERY SURE any subroutines (yours, framework, 3rd party, With your own routines, you have to check for Nothing anyway and throw an> whatever) you pass the string to won't do it also (like ADO.NET... which > by the way will). ArgumentNullException. On the other side, before passing a string variable to a procedure that does not "like" Nothing, you have the same problem as mentioned above: You forgot an Else block before. > Dim s As String "Variable 'a' not declared". ;-)> MsgBox(a.Length.ToString()) <--- Exception! Why doesn't it return 0? ha ha > ha jokes on you! > MsgBox(a.ToLower) '<--- Exception thrown... why oh why??? > > Obviously, I'm being facetious. :-) Often, something is serious, despite. ;-) The example shows very well, why it is not necessary to initialize it with "" (or string.empty): Youshould never do what you do in the example. Armin "Armin Zingler" <az.nospam@freenet.de> wrote in message Sometimes you have no idea if the procedure you're calling cares or not. news:eS2MO89JGHA.3332@TK2MSFTNGP11.phx.gbl... > With your own routines, you have to check for Nothing anyway and throw an > ArgumentNullException. On the other side, before passing a string variable > to a procedure that does not "like" Nothing, you have the same problem as > mentioned above: You forgot an Else block before. Instead of checking for a null string with a myriad of If/Else loops all over the place.... why not just do the decent thing and initialize your string??? > "Variable 'a' not declared". ;-) Doh! No intellisense in a newsreader window. Good eyes! But, you know what I meant by the code. And my code doesn't look like that.... it always looks like: Dim s As String = String.Empty Dim a As String = String.Empty And, I also initialize arrays for similar reasons... Dim ary As Integer() = {} I highly recommend it.... and so does Visual Studio's Code Analyzer. Makes for nice bug-free, easy-to-read code. CMM,
A few messages and now you show already yourself what is against "standard consistent writing conventions for programs" I assume that you see what I mean (otherwise I will explain it deeper). All (good) developers will (lucky enough) argument it and try to make things better. (It was not by accident that I started this discussions, a part of this text was already in my first answer to Hall, however I thought let it first evaluate itself a little bit and have stuffed that text than) :-) Cor"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message Sorry, I have no clue.news:ummchO%23JGHA.2912@tk2msftngp13.phx.gbl... > CMM, > > A few messages and now you show already yourself what is against "standard > consistent writing conventions for programs" > Again, I'm clueless. I just find it surprising that some of you guys > I assume that you see what I mean (otherwise I will explain it deeper). > All (good) developers will (lucky enough) argument it and try to make > things better. > > (It was not by accident that I started this discussions, a part of this > text was already in my first answer to Hall, however I thought let it > first evaluate itself a little bit and have stuffed that text than) > espouse even RECOMMEND such amaturish (IMO) practices. I haven't truly participated in ng's for years... I work in big teams and collaborate with developers in other companies.... so I haven't felt the need until recently (VS2005). I am truly horrified at what I'm seeing in the (this?) community. It's like NONE of the lessons of the past have been learned and not even hints from other development platforms taken seriously. "That's a C# thing," "that's a C++"...... NO man, that's good common sense! I do enjoy debating with you... :-) please don't take anything I say wrong. I see you've helped countless people in these forums.
Show quote
Hide quote
"CMM" <cmm@nospam.com> schrieb Sorry, but you don't get the point. Why do you *always* ("always" means: no> "Armin Zingler" <az.nospam@freenet.de> wrote in message > news:eS2MO89JGHA.3332@TK2MSFTNGP11.phx.gbl... > > With your own routines, you have to check for Nothing anyway and > > throw an ArgumentNullException. On the other side, before passing > > a string variable to a procedure that does not "like" Nothing, you > > have the same problem as mentioned above: You forgot an Else block > > before. > > Sometimes you have no idea if the procedure you're calling cares or > not. Instead of checking for a null string with a myriad of If/Else > loops all over the place.... why not just do the decent thing and > initialize your string??? matter which code path the CPU will go in this procedure) initialize it with ""? - If it will be "" always, use a constant. - The other case is "not always". "Not always" means, you have different cases. If you have different cases, you can set it to "" in one case and to other values in other cases. You will *never* run into a NullReferenceException after the If-Then block. If you do, you forgot the Else block. In addition, why always set it to "" if it will be overweritten in one of the cases anyway? This is true for both, when using the variable in your own procedure as well as when passing it to another procedure. I've written pretty much VB.Net code meanwhile but never had to initialize a string variable to "" ever. Show quoteHide quote > > "Variable 'a' not declared". ;-) Initializing arrays this way doesn't make sense as well. If you will always> > Doh! No intellisense in a newsreader window. Good eyes! But, you > know what I meant by the code. > And my code doesn't look like that.... it always looks like: > Dim s As String = String.Empty > Dim a As String = String.Empty > > And, I also initialize arrays for similar reasons... > Dim ary As Integer() = {} > > I highly recommend it.... and so does Visual Studio's Code Analyzer. > Makes for nice bug-free, easy-to-read code. have an empty array, you don't really need one. If it will not always be empty, you can create an empty array in one case and a not-empty array in other cases. Of course, for both (strings and arrays) there are exceptions, but *as a rule* what you're doing doesn't make sense at all. Armin "CMM" <cmm@nospam.com> schrieb: I believe this strongly depends on what you are doing.> It's easier to use "" ... and very intuitive too. I know. I have to catch > myself all the time too. However, is it a standard (with frequenters of > this "newsgroup") to *initialize* strings as well? > Dim s As String = "" > a lot of these (Dim s As String = "")... (for instance, if you have big That's plain wrong. Both, '""' and 'String.Empty' are equally efficient.> business objects with lots of string fields)... it is very bad and > inneficient to use "" instead of the String.Empty constant (because of the > object references being created and (and discarded) with the former). -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message <snip>news:O$Lw52%23JGHA.3332@TK2MSFTNGP11.phx.gbl... > That's plain wrong. Both, '""' and 'String.Empty' are equally efficient. I'm not an MSIL expert but everything I've read suggests that you're wrong. The former uses "ldstr" to push an object reference and forces a scan in the string table for a match. The latter uses "ldsfld" which simply references an already existing static (no scan of the string table, no new object). Granted the performance is not noticable in normal situations... but if you have a tons of big entity objects with string properties I don't think its fair to say they're both "equally efficient." "CMM" <cmm@nospam.com> schrieb: I keep them uninitialized and use 'Len' instead of 'String.Length'.>I have standardized on String.Empty because I use it it to ALWAYS >initialize a string. (Dim s As String = String.Empty). Try using s.Length >on an un-initialized string and you'd see why this is very good practice! > Obviously this is much better than having As String = "" in dozens It doesn't actually create new objects. All occurances of the zero-length > sometimes hundreds(!) of places in your code (each one creating a *new* > object). So if I use it in that in the Dim, why not use it everywhere else > (like comparisons)? string literal are pointing to the same string object in memory. For reasons of readability I'd prefer '""' over 'String.Empty'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Thank you Hal. I have been trying to research my own question for two days
now, with no avail. I just can't get it right. I guess this is these are the Beginners "bumps in the road." Thanks again for your help. Have a great day! Show quoteHide quote "Hal Rosser" <hmros***@bellsouth.net> wrote in message news:%IXDf.16885$dF5.7504@bignews1.bellsouth.net... > > "CMM" <cmm@nospam.com> wrote in message > news:%235O3XTuJGHA.1728@TK2MSFTNGP14.phx.gbl... >> Or textbox1.text = String.Empty >> >> not sure I heard somewhere that this improves performance... something >> having to do with inline literals NOT being efficiently "interned" in the >> string table. I dunno. But, in VB.Classic this was indeed true: 10 ""'s >> in >> your code meant 10 empty strings and their size descriptor were put into > the >> Vtable of your EXE.... this was and is a little known fact. >> > Interesting - I would have thought ms would have 'in-lined' it either way > in > the compile process. > >
Const Member in Base Class to be overridden in Derived Class?
Sync databound combobox to current bound record in form Installing VB.NET 2003 Weird system.net.mail behaviour Clearing a TextBox ComboBox design-time DataBinding setting questions. vbScript eval() function equivalent in VB.Net - Dynamically evaluate code how to: remove unequal white spaces with trim method Share datasource among programs Can't Figure Out How to Calculate Using Tabs |
|||||||||||||||||||||||