2015-05-23 31 views
-1
If bar1.Visible = False Or bar1.Value > 0 Then 
     npc1.Visible = False 
    End If 
    If bar2.Visible = False Or bar2.Value >= 0 Then 
     npc2.Visible = False 
    End If 
    If bar3.Visible = False Or bar3.Value >= 0 Then 
     npc3.Visible = False 
    End If 
    If bar4.Visible = False Or bar4.Value >= 0 Then 
     npc4.Visible = False 
    End If 
    If bar5.Visible = False Or bar5.Value >= 0 Then 
     npc5.Visible = False 
    End If 

这继续到bar10和npc10 我不知道如何应用循环或数组。我不是最好的编程,但我的项目很快就会到期,我吓坏了,因为它看起来不错。如果可以,请帮助并分解它!简化我的代码

+0

这是不是一个地方,让别人为你做的项目工作... –

+0

好,什么是酒吧和NPC?这是一个用户表单还是这些单元格或...?我们需要更多信息才能提供帮助。 – vacip

+4

在[codereview.se]上的人很擅长使工作代码看起来不错并且工作得更好。如果你包含更多的上下文,比如整个程序,这可能是一个很好的代码审查问题。 –

回答

1
For n = 1 to 10 
    Set c = Me.Controls("bar" & n) 
    If c.Visible = False Or c.Value > 0 Then 
     Me.Controls("npc" & n).Visible = False 
    End If 
Next n 
1

试试这个

Dim i As Long 

For i = 1 To 10 Step 1 
    If bar(i).Visible = False Or bar(i).Value >= 0 Then 
     npc(i).Visible = False 
    End If 
Next i