Sunday, April 20, 2014

Visual Basic Tutorial : How to Use vbStrConv to Convert Text into Upper, Proper and Lower Case

Hi folks.. welcome to another exiting visual basic tutorial.. today we are going to convert text in textbox into Upper, Lower and Proper case using this common code in visual basic..

First we will discuss what is the vbStrConv : credits to msdn.microsoft.com

The Conversion argument settings are:
Enumeration member
Description
VbStrConv.None
Performs no conversion
VbStrConv.LinguisticCasing
Uses linguistic rules for casing, rather than File System (default). Valid with VbStrConv.UpperCase and VbStrConv.LowerCase only.
VbStrConv.UpperCase
Converts the string to uppercase characters.
VbStrConv.LowerCase
Converts the string to lowercase characters.
VbStrConv.ProperCase
Converts the first letter of every word in string to uppercase.
VbStrConv.Wide*
Converts narrow (half-width) characters in the string to wide (full-width) characters.
VbStrConv.Narrow*
Converts wide (full-width) characters in the string to narrow (half-width) characters.
VbStrConv.Katakana**
Converts Hiragana characters in the string to Katakana characters.
VbStrConv.Hiragana**
Converts Katakana characters in the string to Hiragana characters.
VbStrConv.SimplifiedChinese*
Converts Traditional Chinese characters to Simplified Chinese.
VbStrConv.TraditionalChinese*
Converts Simplified Chinese characters to Traditional Chinese.

The syntax is:

TextBox2.Text = StrConv(TextBox1.Text, VbStrConv."desired case")

Further Explanation:

Textbox2 is the display result..
Textbox1 is the input text field...

Program Logic:

Every text typed into the textbox1 will be converted into the selected case and the converted result will display into the Textbox2.

Controls you need for this program:

2 Textbox (textbox1 = input) and (textbox2 = output)

3 RadioButton (Rename into the following:
  Radio1 = Convert to UPPER
  Radio2 = Convert to Proper
  Radio3 = Convert to lower

1 Button

Now we will use this code to button1 click event.. this code contains multi-line if statement syntax.

The conversion Code:

        If RadioButton1.Checked Then
            TextBox2.Text = StrConv(TextBox1.Text, VbStrConv.Uppercase)

        ElseIf RadioButton2.Checked Then
            TextBox2.Text = StrConv(TextBox1.Text, VbStrConv.ProperCase)

        ElseIf RadioButton3.Checked Then
            TextBox2.Text = StrConv(TextBox1.Text, VbStrConv.Lowercase)

        End If

Note: the following code must be inserted into the Private Sub Button1_Click.. 

I uploaded a video tutorial on how you can do this..

Watch Tutorial




No comments:

Post a Comment