|
-
Dec 27th, 2019, 08:48 AM
#1
Thread Starter
New Member
New value not setting in For each statement
I have this code:
Code:
For Each srvr In discord.Guilds
Dim pb As New PictureBox
pb.Width = 70
pb.Height = 70
pb.Left = 10
Dim topVal as Integer = 30
pb.Top = topVal
topVal = +30
Dim ttImage As Bitmap = Bitmap.FromStream(New MemoryStream(tClient.DownloadData(srvr.IconUrl)))
pb.BackgroundImage = ttImage
pb.Tag = srvr.Id.ToString + " | " + srvr.Name
pb.BackgroundImageLayout = ImageLayout.Zoom
Me.Controls.Add(pb)
pb.BringToFront()
Next
It makes the picturebox and adds it onto the form as I wanted, but the new top value doesn't set and they just stack on top of each other. How can I fix this?
-
Dec 27th, 2019, 12:07 PM
#2
Re: New value not setting in For each statement
Debug your code. Read through it line by line as it would be executed. You will see that each time the loop is executed, topVal is getting (re)set to 30, so pb.Top is going to be 30 for all of the PictureBoxes created.
-
Dec 27th, 2019, 02:24 PM
#3
Re: New value not setting in For each statement
topVal = -30
This sets topVal to negative 30.
topVal = +30
This sets topVal to positive 30.
Old style:
topVal = topVal + 30
This increments topVal by 30
New style:
topVal += 30
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Dec 27th, 2019, 03:20 PM
#4
Re: New value not setting in For each statement
Hello
Put
Code:
Dim topVal as Integer = 30
outside the for each loop and apply the correction passel has given. It should solve your problem.
regards
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|