For loop struggles
Posted
#1
(In Topic #1254)
Regular

Despite some years experience with VB and now getting my feet wet with Gambas, I've always struggled with for loops. I don't know why, it just doesn't always click for me.
Say I have a listbox with 200 items in it and I want to do something with that data with a button click but only 5 (exact number is unknown right now) at a time. On top of that, the next button click would pick up after whatever the last item was. So first click of button would be listbox items 1 to 5, second button click would be listbox items 6-10 and so on and so on until the last item of the listbox is reached. Here's what I have so far:
Code (gambas)
- ListBox1.index = i
- 'dynamically creating buttons with text from items in the listbox (example on here that BruceSteers had but i changed a little to meet my needs - thanks Bruce!)
- TextBox1.Text = ListBox1.Current.Text
- '.Text = s
- .width = 150
- .Height = 150
- .Text = ListBox1.Current.Text
- '.Name = s
- .Name = ListBox1.Current.Text
How would I change that for loop to do what I'm trying here?
Posted
Regular

)
b
Posted
Guru

Code (gambas)
- ' set index at 0 if nothing is selected
- 'dynamically creating buttons with text from items in the listbox (example on here that BruceSteers had but i changed a little to meet my needs - thanks Bruce!) (You're welcome :) )
- TextBox1.Text = ListBox1.Current.Text
- '.Text = s
- .width = 150
- .Height = 150
- .Text = ListBox1.Current.Text
- '.Name = s
- .Name = ListBox1.Current.Text
Posted
Regular

Posted
Regular

Posted
Guru

rj71 said
Hey BruceSteers, in your dynamic button creation code, how do I change the font color on the buttons? I figured out how to set the font size but using .Foreground = white I get unknown identifier error. If this were just a button on the form that foreground= white would have worked. What am I not understanding? Also having trouble setting the buttons with a transparent background (.Background = Transparent throws unknown identifier error)as well as a border around the button. .Border = True doesn't throw an error but I don't see a border on the button.
All those color related constants are from Color.class
You are correct to use .Foreground but you must use color constants like this…
.Foreground = Color.White
.Background = Color.Transparent
/comp/gb.qt4/color - Gambas Documentation
You can also try direct color codes (hexidecimal RGB) , (hint, press Ctrl+Shift+C)
.Foreground = &FF00FF
Or make partially transparent.
.Background = Color.SetAlpha(Color.Blue, 200)
Setting Button1.Border = True "should" render a border.
Note: some object use an integer value for border and can use Border.Plain , Border.Raised, Border.None, Etc.
It also depends on the toolkit/theme being used, some toolkit themes just do not render borders.
You should really see a difference with a button having a border or not.
the default value is true for buttons to have a border , only ToolButton does not have a border by default.
Try setting .Border = False and see if you see a difference
Posted
Regular

BruceSteers said
rj71 said
Hey BruceSteers, in your dynamic button creation code, how do I change the font color on the buttons? I figured out how to set the font size but using .Foreground = white I get unknown identifier error. If this were just a button on the form that foreground= white would have worked. What am I not understanding? Also having trouble setting the buttons with a transparent background (.Background = Transparent throws unknown identifier error)as well as a border around the button. .Border = True doesn't throw an error but I don't see a border on the button.
All those color related constants are from Color.class
You are correct to use .Foreground but you must use color constants like this…
.Foreground = Color.White
.Background = Color.Transparent
/comp/gb.qt4/color - Gambas Documentation
You can also try direct color codes (hexidecimal RGB) , (hint, press Ctrl+Shift+C)
.Foreground = &FF00FF
Or make partially transparent.
.Background = Color.SetAlpha(Color.Blue, 200)
Setting Button1.Border = True "should" render a border.
Note: some object use an integer value for border and can use Border.Plain , Border.Raised, Border.None, Etc.
It also depends on the toolkit/theme being used, some toolkit themes just do not render borders.
You should really see a difference with a button having a border or not.
the default value is true for buttons to have a border , only ToolButton does not have a border by default.
Try setting .Border = False and see if you see a difference
Thanks Bruce! That works except it seems that sometimes it doesn't apply to all the buttons that get created, some have the white font color and some don't…same for transparent background. I assume there's something else going on in my code so I'll figure it out. Thanks again!
1 guest and 0 members have just viewed this.


