Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
 Dim j As Integer
  Randomize
  For j = 1 To 6
   Select Case KeyCode
   Case Asc(Controls("label" & CStr(j)).Caption)
   Controls("label" & CStr(j)).Visible = False
   End Select
  Next j
End Sub
我想从label1开始,如果我点击键盘是与label1相应的字母则label1隐形
然后循环到label2
但是
   Case Asc(Controls("label" & CStr(j)).Caption)
   Controls("label" & CStr(j)).Visible = False
根本不遵从循环的label,点什么隐形什么。而且如果有相同字母的label,则同时隐形
请问应该怎么办?

解决方案 »

  1.   

    Controls("label" & CStr(j)).Caption
    ...
    还真的从来没有见过如此别扭的控件名称写法.莫非楼主不知道如何使用控件数组?
    还有那个似乎没有用处的Randomize 
    还有那个只有一个CASE的SELECT楼主,你还是直接说你要写的是什么吧,是打字游戏么?
      

  2.   

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 
    Dim j As Integer 
      For j = 1 To 6 
         if Controls("label" & CStr(j)).visible=true and Asc(Controls("label" & CStr(j)).Caption) =KeyCode  then
      Controls("label" & CStr(j)).Visible = False 
      Next j 
    End Sub
      

  3.   

    漏了一个end if 自己加上吧
      

  4.   

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) 
    Dim j As Integer 
      For j = 1 To 6 
         if Controls("label" & CStr(j)).visible=true and Asc(Controls("label" & CStr(j)).Caption) =KeyCode  then
      Controls("label" & CStr(j)).Visible = False 
         exit for
         end if
      Next j 
    End Sub
      

  5.   

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
      Dim j As Integer
      For j = 1 To 6
        If Controls("label" & CStr(j)).Visible = True Then
            If Asc(Controls("label" & CStr(j)).Caption) = KeyCode Then
                Controls("label" & CStr(j)).Visible = False
            End If
            Exit For
        End If
      Next j
    End Sub
      

  6.   

    估计你说的是这个意思吧:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Static i As Integer
        i = i + 1
        If KeyCode = Asc(Controls("label" & CStr(i)).Caption) Then Controls("label" & CStr(i)).Visible = False
    End Sub
      

  7.   


    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        Static i As Integer
        If KeyCode = Asc(Controls("label" & CStr(i)).Caption) Then 
             Controls("label" & CStr(i)).Visible = False
             i = i + 1
        end if
    End Sub
      

  8.   

    呵呵,楼上的莫把我的代码改错了,楼主明明说了是从label1开始的
      

  9.   

    是,
             Controls("label" & CStr(i)).Visible = False
             i = i + 1
    这两句应该换一下顺序