Variable isn't decalred error --but it is!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jerry West

    #1

    Variable isn't decalred error --but it is!

    I have a 'variable not declared' error occurring when in fact the var is
    declared --its just nested in a If Then statement. Like so:

    If bPortrait Then

    'then its in portrait mode

    ' Make a bitmap for the result.
    Dim bm_dest As New Bitmap(CInt(bm_ source.Height *
    scale_factor), CInt(bm_source. Width * scale_factor))

    Else

    'then it's in landscape mode

    ' Make a bitmap for the result.
    Dim bm_dest As New Bitmap(CInt(bm_ source.Width *
    scale_factor), CInt(bm_source. Height * scale_factor))

    End If

    Why do I get this error when either way the If Then clause falls the var is
    declared and will execute? I understand that I can set the If Then clause
    for the height & width values and then declare the var outside of that. But
    why doesn't the above --which is functionally equivalent-- work?

    JW


  • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

    #2
    RE: Variable isn't decalred error --but it is!

    JW,

    Where do you get the error?

    Kerry Moorman


    "Jerry West" wrote:
    I have a 'variable not declared' error occurring when in fact the var is
    declared --its just nested in a If Then statement. Like so:
    >
    If bPortrait Then
    >
    'then its in portrait mode
    >
    ' Make a bitmap for the result.
    Dim bm_dest As New Bitmap(CInt(bm_ source.Height *
    scale_factor), CInt(bm_source. Width * scale_factor))
    >
    Else
    >
    'then it's in landscape mode
    >
    ' Make a bitmap for the result.
    Dim bm_dest As New Bitmap(CInt(bm_ source.Width *
    scale_factor), CInt(bm_source. Height * scale_factor))
    >
    End If
    >
    Why do I get this error when either way the If Then clause falls the var is
    declared and will execute? I understand that I can set the If Then clause
    for the height & width values and then declare the var outside of that. But
    why doesn't the above --which is functionally equivalent-- work?
    >
    JW
    >
    >
    >

    Comment

    • Jerry West

      #3
      Re: Variable isn't decalred error --but it is!

      You mean when do I encounter the error? If so, the code window underlines
      every instance of bm_dest; flagging it as an error. As well, if I try to run
      the code I am not allowed to. Is that what you mean?

      JW

      "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
      news:57710FC2-7472-4940-A17B-948C8803CBF8@mi crosoft.com...
      JW,
      >
      Where do you get the error?
      >
      Kerry Moorman
      >
      >
      "Jerry West" wrote:
      >
      >I have a 'variable not declared' error occurring when in fact the var is
      >declared --its just nested in a If Then statement. Like so:
      >>
      > If bPortrait Then
      >>
      > 'then its in portrait mode
      >>
      > ' Make a bitmap for the result.
      > Dim bm_dest As New Bitmap(CInt(bm_ source.Height *
      >scale_factor ), CInt(bm_source. Width * scale_factor))
      >>
      > Else
      >>
      > 'then it's in landscape mode
      >>
      > ' Make a bitmap for the result.
      > Dim bm_dest As New Bitmap(CInt(bm_ source.Width *
      >scale_factor ), CInt(bm_source. Height * scale_factor))
      >>
      > End If
      >>
      >Why do I get this error when either way the If Then clause falls the var
      >is
      >declared and will execute? I understand that I can set the If Then clause
      >for the height & width values and then declare the var outside of that.
      >But
      >why doesn't the above --which is functionally equivalent-- work?
      >>
      >JW
      >>
      >>
      >>

      Comment

      • =?Utf-8?B?S2VycnkgTW9vcm1hbg==?=

        #4
        Re: Variable isn't decalred error --but it is!

        JW,

        What I meant was are you trying to use the variable outside the If - Then -
        Else statement?

        If so, then that is your problem. The scope of the variable is only within
        the If - Then - Else statement. You need to dimension bm_dest at the top of
        the procedure:

        Dim bm_dest As BitMap

        and then set it to a new instance inside the If statement.

        Kerry Moorman


        "Jerry West" wrote:
        You mean when do I encounter the error? If so, the code window underlines
        every instance of bm_dest; flagging it as an error. As well, if I try to run
        the code I am not allowed to. Is that what you mean?
        >
        JW
        >
        "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
        news:57710FC2-7472-4940-A17B-948C8803CBF8@mi crosoft.com...
        JW,

        Where do you get the error?

        Kerry Moorman


        "Jerry West" wrote:
        I have a 'variable not declared' error occurring when in fact the var is
        declared --its just nested in a If Then statement. Like so:
        >
        If bPortrait Then
        >
        'then its in portrait mode
        >
        ' Make a bitmap for the result.
        Dim bm_dest As New Bitmap(CInt(bm_ source.Height *
        scale_factor), CInt(bm_source. Width * scale_factor))
        >
        Else
        >
        'then it's in landscape mode
        >
        ' Make a bitmap for the result.
        Dim bm_dest As New Bitmap(CInt(bm_ source.Width *
        scale_factor), CInt(bm_source. Height * scale_factor))
        >
        End If
        >
        Why do I get this error when either way the If Then clause falls the var
        is
        declared and will execute? I understand that I can set the If Then clause
        for the height & width values and then declare the var outside of that.
        But
        why doesn't the above --which is functionally equivalent-- work?
        >
        JW
        >
        >
        >
        >
        >
        >

        Comment

        • Jerry West

          #5
          Re: Variable isn't decalred error --but it is!

          Ah, got it. I didn't realize it's scope was relegated to only the If Then
          statement. Thanks!

          JW

          "Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
          news:F71C339A-074A-4D02-985C-FF8E3B745DED@mi crosoft.com...
          JW,
          >
          What I meant was are you trying to use the variable outside the If -
          Then -
          Else statement?
          >
          If so, then that is your problem. The scope of the variable is only within
          the If - Then - Else statement. You need to dimension bm_dest at the top
          of
          the procedure:
          >
          Dim bm_dest As BitMap
          >
          and then set it to a new instance inside the If statement.
          >
          Kerry Moorman
          >
          >
          "Jerry West" wrote:
          >
          >You mean when do I encounter the error? If so, the code window underlines
          >every instance of bm_dest; flagging it as an error. As well, if I try to
          >run
          >the code I am not allowed to. Is that what you mean?
          >>
          >JW
          >>
          >"Kerry Moorman" <KerryMoorman@d iscussions.micr osoft.comwrote in message
          >news:57710FC 2-7472-4940-A17B-948C8803CBF8@mi crosoft.com...
          JW,
          >
          Where do you get the error?
          >
          Kerry Moorman
          >
          >
          "Jerry West" wrote:
          >
          >I have a 'variable not declared' error occurring when in fact the var
          >is
          >declared --its just nested in a If Then statement. Like so:
          >>
          > If bPortrait Then
          >>
          > 'then its in portrait mode
          >>
          > ' Make a bitmap for the result.
          > Dim bm_dest As New Bitmap(CInt(bm_ source.Height *
          >scale_factor ), CInt(bm_source. Width * scale_factor))
          >>
          > Else
          >>
          > 'then it's in landscape mode
          >>
          > ' Make a bitmap for the result.
          > Dim bm_dest As New Bitmap(CInt(bm_ source.Width *
          >scale_factor ), CInt(bm_source. Height * scale_factor))
          >>
          > End If
          >>
          >Why do I get this error when either way the If Then clause falls the
          >var
          >is
          >declared and will execute? I understand that I can set the If Then
          >clause
          >for the height & width values and then declare the var outside of
          >that.
          >But
          >why doesn't the above --which is functionally equivalent-- work?
          >>
          >JW
          >>
          >>
          >>
          >>
          >>
          >>

          Comment

          Working...