5kong 5kong - 21 days ago 8
Vb.net Question

making a function that does stuff to pictureboxes?

Function myFunction(ByVal degree1 As PictureBox) As PictureBox
degree1.Visible = True
degree1.Image = Image.FromFile("C:\Standard Pics\waiting3.gif")
degree1.Location = New Point(locationx, locationy)
degree1.Size = New Size(51, 51)
End Function


I'm very new to making functions in visual basic- anyway, I'm trying to make a function that makes several changes to a picturebox, but it gives me this "Argument not specified for parameter 'degree1' of 'Public Function myFunction(ByVal degree1 As PictureBox) As PictureBox'" error- any possible fixes?

Answer

Please try following:

Sub mySub(ByRef degree1 As PictureBox)
    degree1.Visible = True
    degree1.Image = Image.FromFile("C:\Standard Pics\waiting3.gif")
    degree1.Location = New Point(locationx, locationy)
    degree1.Size = New Size(51, 51)
End Sub

Note the ByRef part in Sub() signature - it means that you're directly operating over given PictureBox object. This is called "passing argument by reference". You can read more about it here. Oh, and I presume you have your locationx and locationy variables set somewhere in your code?

Comments