试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:容易

算法与程序设计

在VB6中,要使程序启动时自动运行语句form1.caption=″hello″,该语句应被放在下列哪个事件处理过程中(  )
A、form1_load B、form_load C、form_click D、command1_click
举一反三
某校学生会选举需要从学校数据库中随机抽取若干名学生作为监票人。该数据库文件名为school.mdb,其中数据表student存储有关学生学号(xuehao)、姓名(xingming)相关信息,括号内的内容为对应字段名。该程序编辑界面如图所示,相关对象名可参考标识图。

当主持人点击按钮“生成抽号”后,下方的标签会显示可抽取的学号姓名,一定时间后显示被抽取作为监票人的学号姓名。

'xxxss:学校学生数,kcq:可抽取

'xhxm:学号姓名,kcq:可抽取

Dim xxxss As Integer

Dim xhxm(3000) As String

Dim kcq(3000) As Boolean


'cq_Click:启用两个定时器

Private Sub cq_Click()

    cqxhxm.Enabled = True

    xskcqxhxm.Enabled = True

End Sub


Private Sub cz_Click()    '初始化数组kcq,使每个元素数据都处于可显示状态

  For i = 0 To xxxss - 1

    kcq(i) = True           '①

  Next i

End Sub


Private Sub xskcqxhxm_Timer()  '若数组kcq第x个元素处于可抽取状态,则显示数组xhxm第x个元素

    x = Int(Rnd * xxxss)

    If kcq(x) Then xhxmbq.text = kcq(x)     '②

End Sub


Private Sub Form_Load()  '从数据库中提取需要的学号姓名相关数据并初始化数组kcq

    Randomize

    xxxss = 0

    Dim conn As New ADODB.Connection,rs As New ADODB.Recordset

    Dim str_conn as String,str_sql As String

    str_conn = "driver=Microsoft access driver(*.mdb);DBQ="&app.path&"\school.mdb";

    conn.open str_conn

    str_sql = "select * from students"

    rs.open str_sql

    Do While Not rs.eof

      xxxss = xxxss + 1

      xhxm(xxxss) = rs.fields("xuehao")&rs.fields("xingming")

      rs.movenext

    Loop

    For i = 0 To xxxss - 1

      kcq(i) = True

    Next i

End Sub


Private Sub cqxhxm_Timer()    '决定抽取的学号姓名作为监票人

    xskcqxhxm.Enabled = False

    For i = 0 To xxxss - 1

        If xhxmbq.Caption = xhxm(i) Then kcq(i) = False

    Next i

    cqxhxm.Enabled = False

End Sub

①{#blank#}1{#/blank#} 

②{#blank#}2{#/blank#} 

编写VB程序,功能为:单击“发牌”按钮“Command1”后,从一副扑克牌(不包括大王、小王、J、Q、K、A)中随机抽取5张牌,牌的花色(♠♥♣♦)忽略,显示在列表框“List1”中。如果这5张牌由一个对子和一个顺子(3张牌连续)组成,则在标签“Label1”中显示“运气不错:)”,否则显示“运气一般:|”。程序运行界面如图所示。

实现上述功能的VB程序如下:

Private Sub Command1_Click()

  List1.Clear

  Dim five(1 To 5) As Integer

  Dim i As Integer, j As Integer, k As Integer

  Dim p As Integer, find_pair As Boolean

  '随机抽取5张牌,将牌的点数存储在数组five中,并在List1中显示。代码略

  i = 5: p = 1: find_pair = False

  Do While i>= 2

    j=p

    Do While j <= i - 1

      If five(j) > five(j + 1) Then

        t = five(j): five(j) = five(j + 1): five(j + 1) = t

      ElseIf five(j) = five(j + 1) And Not find_pair Then

        t = five(1): five(1) = five(j): five(j) = t

        t = five(2): five(2) = five(j + 1): five(j + 1) = t

        find_pair = True

        i = i + 1

        p = _____________

        Exit Do

      End If

      j = j + 1

    Loop 

    i = i - 1

  Loop

  k = 0

  For i = 3 To 4

    If  Then k = k + 1

  Next i

  If five(1) = five(2) And k = 2 Then

    Label1.Caption = "运气不错:)"

  Else

    Label1.Caption = "运气一般:|"

  End If

End Sub

请回答下列问题:

返回首页

试题篮