Author Topic: Comboboxes?  (Read 1088 times)

Offline Comrade Ravenhawk

  • Level 12
  • *
  • Posts: 79
  • Reputation: +1/-0
    • View Profile
    • The Socialist Gamer Review
Comboboxes?
« on: December 04, 2006, 12:55:04 AM »
Basically I'm doing a project in VB where I have 6 values. I want to apply these six values to one of six options in six different combo boxes. (dropdown boxes)
The dropdown boxes are in an array. One they've chosen options for all 6 dropdown boxes, they hit a button to apply them.
Basically what I need to do is make it so if they try to apply two of the values to the same variable, they get an error.
I'm having trouble figuring out how to get it to go through an check each of them and make sure that none of them are equal.
I'm currently messing around with Nested For loops, but I have issues with visualization.  -_-

Offline compuken

  • Level 10
  • *
  • Posts: 63
  • Reputation: +2/-5
    • View Profile
Re: Comboboxes?
« Reply #1 on: December 05, 2006, 02:43:31 PM »
how about an onclick() event for the combo box

Private Sub Combo1_Click ()
   If Combo1.Text = "selected item 1" Then
      Combo2.RemoveItem 0 //0 is the index number
      Combo3.RemoveItem 0
      Combo4.RemoveItem 0
      Combo5.RemoveItem 0
      Combo6.RemoveItem 0
   End If
End Sub

or

Private Sub Combo1_Click()
combolistcheck()
end sub

Sub combolistcheck()

if combo1.selecteditem = combo2.selecteditem or combo1.selecteditem = combo3.selecteditem or combo1.selecteditem = combo4.selecteditem or  combo1.selecteditem = combo5.selecteditem or
combo1.selecteditem = combo6.selecteditem
then
combo1.selected = 0
combo2. selected = 1
combo3.selected = 2
combo4.selected = 3
combo5.selected = 4
combo6.selected = 5
else
if

......


You get the gist, forgive if all my vb comands don't work as I am a bit rusty in vb. But maybe doing a check in the combo(i)_click sub you can solve your problem.


 

Offline compuken

  • Level 10
  • *
  • Posts: 63
  • Reputation: +2/-5
    • View Profile
Re: Comboboxes?
« Reply #2 on: December 05, 2006, 03:43:17 PM »
Once again you would have to make sure this works  and adjust the top lines for each combo click event. If you make the comboboxes an array then you could condense the code with a for loop

FOR LOOP IF HAVE COMBOBOXES IN ARRAY:
for i = 0 to i = 6 i++
checkstring = combo[i+1].text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if
end for


HERE IS THE LONG CODE:

Private Sub Combo1_Click ()
dim selectedtext as String
selectedtext = combo1.text

combocheck selectedtext

End Sub

Public Sub combocheck(selectedtext as String)

dim checkstring as String
dim multiplecheck as integer

multiplecheck = 0


checkstring = combo1.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if

checkstring = combo2.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if

checkstring = combo3.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if

checkstring = combo4.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if

checkstring = combo5.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if

checkstring = combo6.text
if checkstring = selectedtext then
multiplecheck = multiplecheck + 1
end if


if multiplecheck > 1 then
Msg("you have the same value selected")
end if


end sub

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal