PDA

Click to See Complete Forum and Search --> : Text Conversion - Help!!


AP
Jan 17th, 2000, 06:53 PM
I am fairly new with VB and am having problems converting certain parts of text to upper and lower case. As I enter text into a text box I need it to convert the vowels only to upper case and everything else to stay as lower. I also need to store this in a sequential file and then clear the box ready for the next line!! Can anyone help with this?? Please!!!

smalig
Jan 17th, 2000, 06:59 PM
Use the UCase() and LCase() functions.

string = UCase(string) ' Returns a uppercase.
string = LCase(string) ' Returns a lowercase.

------------------
smalig
smalig@hotmail.com
http://vbcode.webhostme.com/

AP
Jan 17th, 2000, 08:30 PM
So how do I then specify specific characters to change to Uppercase once I have converted all of them to lower? Can I use the Ascii values? If so, how do I specify these??

Thanks,

AP

Jan 17th, 2000, 09:25 PM
May not be the fastest way but this code works:

Private Sub Convert()
Text1.Text = LCase(Text1.Text)
Do
x = InStr(1, Text1.Text, "a", vbBinaryCompare)
If x > 1 Then Text1.Text = Mid(Text1.Text, 1, x - 1) & "A" & Mid(Text1.Text, x + 1, Len(Text1.Text) - x)
If x = 1 Then Text1.Text = "A" & Mid(Text1.Text, 2, Len(Text1.Text) - 1)
Loop Until x = 0
Do
x = InStr(1, Text1.Text, "e", vbBinaryCompare)
If x > 1 Then Text1.Text = Mid(Text1.Text, 1, x - 1) & "E" & Mid(Text1.Text, x + 1, Len(Text1.Text) - x)
If x = 1 Then Text1.Text = "E" & Mid(Text1.Text, 2, Len(Text1.Text) - 1)
Loop Until x = 0
Do
x = InStr(1, Text1.Text, "i", vbBinaryCompare)
If x > 0 And x <> 1 Then Text1.Text = Mid(Text1.Text, 1, x - 1) & "I" & Mid(Text1.Text, x + 1, Len(Text1.Text) - x)
If x = 1 Then Text1.Text = "I" & Mid(Text1.Text, 2, Len(Text1.Text) - 1)
Loop Until x = 0
Do
x = InStr(1, Text1.Text, "o", vbBinaryCompare)
If x > 1 Then Text1.Text = Mid(Text1.Text, 1, x - 1) & "O" & Mid(Text1.Text, x + 1, Len(Text1.Text) - x)
If x = 1 Then Text1.Text = "O" & Mid(Text1.Text, 2, Len(Text1.Text) - 1)
Loop Until x = 0
Do
x = InStr(1, Text1.Text, "u", vbBinaryCompare)
If x > 1 Then Text1.Text = Mid(Text1.Text, 1, x - 1) & "U" & Mid(Text1.Text, x + 1, Len(Text1.Text) - x)
If x = 1 Then Text1.Text = "U" & Mid(Text1.Text, 2, Len(Text1.Text) - 1)
Loop Until x = 0

End Sub



------------------
Boothman
There is a war out there and it is about who controls the information, it's all about the information.

Joacim Andersson
Jan 17th, 2000, 09:51 PM
Or use the KeyPress event:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case LCase(Chr$(KeyAscii))
Case "a","e","o","i","u","y"
KeyAscii = Asc(UCase(Chr$(KeyAscii)))
Case Else
KeyAscii = Asc(LCase(Chr$(KeyAscii)))
End Select

Good luck!

------------------
Joacim Andersson
joacim@programmer.net
joacim@yellowblazer.com
www.YellowBlazer.com (http://www.YellowBlazer.com)