一简单的考试系统,采用读取设置好问题、选项、答案的txt文件来读取并判断计算得分,题目及答案选项均用label标签,只不过答案是采用5个label构成数组方便读取,再用4个按钮用来浏览上下题。现在的问题是,上一题、下一题能正常显示,而第一题、最末题不能即时刷新,得在答案选项上点一下才会刷新,请问:点击第一题、最末题按钮如何即时刷新试题及答案标签的内容?相关代码如下:
Sub seltest(Sel As Integer)
    Dim iT As Integer
    Dim iT2 As Integer
    iCurrNum = Sel
    LCurrNum = "当前第" & Sel & "题" '显示当前题号信息
    lText.Caption = strTest(Sel, 0)
    LTextType.Caption = strTestType(intTest(Sel, 1))
    For iT = 1 To intTest(Sel, 2)
        Check1(iT).BackColor = &H8000000F
        Check1(iT).Enabled = True
        Check1(iT).Caption = Chr(64 + iT) + ".  " + strTest(Sel, iT)
    Next
    For iT = intTest(Sel, 2) + 1 To 5
        Check1(iT).BackColor = &H8000000F
        Check1(iT).Enabled = False
        Check1(iT).Caption = ""
    Next
    lAns.Caption = ""
    iT = intTest(Sel, 4)
    For iT2 = 1 To 5: boolTest(iT2) = False: Next
    Do While iT > 0
        iT2 = iT Mod 10
        If iT2 > 0 And iT2 < 6 Then
            boolTest(iT2) = True
            Check1(iT2).BackColor = &H80000018
            lAns.Caption = lAns.Caption + Chr(64 + iT2)
        End If
        iT = iT / 10
    Loop
End SubPrivate Sub Check1_Click(Index As Integer) '在复选框中选择答案
    Dim iT As Integer
    If (intTest(iCurrNum, 1) <> 3) Then
        For iT = 1 To 5: boolTest(iT) = False: Next
        boolTest(Index) = True
    Else
        boolTest(Index) = Not boolTest(Index)
    End If
    intTest(iCurrNum, 4) = 0
    For iT = 1 To 5
        If boolTest(iT) Then intTest(iCurrNum, 4) = intTest(iCurrNum, 4) * 10 + iT
    Next
    seltest (iCurrNum)
End SubPrivate Sub BtnBack_Click() '上一题事件
    If iCurrNum > 1 Then seltest iCurrNum - 1
End SubPrivate Sub BtnBack_KeyPress(keyascii As Integer)
    BtnOk_KeyPress keyascii
End SubPrivate Sub BtnNext_Click() '下一题事件
    If iTests > iCurrNum Then seltest iCurrNum + 1
End SubPrivate Sub BtnNext_KeyPress(keyascii As Integer)
    BtnOk_KeyPress keyascii
End SubPrivate Sub BtnFirst_Click() '第一题
    iCurrNum = 1'问题代码
End SubPrivate Sub BtnEnd_Click() '最末题
    iCurrNum = 50'问题代码
End SubPrivate Sub Command1_KeyPress(keyascii As Integer)
    BtnOk_KeyPress keyascii
End Sub

解决方案 »

  1.   

    你没有调用 seltest 函数
      

  2.   

    如果这样写
    Private Sub BtnFirst_Click() '第一题
        seltest iCurrNum = 0
    End SubPrivate Sub BtnEnd_Click() '最末题
        seltest iCurrNum = 49又会提示下标越界
        lText.Caption = strTest(Sel, 0)
    怎么回事啊,这是很久以前写的,我现在自己都有点迷糊了。
      

  3.   

    刷新一下吧,Me.Refresh
    不过可能会闪.
      

  4.   

    你的控件数组是从0到50的吗?
    还有strTest(Sel, 0)题目数组是不是从strTest(0, 0)到strTest(50, 0)的呢?
    你检查下先。
      

  5.   

    先介绍一下 txt文件的编排格式 如下
    -------------------------------------------------
    50
    50世界上第一台电子计算机是(    )年在美国诞生的。
    2
    2
    2
    1956
    1946(    )是计算机的输出设备。
    3
    5
    135
    显示器
    键盘
    打印机
    扫描仪
    音箱
    ..........
    -----------------------------------
    50代表试题总数
    每道题下的第一行数字代表试题类型1为单选/2为判断/3为多选
    第二行数字代表答案选项数目2为AB/3为ABC以此类推最多5个
    第三行数字代表正确答案1为A/2为B多选的话如135
    至于数组定义我也搞不清了
    还望高手帮着找出问题
      

  6.   

    定义数组为strTest(50, 8)strText(0,0)   为第一题题目类型
    strText(0,1)   为第一题题目
    strText(0,2)
    strText(0,3)
    strText(0,4)
    strText(0,5)
    strText(0,6)   为1-5个答案。如果其中数组为空就不显示出来就可以了。
    strText(0,7)   为第一题正确答案strText(1,0)   为第二题题目类型
    strText(1,1)   为第二题题目
    strText(1,2)
    strText(1,3)
    strText(1,4)
    strText(1,5)
    strText(1,6)   为1-5个答案。如果其中数组为空就不显示出来就可以了。
    strText(1,7)   为第二题正确答案
    依次类推。[上一道题]和[下一道题]只要改变数组下标在读数组内容就可以了。
      

  7.   

    在读取处加断点察看strTest是否正确读出。调用seltest方法没错,数据结构也已经清楚,最好是从写数组开始调查
      

  8.   

    问题已解决,如下:
    ---------------------
    Private Sub BtnFirst_Click() '第一题
        seltest 1
    End SubPrivate Sub BtnEnd_Click() '最末题
        seltest 50
    End Sub
    --------------------