PictureBox array

Dim i
i=1
Dim pik
Pik = ""
Pik = "pictureBox" & CStr(i)
Msgbox "pictureBox1.Left : " & pik.Left

Undefined

May i know what has went wrong…

The .Left property works on most controls. In your example, though, Pik is a simple string.

I know pik is a string.my question is ,how to refer picturebox as an array…would you mind to help…i think it will be beneficial for others too.

Can you explain more about what you mean?

I have quite a number of picturebox.to random swap the left of all picturebox is tedious.so i wish i could list all the picturebox in an array and swap them ,eg
For i = 1 to 14
a = rand(i)+1
Pic[i].Left =pic[a].Left
NEXT

Oh,i have think of a long wited way.something like :

Pic[1]=pictureBox1.Left
'The list goes
'Then u do the swaping part
'Does anyone has even simpler way?

Or put your picture left data during array initialising.

I think you want a reference to the element, not a string with the name of the element.

Try this:

Pic[1] = document.getElementsByName("pictureBox1");

Thanks,will try when i reached home.

Dim Pic
Pic = Array("","","","","","","","","")
p0 = pictureBox1.getContext("2d")
p1 = pictureBox2.getContext("2d")

Sub Main()
p0.addImage("pp1.jpg",0,0)
p1.addImage("pp2.jpg",0,0)

JavaScript
Pic[1] = document.getElementsByName("pictureBox1");
Pic[2] = document.getElementsByName("pictureBox2");
End JavaScript

End Sub

Function Button1_onclick() 
  T=SetInterval(NextAction3,1000)
End Function


Function NextAction3()
Pic[1].Left = Pic[1].Left + 5
Pic[1].Top = Pic[1].Top + 5
End Function

document.getElementsByName doent do as expected
pic is shown but the pic does’nt move and Top is colored black [Pic[1].Top]

Function Button4_onclick() 
  T=SetInterval(NextAction3,1000)
End Function


Function NextAction3()
pictureBox1.Left = pictureBox1.Left + 5
pictureBox1.Top = pictureBox1.Top + 5
End Function

this is ok

Im still troubled with documents.getElementsByName ,as seen in 2nd previous post.any advice,anyone?

You’ll want to look at this for a discussion of all of the properties and events of the document object:

Then I would go into Chrome on any page or your app in Start In Desktop Browser or some such, and start the inspector (F12 in windows) and go to the console tab. Type in document. and you’ll see all the properties and methods. You can type in the arguments and test it out, see how it works.

Try document.location for example.

Also, in your case, you should also look at the elements and find your picture boxes and you’ll see some subelements that are created with their names.

i can only think of changing it to

pic[1] = document.getElementsByName("pictureBox1.Left");
pic[1] = pic[1] + 1;

It returns NodeList[]
Still doesn’t solve my problem.no err,doesn’t move

This comes before previous post

pic[1] = document.getElementsByName("pictureBox1.Left);

Try everything,cant get it to work.

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly.

pic[1] = document.getElementsByName("pictureBox1");
Is it afterward
c[1].Left =c[1].Left + 1
'Dont know why still get it to work,sorry to bother you again....

Since c[1] is a reference to pictureBox1,

pictureBox1[1].Left =pictureBox1[1].Left + 1

is the same as doing

c[1].Left =c[1].Left + 1