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?
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.
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
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