Cesar Francisco

I have three TextBoxes where the first letter has to be always Uppercase (First Name, Last

Name and Gender)

Code Snippet

Private Sub txtboxFirstName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles

txtboxFirstName.Leave

Dim myText As String = StrConv(txtboxFirstName.Text, VbStrConv.ProperCase)

txtboxFirstName.Text = myText

End Sub

Is there a way to simplify and not write this code three times, beside of extending the TextBox Class




Re: Visual Basic Express Edition Simplify First Letter Uppercase

JohnWein

Does anyone else have as much time on their hands as you and I

Code Snippet

Private Sub TextBox1_Leave(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles TextBox1.Leave, _

TextBox2.Leave, TextBox3.Leave

sender.Text = StrConv(sender.Text, VbStrConv.ProperCase)

End Sub





Re: Visual Basic Express Edition Simplify First Letter Uppercase

Cesar Francisco

Thanks, it worked as advertised.

Sender is a nice guy.

I am surprised that I am not the only one squandering it.






Re: Visual Basic Express Edition Simplify First Letter Uppercase

Solitaire

sender only works with Option Strict Off.

Option Strict On disallows late binding.






Re: Visual Basic Express Edition Simplify First Letter Uppercase

Cesar Francisco

Right. Still, it was a valiant effort. Back to the Past.




Re: Visual Basic Express Edition Simplify First Letter Uppercase

JohnWein

You can set Option Strict to your preferences in Project.Properties. The purpose of VB is to minimize the time from concept to working application. Write the program and then address the problem areas. Many VB6 programs were written declaring all variables as variants.



Re: Visual Basic Express Edition Simplify First Letter Uppercase

Solitaire

This will work with Option Strict On:

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave

TextBox1.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)

End Sub






Re: Visual Basic Express Edition Simplify First Letter Uppercase

JohnWein

What's with your hang-up with Option Strict set up to generate an error for late binding Set it to generate a warning. Option Strict is a tool to assist the programmer. There is no chance of a runtime error in the late binding of Textboxes in this context.



Re: Visual Basic Express Edition Simplify First Letter Uppercase

Cesar Francisco

My wish was to simplify and concentrate the code in one block.

Taking something from both of you, I do thank both of you.

Who can arbitrate in this matter Not me.

Code Snippet

Private Sub txtbox_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

txtbLastN.Leave, txtbFirstN.Leave, txtbGen.Leave

txtbFirstN.Text = StrConv(txtbFirstN.Text, VbStrConv.ProperCase)

txtbLastN.Text = StrConv(txtbLastN.Text, VbStrConv.ProperCase)

txtbGen.Text = StrConv(txtbGen.Text, VbStrConv.ProperCase)

End Sub

Solitaire: Salute and merci to a great and careful programmer

John: it is awfully nice to meet a legendary VB6-er. I gather, it was the time of great skill and drudgery.

(Some of the features I am trying to implement are those of a commercial VB6/Jet application).

In view of your extensive VB6 experience I would like you to look at one of my other post. Please.






Re: Visual Basic Express Edition Simplify First Letter Uppercase

Solitaire

John Wein said:

>What's with your hang-up with Option Strict set up to generate an error for late binding Set it to generate a warning. Option Strict is a tool to assist the programmer. There is no chance of a runtime error in the late binding of Textboxes in this context. <

Yes there is. I tried your code using "sender" before my previous post and it generates Build errors -- IT WON'T RUN!!!

I teach programming and have all my students configure the IDE so Option Strict is On at the beginning of my course. Most companies have that in place as a requirement (and I heard they might even fire a programmer who doesn't have it on). It prevents a lot of errors that might otherwise occur, making debugging very difficult if not adhered to.







Re: Visual Basic Express Edition Simplify First Letter Uppercase

JohnWein

You are right, if you have your IDE setup to generate errors for late binding it won't run. I guess I think of Visual Basic in all its flavors as a tool to rapidly demonstate a concept rather than a programming tool. As I said at the start of this thread, I have a lot of time on my hands and the other participants must also. Servicing the events individually for each TextBox takes no thought and is as good any other method that someone is likely to come up with. If you have time to think about simplifying this task you don't have much to do.

Edit: See if this will run on your computer

Code Snippet

Option Strict On

Public Class Form1

Private Sub TextBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Leave, TextBox2.Leave, TextBox3.Leave

Dim TB As TextBox = CType(sender, TextBox)

TB.Text = StrConv(TB.Text, VbStrConv.ProperCase)

End Sub





Re: Visual Basic Express Edition Simplify First Letter Uppercase

Solitaire

Yes, that one works.

You seem to be hung up on the amount of time people have to spend answering forum questions. I happen to be a retired schoolteacher, currently teaching programming part-time on the college level. I enjoy both teaching and learning, and have picked up a lot of valuable information on these forums, which I am happy to share with others.