vb6 - Alternative method for "For Loop" -
vb6 - Alternative method for "For Loop" -
i have 4 different values, want check 4 values 4 different combination
code
dim tot1, tot2, tot3, to4 variant dim item1, item2, item3, item4 variant each item1 in tot1 each item2 in tot2 each item3 in tot3 each item4 in tot4 if item1 = "all" , item2 <> "all" , item3 <> "all" , item4 <> "all" '1 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition <> '" & item2 & "' , section <> '" & item3 & "' , location <> '" & item4 & "'" elseif item1 <> "all" , item2 = "all" , item3 <> "all" , item4 <> "all" '2 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition = '" & item2 & "' , section <> '" & item3 & "' , location <> '" & item4 & "'" elseif item1 <> "all" , item2 <> "all" , item3 = "all" , item4 <> "all" '3 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition <> '" & item2 & "' , section = '" & item3 & "' , location <> '" & item4 & "'" elseif item1 <> "all" , item2 <> "all" , item3 <> "all" , item4 = "all" '4 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition <> '" & item2 & "' , section <> '" & item3 & "' , location = '" & item4 & "'" elseif item1 = "all" , item2 = "all" , item3 <> "all" , item4 <> "all" '1 & 2 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition = '" & item2 & "' , section <> '" & item3 & "' , location <> '" & item4 & "'" elseif item1 = "all" , item2 <> "all" , item3 = "all" , item4 <> "all" '1 & 3 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition <> '" & item2 & "' , section = '" & item3 & "' , location <> '" & item4 & "'" elseif item1 = "all" , item2 <> "all" , item3 <> "all" , item4 = "all" '1 & 4 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition <> '" & item2 & "' , section <> '" & item3 & "' , location = '" & item4 & "'" elseif item1 <> "all" , item2 = "all" , item3 = "all" , item4 <> "all" '2 & 3 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition = '" & item2 & "' , section = '" & item3 & "' , location <> '" & item4 & "'" elseif item1 <> "all" , item2 = "all" , item3 <> "all" , item4 = "all" '2 & 4 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition = '" & item2 & "' , section <> '" & item3 & "' , location = '" & item4 & "'" elseif item1 <> "all" , item2 <> "all" , item3 = "all" , item4 = "all" '3 & 4 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition <> '" & item2 & "' , section = '" & item3 & "' , location = '" & item4 & "'" elseif item1 = "all" , item2 = "all" , item3 = "all" , item4 <> "all" '1 & 2 & 3 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition = '" & item2 & "' , section = '" & item3 & "' , location <> '" & item4 & "'" elseif item1 = "all" , item2 = "all" , item3 <> "all" , item4 = "all" '1 & 2 & 4 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition = '" & item2 & "' , section <> '" & item3 & "' , location = '" & item4 & "'" elseif item1 = "all" , item2 <> "all" , item3 = "all" , item4 = "all" '1 & 3 & 4 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition <> '" & item2 & "' , section = '" & item3 & "' , location = '" & item4 & "'" elseif item1 <> "all" , item2 = "all" , item3 = "all" , item4 = "all" '2 & 3 & 4 ssql = "insert table1 select distinct emp_code employee company <> '" & item1 & "' , partition = '" & item2 & "' , section = '" & item3 & "' , location = '" & item4 & "'" elseif item1 <> "all" , item2 <> "all" , item3 <> "all" , item4 <> "all" '1 & 2 & 3 & 4 ssql = "insert table1 select distinct emp_code employee company = '" & item1 & "' , partition = '" & item2 & "' , section = '" & item3 & "' , location = '" & item4 & "'" end if next next next next
the above mentioned code working, code hard checking 4 values combination, incase if checking values 6 hard write combination....
any other alternative method available...?
i think havnt mention exact construction of data, otherwise there have been improve code example, however, seek own code little modification
dim tot1 new collection, tot2 new collection, tot3 new collection, tot4 new collection dim item1, item2, item3, item4 variant dim str string tot1.add "all" tot1.add "2" tot1.add "3" tot1.add "4" tot2.add "1" tot2.add "2" tot2.add "3" tot2.add "all" tot2.add "5" tot3.add "1" tot3.add "all" tot3.add "3" tot3.add "4" tot3.add "5" tot3.add "6" tot4.add "1" tot4.add "all" tot4.add "3" each item1 in tot1 each item2 in tot2 each item3 in tot3 each item4 in tot4 str = vbnullstring if item1 = "all" str = str & "& 1 " if item2 = "all" str = str & "& 2 " if item3 = "all" str = str & "& 3 " if item4 = "all" str = str & "& 4 " debug.print item1 & "," & item2 & "," & item3 & "," & item4 & " -> " & mid$(trim$(str), 2) next next next next
vb6 for-loop
Comments
Post a Comment