help!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • richy176
    New Member
    • May 2007
    • 8

    #1

    help!

    hey...im doing an IF statement, and i was wondering if there is a way this code below can be done 17 times without copying and pasting 17 times?

    If cboGSnap(0) = "2" Then
    lblSnapWin(0) = "G"
    ElseIf cboYSnap(0) = "2" Then
    lblSnapWin(0) = "Y"
    End If

    If Val(cboGSnap(0) ) + Val(cboYSnap(0) ) = 4 Then
    MsgBox "Error! please recheck score input", vbExclamation, "error"
    cboGSnap(0) = "0"
    cboYSnap(0) = "0"
    lblSnapWin(0) = ""

    End If

    thanks...please reply!
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by richy176
    hey...im doing an IF statement, and i was wondering if there is a way this code below can be done 17 times without copying and pasting 17 times?

    If cboGSnap(0) = "2" Then
    lblSnapWin(0) = "G"
    ElseIf cboYSnap(0) = "2" Then
    lblSnapWin(0) = "Y"
    End If

    If Val(cboGSnap(0) ) + Val(cboYSnap(0) ) = 4 Then
    MsgBox "Error! please recheck score input", vbExclamation, "error"
    cboGSnap(0) = "0"
    cboYSnap(0) = "0"
    lblSnapWin(0) = ""

    End If

    thanks...please reply!
    Do you mean by changing the indexes???
    Sure, here you are:

    Code:
    Dim i as integer
    For i = 1 to 16
    If cboGSnap(i) = "2" Then
        lblSnapWin(i) = "G"
    ElseIf cboYSnap(i) = "2" Then
        lblSnapWin(i) = "Y"
    End If
    
    If Val(cboGSnap(i)) + Val(cboYSnap(i)) = 4 Then
        MsgBox "Error! please recheck score input", vbExclamation, "error"
    cboGSnap(i) = "0"
    cboYSnap(i) = "0"
    lblSnapWin(i) = ""
    End If
    
    Next
    Hope this helps.

    Comment

    Working...