Showing posts with label Using Event Keypress and Case Function. Show all posts
Showing posts with label Using Event Keypress and Case Function. Show all posts

Wednesday, August 1, 2012

Sample Program #9


Let us create a program that will capitalize every first letter of the word and lowering the case of the remaining letters after pressing the [ENTER] button. Here is the code:

Private Sub txtw_keypress(KeyAscii As Integer)
Dim size, pos As Integer
  If KeyAscii = 13 Then
    txtw.SelStart = 0
    txtw.SelLength = 1
    txtc.Text = UCase(txtw.SelText)
    size = Len(txtw.Text) - 1
    pos = 1
 
    Do While pos <= size
      txtw.SelStart = pos
      txtw.SelLength = 1
      If txtw.SelText = " " Then
        pos = pos + 1
        txtw.SelStart = pos
        txtw.SelLength = 1
        txtc.Text = txtc.Text + " " + UCase(txtw.SelText)
      Else
        txtc.Text = txtc.Text + LCase(txtw.SelText)
      End If
      pos = pos + 1
    Loop
    txtw.SelStart = Len(txtw.Text)
  End If
End Sub