当前所在位置:珠峰网资讯 >> 计算机 >> IT教育 >> 正文
计算机二级考试VB常用算法:排序
发布时间:2007/12/15 10:28:53 来源:xue.net 编辑:城市学习网
、实战练习         补充代码(2002春二(9))
         C盘根目录下stu.txt文件中以下的格式保存着学生姓名及班号信息。本程序的功能是:读取该文件中的数据,再利用InputvBox输入要查找的学生姓名,通过顺序查找,给出找到或找不到的信息。附图是某同学被找到时显示的信息窗口。
        张文,机械01
        李明,机械01
        王文卉,机械01
        …
        何宇宙,电子02    
 
    
                  Option Explicit
                  Option Base 1
                  Private Sub Form_click()
                           Dim stu() As String, glass() As String, i As Integer
                           Dim n As Integer, name As String, k As Integer
                           Open "c:\stu\stu.txt" For Input As #11
                           Do While (1)
                                    (2)
                                    ReDim Preserve stu(n), glass(n)
                                    Input #11, stu(n), glass(n)
                           Loop
                           name = InputBox("输入欲查找的学生姓名:")
                           Call search(name, stu, k)
                           If k <= n Then
                                    MsgBox (3)
                           Else
                                    MsgBox "无此人。"
                           End If
                           Close #11
                  End Sub
                  Private Sub search(name As String, stu() As String, k As Integer)
                           Dim i As Integer
                           For i = 1 To UBound(stu)
                                    If name = stu(i) Then
                                             (4)
                                    End If
                           Next i
                           (5)
                  End Sub
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved