Tutorials2u.com

Tutorials on various topics

converting a string to uppercase or lowercase using the API

converting a string to uppercase or lowercase using the API

Start up Visual Basic as usual and enter the code below in the general declarations section of the form.

Option Explicit

Private Declare Function CharLower Lib “user32″ Alias “CharLowerA” (ByVal lpsz As String) As Long
Private Declare Function CharUpper Lib “user32″ Alias “CharUpperA” (ByVal lpsz As String) As Long

Now enter the following in the Form_Load event procedure

Private Sub Form_Load()
Dim strTest As String
Me.AutoRedraw = True
‘test string
strTest = “This is a test string Which is Mixed Case”
Me.Print strTest
‘Convert all the characters to uppercase
CharUpper strTest
Me.Print strTest
‘Convert all the characters to lowercase
CharLower strTest
Me.Print strTest
End Sub

Now run the program (Press F5) and all going well you should see the date and time of your system. Here is what was displayed
on the test system.

Analysis

This uses the CharUpper and CharLower API commands which take a pointer to astring, the string will be hardcoded in and then
converted.

This could be useful for ensuring that a user used only lowercase when entering a username / password combo in an app.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Sponsors


Links