combox.index

Post your Gambas programming questions here.
Post Reply
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

combox.index

Post by grayghost4 »

I am working with a combo box and trying to assign a value to the combox.index
 ComboBox1.Index = ComboBox1.Count
  Print ComboBox1.Index, ComboBox1.Count

out put is   -1         7 

 ComboBox1.Index = 4 
  Print ComboBox1.Index, ComboBox1.Count

out put is   4       7 

Dim x As Integer = ComboBox1.Count
  ComboBox1.Index = x
  Print x, ComboBox1.Index, ComboBox1.Count

output is   7       -1        7


Dim x As Integer = 4
  ComboBox1.Index = x
  Print x, ComboBox1.Index, ComboBox1.Count

output is   7       4        7
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
Attachments
printchecksBk.tar.gz
(1.09 MiB) Downloaded 327 times
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: combox.index

Post by stevedee »

grayghost4 wrote: Sunday 23rd February 2020 6:14pm I am working with a combo box and trying to assign a value to the combox.index
 ComboBox1.Index = ComboBox1.Count
  Print ComboBox1.Index, ComboBox1.Count

out put is   -1         7 

......

Dim x As Integer = ComboBox1.Count
  ComboBox1.Index = x
  Print x, ComboBox1.Index, ComboBox1.Count

output is   7       -1        7
You can only set the ComboBox.Index to integers in the legal range for the current condition of the combobox.

For example, if I create a new combobox and do this;
  ComboBox1.Add("one")
  ComboBox1.Add("two")
  ComboBox1.Add("three")
I now have 3 items in the combobox, so the .Count = 3 and when .Index = 0 the Item is "one"
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.

I hope this is clear, but let me know.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: combox.index

Post by grayghost4 »

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.
Post Reply