|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Text box number of characters VB6What's the simplest way to count the number of characters entered into a
text box? Examples I've found like: Private Sub Command1_Click() Text2.Text = Text1.Text.Length End Sub Fail Any suggestions appreciated. "Edward" <nospam@mail.com> wrote in message You were probably finding examples for VB.NET, quite a different beast than news:Do2ol.60995$fM1.9833@newsfe14.iad... > What's the simplest way to count the number of characters entered into a > text box? > > Examples I've found like: > Private Sub Command1_Click() > Text2.Text = Text1.Text.Length > End Sub > > Fail > > Any suggestions appreciated. VB6. Use the Len() function. Look it up in VB6's Help. Text2.Text = Len(Text1.Text) -- Mike "Edward" <nospam@mail.com> wrote in message Resolved using:news:Do2ol.60995$fM1.9833@newsfe14.iad... > What's the simplest way to count the number of characters entered into a > text box? > > Examples I've found like: > Private Sub Command1_Click() > Text2.Text = Text1.Text.Length > End Sub > > Fail > > Any suggestions appreciated. Text2.Text = Len(Text1)
Show quote
Hide quote
>> What's the simplest way to count the number of characters entered into a Just for clarity in future code maintenance sessions, I would suggest you >> text box? >> >> Examples I've found like: >> Private Sub Command1_Click() >> Text2.Text = Text1.Text.Length >> End Sub >> >> Fail >> >> Any suggestions appreciated. > > Resolved using: > > Text2.Text = Len(Text1) specify the Text property for the TextBox in the Len function call... Text2.Text = Len(Text1.Text) -- Rick (MVP - Excel)
Show quote
Hide quote
"Rick Rothstein" <rick.newsNO.SPAM@NO.SPAMverizon.net> wrote in message yep, and the case for consistency. If you use the default property in one news:%23tUapZRlJHA.4404@TK2MSFTNGP06.phx.gbl... >>> What's the simplest way to count the number of characters entered into a >>> text box? >>> >>> Examples I've found like: >>> Private Sub Command1_Click() >>> Text2.Text = Text1.Text.Length >>> End Sub >>> >>> Fail >>> >>> Any suggestions appreciated. >> >> Resolved using: >> >> Text2.Text = Len(Text1) > > Just for clarity in future code maintenance sessions, I would suggest you > specify the Text property for the TextBox in the Len function call... > > Text2.Text = Len(Text1.Text) > part of the expression best to use it in the other part. Hi Edward,
Show quoteHide quote "Edward" <nospam@mail.com> wrote in message As Rick suggests, it's generally better to avoid the use of default news:YI2ol.60997$fM1.39693@newsfe14.iad... > "Edward" <nospam@mail.com> wrote in message > news:Do2ol.60995$fM1.9833@newsfe14.iad... >> What's the simplest way to count the number of characters entered into a >> text box? >> >> Examples I've found like: >> Private Sub Command1_Click() >> Text2.Text = Text1.Text.Length >> End Sub >> >> Fail >> >> Any suggestions appreciated. > > Resolved using: > > Text2.Text = Len(Text1) properties, and instead write: Text2.Text = Len(Text1.Text) "Bill McCarthy" <Bill McCarthy Is An Identity Thief> wrote in message Hi Edward. As Rick suggests, and as McCarthy now also suggests, it's news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... > Hi Edward. As Rick suggests, it's generally better to avoid > the use of default properties, and instead write: > Text2.Text = Len(Text1.Text) generally better to avoid the use of default properties, and instead write: Text2.Text = Len(Text1.Text) Anyone else confirm that? ;-) Mike Mike Williams wrote:
> No, in fact I'd dispute it. It's not only best to avoid default> Hi Edward. As Rick suggests, and as McCarthy now also suggests, it's > generally better to avoid the use of default properties, and > instead write: > > Text2.Text = Len(Text1.Text) > > Anyone else confirm that? ;-) properties, it's also best to avoid implicit conversions. Text2.Text = CStr(Len(Text1.Text)) (-: "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message .. . . and another totally useless answer gets added to McCarthy's brownie news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... > Hi Edward, As Rick suggests, it's generally better to avoid > the use of default properties, and instead write: > Text2.Text = Len(Text1.Text) points total by his Micro$oft puppet master. "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message No brownie points for that, it uses ETC. It should read:news:eIOp5cZlJHA.1248@TK2MSFTNGP03.phx.gbl... > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message > news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... > >> Hi Edward, As Rick suggests, it's generally better to avoid >> the use of default properties, and instead write: >> Text2.Text = Len(Text1.Text) > > . . . and another totally useless answer gets added to McCarthy's brownie > points total by his Micro$oft puppet master. Text2.Text = CStr(Len(Text1.Text)) Dave O. Hi Dave,
Show quoteHide quote "Dave O." <nob***@nowhere.com> wrote in message Oh Williams still trolling... how sad for him.news:eJJTVrZlJHA.1252@TK2MSFTNGP03.phx.gbl... > > "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message > news:eIOp5cZlJHA.1248@TK2MSFTNGP03.phx.gbl... >> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message >> news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... >> >>> Hi Edward, As Rick suggests, it's generally better to avoid >>> the use of default properties, and instead write: >>> Text2.Text = Len(Text1.Text) >> >> . . . and another totally useless answer gets added to McCarthy's brownie >> points total by his Micro$oft puppet master. > > No brownie points for that, it uses ETC. It should read: Len() returns a Long which is always safely converted to a String, i.e a > Text2.Text = CStr(Len(Text1.Text)) > widening conversion. Implicit widening conversions are seldom a problem. Implicit narrowing conversions are what are generally referred to as evil type conversion.
Show quote
Hide quote
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message Who cares, it's bad practice which if used where it's probably OK will be news:uFtl8yZlJHA.1252@TK2MSFTNGP03.phx.gbl... > Hi Dave, > > "Dave O." <nob***@nowhere.com> wrote in message > news:eJJTVrZlJHA.1252@TK2MSFTNGP03.phx.gbl... >> >> "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message >> news:eIOp5cZlJHA.1248@TK2MSFTNGP03.phx.gbl... >>> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message >>> news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... >>> >>>> Hi Edward, As Rick suggests, it's generally better to avoid >>>> the use of default properties, and instead write: >>>> Text2.Text = Len(Text1.Text) >>> >>> . . . and another totally useless answer gets added to McCarthy's >>> brownie points total by his Micro$oft puppet master. >> > > Oh Williams still trolling... how sad for him. > >> No brownie points for that, it uses ETC. It should read: >> Text2.Text = CStr(Len(Text1.Text)) >> > > > Len() returns a Long which is always safely converted to a String, i.e a > widening conversion. Implicit widening conversions are seldom a problem. > Implicit narrowing conversions are what are generally referred to as evil > type conversion. used where it's not OK. If it's OK to allow implicit type conversion which always seem to work, then it's equally OK to omit default properties because that always seems to work - please try to be consistent. VB.NET may encourage sloppy programming, but there is no need to spread that rot here. Dave O.
Show quote
Hide quote
"Dave O." <nob***@nowhere.com> wrote in message I suggest you look at the differences: in particular the differences between news:OGQ2gtblJHA.4372@TK2MSFTNGP02.phx.gbl... > > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message > news:uFtl8yZlJHA.1252@TK2MSFTNGP03.phx.gbl... >> Hi Dave, >> >> "Dave O." <nob***@nowhere.com> wrote in message >> news:eJJTVrZlJHA.1252@TK2MSFTNGP03.phx.gbl... >>> >>> "Mike Williams" <M***@WhiskyAndCoke.com> wrote in message >>> news:eIOp5cZlJHA.1248@TK2MSFTNGP03.phx.gbl... >>>> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message >>>> news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... >>>> >>>>> Hi Edward, As Rick suggests, it's generally better to avoid >>>>> the use of default properties, and instead write: >>>>> Text2.Text = Len(Text1.Text) >>>> >>>> . . . and another totally useless answer gets added to McCarthy's >>>> brownie points total by his Micro$oft puppet master. >>> >> >> Oh Williams still trolling... how sad for him. >> >>> No brownie points for that, it uses ETC. It should read: >>> Text2.Text = CStr(Len(Text1.Text)) >>> >> >> >> Len() returns a Long which is always safely converted to a String, i.e a >> widening conversion. Implicit widening conversions are seldom a problem. >> Implicit narrowing conversions are what are generally referred to as evil >> type conversion. > > Who cares, it's bad practice which if used where it's probably OK will be > used where it's not OK. > If it's OK to allow implicit type conversion which always seem to work, > then it's equally OK to omit default properties because that always seems > to work - please try to be consistent. widening conversions and narrowing. A widening conversion is guaranteed to work. The only problems I have ever seen it cause is in code readability as the type may not be clear. Default properties on the other hand can cause a whole heap of code maintenance issues on top of any readability issues. Narrowing conversions are of course a different matter. They should be handled explicitly because there is the chance they fail. > VB.NET may encourage sloppy programming, but there is no need to spread ROFL ! First, .NET was mentioned in regard to this, but now you mention it, > that rot here. > the fact is .Net is superior, not inferior. .NET has explicit typing, strong typing, optional strict semantics. It's VB6 which forces you to use assignment to force a cast. But that's all an aside to what was being discussed. But if you like I'm happy to go into more detail there, such as how VB on .NET has the CType operator, operator overloading, as well as DirectCast etc. Let me know if you need more detail, as I'd hate you to wrongly think VB.NET encourages sloppy programming. it allows the same sloppiness as VB6 does, but it also allows you to enforce better programming practices. HTH's :) Bill,
Australia is much larger then the Netherlands. I hope you don't mind that I feel me perfectly well here. :-) CorCor Ligthert[MVP] wrote:
> I hope you don't mind that I feel me perfectly well here. Cor, why don't you go feel yourself somewhere else, eh? ;-)
Show quote
Hide quote
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message I am well aware of the difference between for example converting a long to news:uPxb84blJHA.4696@TK2MSFTNGP02.phx.gbl... >> Who cares, it's bad practice which if used where it's probably OK will be >> used where it's not OK. >> If it's OK to allow implicit type conversion which always seem to work, >> then it's equally OK to omit default properties because that always seems >> to work - please try to be consistent. > > I suggest you look at the differences: in particular the differences > between widening conversions and narrowing. > A widening conversion is guaranteed to work. The only problems I have > ever seen it cause is in code readability as the type may not be clear. > Default properties on the other hand can cause a whole heap of code > maintenance issues on top of any readability issues. > > Narrowing conversions are of course a different matter. They should be > handled explicitly because there is the chance they fail. an integer and converting an integer into a long, In one case it will always work but in the other there could be a problem. My point is that if you encourage non-expert users to omit the explicit type conversion in some cases they are likey to leave it out where it is needed, however if you encourage them to always be explicit then they will always get it correct. There is no problem with specifying the conversion function where the type is widening and it makes the code far clearer to read, so omittion while technically acceptable is a sloppy practice especially when teaching. Dave O. Hi Bill,
This makes me curious, is there any explanation about this then then "In generally better"? In my opinion it is in generally better to use a property then a function. However, I assume there is a special reason for this for VB6 and so I am currious about that. Cor Show quoteHide quote "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... > Hi Edward, > > "Edward" <nospam@mail.com> wrote in message > news:YI2ol.60997$fM1.39693@newsfe14.iad... >> "Edward" <nospam@mail.com> wrote in message >> news:Do2ol.60995$fM1.9833@newsfe14.iad... >>> What's the simplest way to count the number of characters entered into a >>> text box? >>> >>> Examples I've found like: >>> Private Sub Command1_Click() >>> Text2.Text = Text1.Text.Length >>> End Sub >>> >>> Fail >>> >>> Any suggestions appreciated. >> >> Resolved using: >> >> Text2.Text = Len(Text1) > > As Rick suggests, it's generally better to avoid the use of default > properties, and instead write: > Text2.Text = Len(Text1.Text) > > Hi Cor,
"Cor Ligthert[MVP]" <Notmyfirstn***@planet.nl> wrote in message Code that uses default properties can *in general* be harder to maintain. news:%2378mXnZlJHA.1168@TK2MSFTNGP05.phx.gbl... > Hi Bill, > > This makes me curious, is there any explanation about this then then "In > generally better"? > For example, lets say you have a method Foo that expects a String argument, Foo(ByVal x as string). If you change that to variant then instead of the textbox's text you end up getting the textbox itself. That's kind of issue can only be detected at runtime. > In my opinion it is in generally better to use a property then a function. Properties are an abstraction over functions to imply state. Where there is no implied state, functions are typically more appropriate. Show quoteHide quote > However, I assume there is a special reason for this for VB6 and so I am > currious about that. > > Cor > > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message > news:eWL8fzUlJHA.3760@TK2MSFTNGP03.phx.gbl... >> Hi Edward, >> >> "Edward" <nospam@mail.com> wrote in message >> news:YI2ol.60997$fM1.39693@newsfe14.iad... >>> "Edward" <nospam@mail.com> wrote in message >>> news:Do2ol.60995$fM1.9833@newsfe14.iad... >>>> What's the simplest way to count the number of characters entered into >>>> a text box? >>>> >>>> Examples I've found like: >>>> Private Sub Command1_Click() >>>> Text2.Text = Text1.Text.Length >>>> End Sub >>>> >>>> Fail >>>> >>>> Any suggestions appreciated. >>> >>> Resolved using: >>> >>> Text2.Text = Len(Text1) >> >> As Rick suggests, it's generally better to avoid the use of default >> properties, and instead write: >> Text2.Text = Len(Text1.Text) >> >> >
PropertyBag and settings
How to embed a Manifest File? Graphic Time Labeling how to reposition desktop icons ADO Recordset Find method Problem Test (yeah, I know) Visual Basic 6.0 on 64-Bit system Re: create pdf file in VB6 VB6 with SQLite: Is there a report generator/viewer? Shell Function: task ID |
|||||||||||||||||||||||