99账号:帮我VB两道题

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 08:36:37
1把字符作如下分类:大写字母:A-Z、小写字母:a-x、数字:0-9、其它字符。根据此分类方法,从键盘输入一个字符,输出该字符类型。
5.已知s=2+4+6+...+n,试找出一个最大整数n,使s<25000

Private Sub Command5_Click()
'已知s=2+4+6+...+n,试找出一个最大整数n,使s<25000

Dim i As Integer
Dim s As Integer

i = 1
Do While s < 2500
s = s + i * 2
i = i + 1
Loop

MsgBox s
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
'需要添加一个Label1

If Chr(KeyAscii) >= 0 And Chr(KeyAscii) <= 9 Then
Label1.Caption = "0-9"
ElseIf KeyAscii >= Asc("a") And KeyAscii <= Asc("x") Then
Label1.Caption = "a-x"
ElseIf KeyAscii >= Asc("A") And KeyAscii <= Asc("Z") Then
Label1.Caption = "A-Z"
Else
Label1.Caption = ""
End If

End Sub

我之前在http://zhidao.baidu.com/question/2450595.html 下面的评论里面回答过啦!!

找学的好的同学帮你吧

我可以给你一个大体模式:
if A—Z,then
字符型
if 0—9,then
数值型
……
依次类推!

1:文本框(或者其它什么能响应的也行)的KeyPress事件,返回一个KeyAscii码;
65-90是A-Z
97-122是a-z
48-57是0-9
比如:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57:
Print "数字"
Case 65 To 90:
Print "大写字母"
Case 97 To 122:
Print "小写字母"
Case Else:
Print "其它字符"
End Select
End Sub

2:写到别的事件也可以
Private Sub Form_Load()
i = 2
s = 0
While s < 25000
s = s + i
i = i + 2
Wend
Print "最大的n:"; i - 2
Print "此时的s:"; s - i - 2
End Sub

我给出上面两个问题的算法,如何输出就随你了~ ^_^