Friday, July 13, 2012

Sample Program #6















Let us create a program that will get the first and last letter of an entered string combining the selstart, sellength, seltext and len() function.



'LONG METHOD STYLE CODE
Private Sub cmdfind_Click()
  Dim a As Integer
 
  txta.SelStart = 0
  txta.SelLength = 1
  txtb.Text = "The first letter is " + UCase(txta.SelText)
 
  a = Len(txta.Text) - 1
  txta.SelStart = a
  txta.SelLength = 1
  txtb.Text = txtb.Text + " and the last letter is " + UCase(txta.SelText)
 
  txta.SelStart = a + 1
End Sub


'SHORT METHOD STYLE CODE
Private Sub cmdfind_Click()
 
  txta.SelStart = 0
  txta.SelLength = 1
  txtb.Text = "The first letter is " + UCase(txta.SelText)
 
  txta.SelStart = Len(txta.Text) - 1
  txta.SelLength = 1
  txtb.Text = txtb.Text + " and the last letter is " + UCase(txta.SelText)
 
  txta.SelStart = Len(txta.Text)
End Sub