Text box number of characters VB6 
Author Message
 Text box number of characters VB6

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.



Thu, 11 Aug 2011 10:04:19 GMT  
 Text box number of characters VB6


Quote:
> 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.

You were probably finding examples for VB.NET, quite a different beast than
VB6.

Use the Len() function.  Look it up in VB6's Help.

Text2.Text = Len(Text1.Text)

--
Mike



Thu, 11 Aug 2011 10:16:43 GMT  
 Text box number of characters VB6

Quote:
> 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)



Thu, 11 Aug 2011 10:26:01 GMT  
 Text box number of characters VB6

Quote:
>> 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)

--
Rick (MVP - Excel)



Fri, 12 Aug 2011 01:52:47 GMT  
 Text box number of characters VB6
Hi Edward,


Quote:


>> 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)


Fri, 12 Aug 2011 08:06:12 GMT  
 Text box number of characters VB6


Quote:
>>> 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)

yep, and the case for consistency. If you use the default property in one
part of the expression best to use it in the other part.


Fri, 12 Aug 2011 08:07:33 GMT  
 Text box number of characters VB6


Quote:
> Hi Edward. As Rick suggests, it's generally better to avoid
> the use of default properties, and instead write:
> Text2.Text = Len(Text1.Text)

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?    ;-)

Mike



Fri, 12 Aug 2011 17:11:30 GMT  
 Text box number of characters VB6


Quote:
> 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.


Fri, 12 Aug 2011 17:15:46 GMT  
 Text box number of characters VB6
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



Quote:
> Hi Edward,





>>> 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)



Fri, 12 Aug 2011 17:33:49 GMT  
 Text box number of characters VB6


Quote:


>> 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:
Text2.Text = CStr(Len(Text1.Text))

Dave O.



Fri, 12 Aug 2011 17:40:55 GMT  
 Text box number of characters VB6
Hi Dave,


Quote:





>>> 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.

Quote:
> 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.


Fri, 12 Aug 2011 17:47:47 GMT  
 Text box number of characters VB6
Hi Cor,


Quote:
> Hi Bill,

> This makes me curious, is there any explanation about this then then "In
> generally better"?

Code that uses default properties can *in general* be harder to maintain.
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.

Quote:
> 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.
Quote:
> However, I assume there is a special reason for this for VB6 and so I am
> currious about that.

> Cor



>> Hi Edward,





>>>> 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)



Fri, 12 Aug 2011 17:51:10 GMT  
 Text box number of characters VB6

Quote:

> 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?    ;-)

No, in fact I'd dispute it. It's not only best to avoid default
properties, it's also best to avoid implicit conversions.

  Text2.Text = CStr(Len(Text1.Text))

  (-:

--
   Jim Mack
   Twisted tees at http://www.cafepress.com/2050inc
   "We sew confusion"



Fri, 12 Aug 2011 20:05:50 GMT  
 Text box number of characters VB6



Quote:
> Hi Dave,







>>>> 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.
VB.NET may encourage sloppy programming, but there is no need to spread that
rot here.

Dave O.



Fri, 12 Aug 2011 21:33:54 GMT  
 Text box number of characters VB6


Quote:



>> Hi Dave,







>>>>> 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.

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.

Quote:
> VB.NET may encourage sloppy programming, but there is no need to spread
> that rot here.

ROFL !  First, .NET was mentioned in regard to this, but now you mention it,
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 :)


Fri, 12 Aug 2011 21:52:34 GMT  
 
 [ 18 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Counting number of characters in a text box

2. Column (character) numbers in Rich Text Box

3. Input and display of Vietnamese Characters using text box and label in VB6

4. Text from vba text box (>2000 characters) to a Word bookmard

5. Allowing ONLY text to be typed in my text box - NO NUMBERS

6. Allowing ONLY text to be typed in my text box - NO NUMBERS

7. Line break character for text box

8. Hidden character for password text box

9. Characters in text boxes

10. Userform Text Box limited to 256 characters

11. Character Position in Text Box

12. I need to grab the last 6 Characters in a text box

 

 
Powered by phpBB® Forum Software