combox.index

Post

Posted
Rating:
#1 (In Topic #379)
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
I am working with a combo box and trying to assign a value to the combox.index

Code (gambas)

  1.  ComboBox1.Index = ComboBox1.Count
  2.   Print ComboBox1.Index, ComboBox1.Count
  3.  
  4. out put is   -1         7
  5.  
  6.  ComboBox1.Index = 4
  7.   Print ComboBox1.Index, ComboBox1.Count
  8.  
  9. out put is   4       7
  10.  
  11. Dim x As Integer = ComboBox1.Count
  12.   ComboBox1.Index = x
  13.   Print x, ComboBox1.Index, ComboBox1.Count
  14.  
  15. output is   7       -1        7
  16.  
  17.  
  18. Dim x As Integer = 4
  19.   ComboBox1.Index = x
  20.   Print x, ComboBox1.Index, ComboBox1.Count
  21.  
  22. output is   7       4        7
  23.  

Seams to work with a number … but not with .count   how can I convert .count  to a number ,
I have tried ABS .,. ASC … VAL … STR… NO JOY  :mrgreen:
for some reason combobox1.count is not an integer ??
what am I doing wrong ???

my program is attached with the problem at lines 86 to 90

Attachment
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
stevedee is in the usergroup ‘Regular’

grayghost4 said

I am working with a combo box and trying to assign a value to the combox.index

Code (gambas)

  1.  ComboBox1.Index = ComboBox1.Count
  2.   Print ComboBox1.Index, ComboBox1.Count
  3.  
  4. out put is   -1         7
  5.  
  6. ......
  7.  
  8. Dim x As Integer = ComboBox1.Count
  9.   ComboBox1.Index = x
  10.   Print x, ComboBox1.Index, ComboBox1.Count
  11.  
  12. output is   7       -1        7
  13.  
  14.  
  15. You can only set the ComboBox.Index to integers in the legal range for the current condition of the combobox.
  16.  
  17. For example, if I create a new combobox and do this;
  18.  
  19. [code numbers="1" param="gambas" scroll="1"]  ComboBox1.Add("one")
  20.   ComboBox1.Add("two")
  21.   ComboBox1.Add("three")[/code]
  22.  
  23. I now have 3 items in the combobox, so the .Count = 3  and when .Index = 0 the Item is "one"
  24. When you attempt to set .Index to 3 you get an error (or -1 value) because .Index = 3 would be the 4th Item, which does not exist.
  25.  
  26. I hope this is clear, but let me know.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
GrayGhost is in the usergroup ‘Enthusiast’
thank You …. all I needed was .count -1 to get what i wanted  :D
The proverbial off by one error.
I have been struggling with this for two day.
Online now: No Back to the top
1 guest and 0 members have just viewed this.