Function question???

K

karim

I have this function to zoom an image in my form, but I can't get it to work.
can anyone tell me how to get it to work or what's wrong with it. also i'm
getting this erorr msg: (local variable cannot have the same name as the
function containing it)
here is the code:

Public Function ZoomImage(ByVal img As System.Drawing.Image, ByVal ZoomValue
As Int32) As System.Drawing.Image
Dim width As Int32 = Convert.ToInt32(img.Width * ZoomValue) / 100
Dim height As Int32 = Convert.ToInt32(img.Height * ZoomValue) / 100
'Create a new image based on the zoom parameters we require
Dim zoomImage As New System.Drawing.Bitmap(img, width, height)

'Create a new graphics object based on the new image
Dim converted As System.Drawing.Graphics =
System.Drawing.Graphics.FromImage(zoomImage)

'Clean up the image
converted.InterpolationMode = InterpolationMode.HighQualityBicubic

'Return the zoomed image
Return zoomImage
End Function
 
A

Andrew Morton

karim said:
also i'm getting this erorr msg: (local variable cannot have
the same name as the function containing it)
Public Function ZoomImage(...
Dim zoomImage As ...

Start by changing the name of the variable zoomImage. VB is not
case-sensitive.

Andrew
 
K

kimiraikkonen

Start by changing the name of the variable zoomImage. VB is not
case-sensitive.

Andrew

I think changing function name "ZoomImage" to something like
"ZoomImageFunc" or anything should help based on the error which OP
describes.

Because function returns zoomImage variable which is declared as:
Dim zoomImage As New System.Drawing.Bitmap(img, width, height)

...inside function-end function block.

Thanks,

Onur Güzel
 
A

Andrew Morton

kimiraikkonen said:
I think changing function name "ZoomImage" to something like
"ZoomImageFunc" or anything should help based on the error which OP
describes.

Because function returns zoomImage variable which is declared as:
Dim zoomImage As New System.Drawing.Bitmap(img, width, height)

Hmmm... I would have thought that the external appearance of the function
(its name) should take precedence over the names of the variables used
inside that function, hence my suggestion to change the name of the variable
rather than the function.

Also, I thought that using the type of a variable/function in its name had
gone out of fashion?

ICBW...

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top