The email I get…

Every day I get from 1 to 10 emails asking me various VB questions… some I answer by pointing to a link, some by providing code, and sometimes I just point people to the newsgroups or forums that exist for this type of question… but this time I thought I’d just post the question and answer into my blog …

The Question (edited slightly):

I just want to ask how to make the string in to proper format..
ex…
input.
gerald

this must be the output:
Gerald

and i want it to interactively change when i’m inputing a string in a textbox..

And the answer is to put this code into the TextChanged event of your textbox;

Dim ci As Globalization.CultureInfo = _
    System.Threading.Thread.CurrentThread.CurrentCulture

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim pos As Integer = TextBox1.SelectionStart
TextBox1.Text = ci.TextInfo.ToTitleCase(TextBox1.Text)
If pos > 0 AndAlso pos <= TextBox1.Text.Length Then
TextBox1.SelectionStart = pos
End If
End Sub

The key is that the CultureInfo class provides a TextInfo instance, which in turn has a method of “ToTitleCase” on it… This KB article provides more info and also shows an alternate method to achieve the same results (StrConv()).

The email I get…

9 Responses

  1. Hi.

    How do i make a form sizable for any monitor resolution (dpi) because i develop in a monitor whith 1280 x 1024 pixels but in other lower resolution my forms don’t fit.
    could you help me?

    Ernesto August 26, 2004 at 3:21 am #
  2. This is a pretty cool little code snippet, but is it possible that this would be slow during data entry? It seemed to be very fast when I tested it, but going out to the _TextChanged event every time a key is pressed just seems to me kind of redundant. Anyways, just wondering if I should be worried about the speed at all.

    Thanks!

    Essential

    Essential August 26, 2004 at 6:30 am #
  3. How can i change the background and Fore color of Status bar in VB 6.0

    Harsh Kumar Garg August 26, 2004 at 2:56 pm #
  4. hi………..
    u’r really smart…
    can u give a code that function as changing image everytime i click a command button….

    thanksssssss…..

    gerald August 27, 2004 at 9:15 am #
  5. I have a simple question. Is there a known problem with the DataReport1.PrintReport? It seems to hang my computer everytime I run it. I have place my application on other systems and on some of them it seems to work just fine, but when I check the task manager, even when I exit the application my program is still listed there. I have close and set to nothing all the objects that I use and unload all forms. Any ideas???

    Hilda J. Espinoza August 27, 2004 at 10:03 pm #
  6. Hi Techies,

    Have an Query.

    Please let me know If any one have a solution for this.
    I have a Project which consists of 10 forms and 3 data reports and Access Database.
    I created an exe and tried to run it on a WIN XP system. It executes fine but when I try to access the Data Report. It gives me an error and the Program terminate. That might be because the required ocx &amp; dll files may be missing.
    One of the solution is to create an setup of the project. But I want to use just the exe.
    Please could any body suggest how should I proceed with this. What are the required file, and where should they be stored. Just wanted to run the exe and also the data reports within it.
    Some please tell me how can it be done.

    Thanks and Regards
    Prashant

    Prashant Thorat August 27, 2004 at 11:33 pm #
  7. How can I write vb.net code to insert data into an access db table if the data
    is new, and yet just ignore it if it already exists in the table?
    Do I use a Try,Catch,Finally block? What would I check to catch the duplicates
    and ignore them?
    Any help would be appreciated.

    susan August 28, 2004 at 12:24 am #
  8. Low…. peps…….

    i need help………
    someone please tell on how to code a image that when i click a command button the will automatically change……. the name of the command button is NEXT……
    tnxs………

    gerald Stun August 30, 2004 at 5:02 am #
  9. Hi Techies,

    Have an Query.

    Please let me know If any one have a solution for this.
    I have a Project which consists of 10 forms and 3 data reports and Access Database.
    I created an exe and tried to run it on a WIN XP system. It executes fine but when I try to access the Data Report. It gives me an error and the Program terminate. That might be because the required ocx

    rahul March 13, 2007 at 4:11 pm #

Leave a Reply