Function question???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?a2FyaW0=?=

    Function question???

    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.FromIm age(zoomImage)

    'Clean up the image
    converted.Inter polationMode = InterpolationMo de.HighQualityB icubic

    'Return the zoomed image
    Return zoomImage
    End Function
  • Andrew Morton

    #2
    Re: Function question???

    karim wrote:
    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


    Comment

    • kimiraikkonen

      #3
      Re: Function question???

      On Oct 15, 12:56 pm, "Andrew Morton" <a...@in-press.co.uk.inv alid>
      wrote:
      karim wrote:
      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
      I think changing function name "ZoomImage" to something like
      "ZoomImageF unc" 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

      Comment

      • Andrew Morton

        #4
        Re: Function question???

        kimiraikkonen wrote:
        On Oct 15, 12:56 pm, "Andrew Morton" <a...@in-press.co.uk.inv alid>
        wrote:
        >karim wrote:
        >>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
        >
        I think changing function name "ZoomImage" to something like
        "ZoomImageF unc" 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


        Comment

        Working...