954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Upper case, lower case in vb.net

Hello i want to the textbox that when I start to type in names it should be like this

Camille Aisha Cordova
How do I do this?

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

Try this,
I'm pretty sure this is how you convert the first letter in each work to upper case.
or you can try useing toupper.

Dim text1 As String = "camille aisha cordova"
Dim text2 As String = StrConv(Text1, VbStrConv.ProperCase)
textbox.text = text2
bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 

There is a vb string method you can use when you are done with the textbox

Private Sub txtName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.Leave

    Dim str As String = StrConv(txtName.Text, VbStrConv.ProperCase)
    txtName.Text = str

  End Sub

If you want it to Capitolize your string as you type in the textbox you need to Handle the Keypress,KeyUp events of the textbox.

Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
 

same thing

bluehangook629
Posting Whiz in Training
204 posts since Dec 2009
Reputation Points: 11
Solved Threads: 14
 

And your point is? Or are you telling me while I was posting to you someone else got there before me? If that is the case; Sorry about that, and have a nice day!

Phasma
Junior Poster in Training
81 posts since Nov 2008
Reputation Points: 21
Solved Threads: 21
 

can anyone help me. i decided that i'll just let the user type however way the user wants. just that when the data saves it should be in Sentence Case regardless of how the user typed it.

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

Dim str As String = StrConv(txtName.Text, VbStrConv.ProperCase)
txtName.Text = str

Use this while saving ur data as mentioned by Phasma... Whats the problem in it?

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

thank you now it's working, i don't know what happened when i tried it first.
another question, i have too many textboxes to do the sentence, not just only one. what do i do?

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

Create a function:

Private Function FormatString(Byval txt as string) as String
   Return StrConv(txt, VbStrConv.ProperCase)
End Function


And on saving the data you do for each string you need to format:
Instead of txtName.Text you use FormatString(txtName.Text)

I wouldn't do it on every keypress or leaving the control.

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

how do i call it?
Call FormatString(txt:=Text1.Text)?

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

oh i didn't see FormatString(txtName.Text)
sorry sorry :3

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

this is for FormatString(txtsurname.Text) one textbox only,
what if i want to use it in multiple textboxes?

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

That is depends on your layout. If you have those textboxes in a groupbox, you could loop the groupbox for all textboxes. Else you have to loop the form and its containers.

Also it is depends on the amount of textboxes you need to format if its worth doingthe loop.

How do you save your stuff? Any code?

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 
strsql = "insert into student_info(Surname, First_Name, Middle_Name, Home_Address, Religion, Tel_No, Name_incase_Emergency, Address_emergency, Tel_No_Emergency, Grade_yearlevel, Place_of_Birth, SchoolLastAttended, Address_School, School_Year, Father_Name, Father_EducAttain, Occupation, EmployedAt, Address_employment,Father_TelNum_Work, Mother_Name, Mother_EducAttain, Occupation_Mother, EmployedAt_Mother, AddEmp_Mother, Mother_TelNum_Work,Birth_Date, Citizenship, General_ave,Gender,Requirements_NSO,Requirements_GoodMoral,Requirements_ReportCard) values ('" & txtsurname.Text & "', '" & txtfirstname.Text & "', '" & txtmiddlename.Text & "', '" & txtaddress.Text & "', '" & txtreligion.Text & "', '" & txtcontactnum.Text & "', '" & txtnameemergency.Text & "', '" & txtaddemergency.Text & "','" & txtcontactemergency.Text & "', '" & gradeyear.Text & "', '" & txtplacebirth.Text & "', '" & txtschoolname.Text & "', '" & txtschooladd.Text & "', '" & txtschoolyear.Text & "', '" & txtfathername.Text & "', '" & txtfathereduattain.Text & "', '" & txtfatheroccupation.Text & "', '" & txtfatheremployedat.Text & "', '" & txtfatheraddemp.Text & "', '" & txtfathertelnum.Text & "', '" & txtmothername.Text & "', '" & txtmothereduattain.Text & "', '" & txtmotheroccupation.Text & "', '" & txtmotheremployedat.Text & "', '" & txtmotheraddemp.Text & "', '" & txtmothertelnum.Text & "', '" & datebirth.Text & "', '" & txtcitizenship.Text & "', '" & txtgenaverage.Text & "', '" & txtgender.Text & "', '" & requirements_nso.Text & "', '" & requirements_goodmoral.Text & "', '" & requirements_reportcard.Text & "')"

        Dim sqlcmd As New SqlClient.SqlCommand
        sqlcmd.CommandText = strsql
        sqlcmd.Connection = sqlconn
        sqlcmd.ExecuteNonQuery()


this is how i save my data, i have way too many textboxes.

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

ok...
Add the following code to your form class:

Private Sub RecurseContainers(container As Control)
		For Each ctrl In container.Controls
			If TypeOf (ctrl) Is TextBox Then
				ConvertText(CType(ctrl, TextBox))
				Continue For
			End If
			If TypeOf (ctrl) Is Control Then 'panel, groupBox or any other container
				RecurseContainers(CType(ctrl, Control))
			End If
		Next
	End Sub

	Private Sub ConvertText(txt As TextBox)
		txt.Text = FormatString(txt.Text)
	End Sub

	Private Function FormatString(ByVal txt As String) As String
		Return StrConv(txt, VbStrConv.ProperCase)
	End Function


Now add the following line just before you do your "strsql = "insert...." stuff

RecurseContainers(Me)


This will transform all your textboxes.

GeekByChoiCe
Master Poster
721 posts since Jun 2009
Reputation Points: 208
Solved Threads: 168
 

YES! It works! THANK YOU SO MUCH! :D

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

I know that I marked this as SOLVED, but I just have a tiny question,
how come this code won't allow me to select all the textbox i just type by using Ctrl + A, or Ctrl + C, or Ctrl + V

If (Microsoft.VisualBasic.Asc(e.KeyChar) < 65) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 90) And (Microsoft.VisualBasic.Asc(e.KeyChar) < 97) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 122) Then
'Allowed space and backspace
If (Microsoft.VisualBasic.Asc(e.KeyChar) <> 32) And e.KeyChar <> ControlChars.Back Then
e.Handled = True
MsgBox("Numbers and special characters is not allowed. Please enter letters")
End If
End If

aishapot
Junior Poster in Training
75 posts since Sep 2011
Reputation Points: 7
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: