Create Initial Word into a Capitalized Letters In Visual Basic 6.0

for this post we will discuss a function that can change every initial letter on a word into uppercase or capslock.

Open a new project (Standard.Exe), in Form1 add a textbox and set the Height and Width property of a rather large size make sure your Multiline property is set to True, so that its textbox can be widened down, and let the Name property match its default name .



Now let's move to editor mode, click View -> Code, and enter the following code :

Public Function AwalKataKapital(strKalimat As String)
Dim i As Integer
Dim Temp As String
Dim Lokasi As Integer
Dim huruf As String * 1
  Temp$ = ""
  For i% = 1 To Len(strKalimat)
    huruf = Chr(Asc(Mid(strKalimat, i%, 1)))
    If Len(Trim(huruf)) < 1 Then
      Lokasi% = i% + 1
    End If
    If i% = Lokasi% Or i% = 1 Then
       Temp$ = Temp$ + UCase(Chr(Asc(Mid(strKalimat, _
               i%, 1))))
    Else
       Temp$ = Temp$ + LCase(Chr(Asc(Mid(strKalimat, _
                i%, 1))))
    End If
  Next i
  AwalKataKapital = Temp$
End Function
Private Sub Text1_Change()
  Dim posisi As Integer
  posisi = Text1.SelStart
  Text1.Text = AwalKataKapital(Text1.Text)
  Text1.SelStart = posisi
End Sub

Press F5 to run the project, you try to type some words in the textbox we have provided, then every letter of the beginning of the word will automatically turn into capital letters.

Good luck.

Share this

Related Posts

Previous
Next Post »

3 comments

comments