Inside a computer, all characters are stored as numbers. Each programming language supports a particular set that defines valid values for characters in that language. Visual Basic uses the ASCII character set. Characters in the ASCII set contain all letters and symbols on the keyboard + other special characters.
Note:
Examples |
|
fname = “Jon ” lname = “Jonsson” fullname = fname & lname The value of fullname is “Jon Jonsson” |
fname = “Annie” lname = “Buddy” lblanswer.caption = lname & “,” & fname The value of lblanswer.caption would be Buddy,Annie |
txtname.text = “Jules” & vbCrLf & “Jurgensson” The textbox would show: Jules Jurgensson |
The following prompts the user for their name using an inputbox: If
the user does not enter a name and clicks o.k. or cancel, the value of
fname will be null – an empty string! fname = InputBox("Please enter your name:", "Login") |
|
Examples,
|
|
Examples,
|
You can combine the Len function with two new properties of text boxes and the text portion of a combo box - the SelStart and SelLength properties. The SelStart property sets or returns the position of the first selected character; the SelLength property sets or returns the number of selected characters. You can make the current contents of a text box or the Text property of a combo box appear selected when the user tabs into the control and receives its focus.
Private Sub txtName_GotFocus(
)
' Select the current entry
With txtName
.SelStart =
0
' begin selection at start
.SelLength =
Len (txtName.Text) '
Select the number of characters
End With
End Sub
When a list box has a very large number of entries, you can help the user by selecting the matching entry as he types in a text box. For example, when you type p the list quickly scrolls and displays words beginning with p. Then if you type r, the list scrolls down to the words that start with pr.
Private Sub txtCoffee_Change(
)
' Locate first matching occurence in the
list
Dim iIndex as Integer
Dim
bFound as Boolean
Do while Not bFound and iIndex < 1stCoffee.ListCount
If Ucase
(Left (1stCoffee.List(iIndex), Len (txtCoffee.Text))) = UCase (txtCoffee.Text)
Then
1stCoffee.ListIndex = iIndex
bFound = True
End If
iIndex =
iIndex + 1
Loop
End Sub