第一题:在Change事件中进行判断,主要条件是9位学号,前2位年级,第5位类型
Private Sub Text1_Change()
If Len(Text1.Text) = 9 Then '等于9位才进行判断
Select Case Left(Trim(Text1.Text), 2)'取前2位判断年级
Case "01"
Text2.Text = "一年级" '01,02,03代表年级
Case "02"
Text2.Text = "二年级"
Case "03"
Text2.Text = "三年级"
Case Else
Text2.Text = ""
Text3.Text = "" '超出范围即无效学号,清空显示
End Select
Select Case Mid(Trim(Text1.Text), 5, 1)取第5位判断类型
Case "2"
Text3.Text = "博士" '2-博士,3-硕士,4-本科,5-专科
Case "3"
Text3.Text = "硕士"
Case "4"
Text3.Text = "本科"
Case "5"
Text3.Text = "专科"
Case Else
Text2.Text = ""
Text3.Text = "" '超出范围即无效学号,清空显示
End Select
Else
Text2.Text = ""
Text3.Text = ""
End If
End Sub
第二题:主要条件是即时转换,对写入及删除产生一个即时效果,大小写及非字字母转换,所以在Change中判断,用ASC、Chrw检测及转换。
Private Sub Text4_Change()
Text5.Text = "" '清空显示框
For i = 1 To Len(Text4.Text)'取每一位字符
Select Case Asc(Mid(Text4.Text, i, 1))'对每一位字符判断
Case 65 To 90 '大写字母
Text5.Text = Text5.Text & ChrW(Asc(Mid(Text4.Text, i, 1)) + 32)'转小写
Case 92 To 122 '小写字母
Text5.Text = Text5.Text & ChrW(Asc(Mid(Text4.Text, i, 1)) - 32)'转大写
Case Else
Text5.Text = Text5.Text & "*"'转星号
End Select
Next
End Sub
第三题:由于用复选框作选择,复选框的值为0或1,数值型,问题条件只是0或255固定值,所以直接乘255就可以满足条件。(建议使用三个滑块,效果更好)
在3个复选框的Click事件中写
Private Sub Check1_Click()
Form1.BackColor = RGB(Check1.Value * 255, Check2.Value * 255, Check3.Value * 255)
End Sub
Private Sub Check2_Click()
Form1.BackColor = RGB(Check1.Value * 255, Check2.Value * 255, Check3.Value * 255)
End Sub
Private Sub Check3_Click()
Form1.BackColor = RGB(Check1.Value * 255, Check2.Value * 255, Check3.Value * 255)
End Sub
1.
sub do(numberx as integer)
text2="年级:" & left(numberx,2) & vbcrlf
select case mid(numberx,5,1)
case 2
x="博士"
case 3
x="硕士"
case 4
x="本科"
case 5
x="专科"
end select
text2=text2 & "学生类型:" & x
end sub
2.
Private Sub Text1_KeyPress(KeyAscii As Integer)
if KeyAscii>97 And KeyAscii<122 Then
text2=text2 & chrw(KeyAscii-32)
elseif KeyAscii>65 And KeyAscii<90 Then
text2=text2 & chrw(KeyAscii+32)
endif
End Sub
3.
创建3个check空间命名为red1、green1、blue1
public red,green,blue as integer
Private Sub Red1_Click()
if red1.value=1 then
red=255
else
red=0
label1.BackColor=RGB(red,green,blue)
End Sub
Private Sub blue1_Click()
if blue1.value=1 then
blue=255
else
blue=0
label1.BackColor=RGB(red,green,blue)
End Sub
Private Sub green1_Click()
if green1.value=1 then
green=255
else
green=0
label1.BackColor=RGB(red,green,blue)
End Sub
1.已知学号由9位数组成,如:032343001,其中前2位表示年级,第5位表示学生类型(类型规定如下:2-博士,3-硕士,4-本科,5-专科)。设计程序,从文本框输入学号,在另外两个文本框中显示该生年级及学生类型。
Dim XW As String
Select Case Mid(Text1.Text, 5, 1)
Case 2
XW = "博士"
Case 3
XW = "硕士"
Case 4
XW = "本科"
Case 5
XW = "专科"
End Select
Print Left(Text1.Text, 2) & "年级," & XW & "学位"
2.设计对输入字符进行转换的程序。要求在文本框中每输入一个字符就进行判断和转换,转换结果显示在另一文本框中。(转换规则为:将其中小写字母转换为大写,大写字母转换为小写,其余非字母字符转换为“*”)。
'A-Z: 65-90
'a-z: 97-122
'*: 42
Text2.Text = ""
Dim N As Integer
For N = 1 To Len(Text1.Text)
If Asc(Right(Left(Text1.Text, N), 1)) >= 65 And Asc(Right(Left(Text1.Text, N), 1)) <= 90 Then
Text2.Text = Text2.Text & Chr(Asc(Right(Left(Text1.Text, N), 1)) + 32)
Else
If Asc(Right(Left(Text1.Text, N), 1)) >= 97 And Asc(Right(Left(Text1.Text, N), 1)) <= 122 Then
Text2.Text = Text2.Text & Chr(Asc(Right(Left(Text1.Text, N), 1)) - 32)
Else
Text2.Text = Text2.Text & "*"
End If
End If
Next N
3.设计程序,利用3个复选框代表红、绿、蓝三颜色值,当选中复选框时表示颜色值为255,不选中为0,把通过RGB函数调配的颜色作为一个标签的背景色。
Dim R, G, B As Integer
If Check1.Value = 1 Then R = 255
If Check2.Value = 1 Then G = 255
If Check3.Value = 1 Then B = 255
Label1.BackColor = RGB(R, G, B)