![](https://lstatic.shangxueba.com/sxbzda/h5/images/m_q_title.png)
(10 ) 有如图所示的窗体 。 程序执行时先在 Text1 文本框中输入编号 , 当焦点试图离开 Text1 时
合法编号的组成是:前 2 个字符是大写英文
字母,第 3 个字符是 “ - ” ,后面是数字字符
(至少 1 个)。下面程序可实现此功能,请
填空。
Private Sub Text1_Lostfocus()
Dim k%,n%
n=Len([13] )
For k=1 to if (n>3,n,4)
c=Mid(Text1. Text,k,1)
Select Case k
Case 1,2
If c<"A" Or c>"Z" Then
MsgBox(" 第 "&k&" 个字符必须是大写字母! ")
SetPosition k
Exit For
End If
Case 3
If c<>"-" Then
MsgBox(" 第 "&k&" 个字符必须是字符 "'"-"'")
SetPosition k
Exit For
End If
Case Else
If c<"0" Or c>"9" Then
MsgBox(" 第 "&k&" 个字符必须是数字! ")
SetPosition k
Exit For
End If
End Select
Next k
End Sub
Private Sub SetPosition(pos As Integer)
Text1.SelStart=pos-1
Text.SelLength= [14]
Text1. [15]
End Sub
![](https://lstatic.shangxueba.com/sxbzda/h5/images/tips_org.png)