|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
I declared the variable already, so why doesn't VB recognize it?from a module to a form. The code is in this style: Private priVar as Boolean Public Property Get pubVar() as Boolean pubVar = priVar End Property Public Property Let pubVar(nv as Boolean) priVar = nv 'Do stuff to form End Property When I run the code, I get an error about the variable not being defined. It highlights the reference to priVar in the Let method and every other time that I reference it in the Let method. It does not give me this error in the Get method, nor did I ever get this error when the code was in the module. Needless to say, it has me stumped. Anyone have any idea what I did wrong? -- Chris Lieb UPS CACH, Hodgekins, IL Tech Support Group - Systems/Apps Where are you trying to using the variable from? If from within the same
form that the property is defined then the code should work. If from within a module or another form then you need to preface the variable with the form name. Like: Form1.pubVar -- Show quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp -- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message news:757D0D8D-71FA-48CB-A699-B676B0AB0385@microsoft.com... > I am restructuring a program and copied over some code for some properties > from a module to a form. The code is in this style: > > Private priVar as Boolean > > Public Property Get pubVar() as Boolean > pubVar = priVar > End Property > > Public Property Let pubVar(nv as Boolean) > priVar = nv > > 'Do stuff to form > End Property > > When I run the code, I get an error about the variable not being defined. > It highlights the reference to priVar in the Let method and every other time > that I reference it in the Let method. It does not give me this error in the > Get method, nor did I ever get this error when the code was in the module. > Needless to say, it has me stumped. Anyone have any idea what I did wrong? > > -- > Chris Lieb > UPS CACH, Hodgekins, IL > Tech Support Group - Systems/Apps
Show quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message I think that property procedures are reserved for classes.news:757D0D8D-71FA-48CB-A699-B676B0AB0385@microsoft.com... >I am restructuring a program and copied over some code for some properties > from a module to a form. The code is in this style: > > Private priVar as Boolean > > Public Property Get pubVar() as Boolean > pubVar = priVar > End Property > > Public Property Let pubVar(nv as Boolean) > priVar = nv > > 'Do stuff to form > End Property > > When I run the code, I get an error about the variable not being defined. > It highlights the reference to priVar in the Let method and every other > time > that I reference it in the Let method. It does not give me this error in > the > Get method, nor did I ever get this error when the code was in the module. > Needless to say, it has me stumped. Anyone have any idea what I did > wrong? > -- Peter Aitken Remove the crap from my email address before using. Forms are Classes - just a special type that has a graphical interface.
-- Show quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp -- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ "Peter Aitken" <pait***@CRAPnc.rr.com> wrote in message news:%231potP%23VFHA.3076@TK2MSFTNGP12.phx.gbl... > "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message > news:757D0D8D-71FA-48CB-A699-B676B0AB0385@microsoft.com... > >I am restructuring a program and copied over some code for some properties > > from a module to a form. The code is in this style: > > > > Private priVar as Boolean > > > > Public Property Get pubVar() as Boolean > > pubVar = priVar > > End Property > > > > Public Property Let pubVar(nv as Boolean) > > priVar = nv > > > > 'Do stuff to form > > End Property > > > > When I run the code, I get an error about the variable not being defined. > > It highlights the reference to priVar in the Let method and every other > > time > > that I reference it in the Let method. It does not give me this error in > > the > > Get method, nor did I ever get this error when the code was in the module. > > Needless to say, it has me stumped. Anyone have any idea what I did > > wrong? > > > > I think that property procedures are reserved for classes. > > > -- > Peter Aitken > > Remove the crap from my email address before using. > > "Veign" <NOSPAMinveign@veign.com> wrote in message And beyond that, property procedures also work just fine in standardnews:up8jNX%23VFHA.584@TK2MSFTNGP15.phx.gbl > Forms are Classes - just a special type that has a graphical > interface. > "Peter Aitken" <pait***@CRAPnc.rr.com> wrote in message > news:%231potP%23VFHA.3076@TK2MSFTNGP12.phx.gbl... >> I think that property procedures are reserved for classes. modules. VB6 is a very flexible tool when you know how to use it. -- Reply to the group so all can participate VB.Net: "Fool me once..." True - Just never think of putting property procedures in standard modules.
I guess if you wanted to encapsulate something that requires a hook / subclass maybe if would make the module neater looking... -- Show quoteChris Hanscom - Microsoft MVP (VB) Veign's Resource Center http://www.veign.com/vrc_main.asp -- Read. Decide. Sign the petition to Microsoft. http://classicvb.org/petition/ "Bob Butler" <tiredofit@nospam.com> wrote in message news:ONwNiB$VFHA.2424@TK2MSFTNGP10.phx.gbl... > "Veign" <NOSPAMinveign@veign.com> wrote in message > news:up8jNX%23VFHA.584@TK2MSFTNGP15.phx.gbl > > Forms are Classes - just a special type that has a graphical > > interface. > > "Peter Aitken" <pait***@CRAPnc.rr.com> wrote in message > > news:%231potP%23VFHA.3076@TK2MSFTNGP12.phx.gbl... > >> I think that property procedures are reserved for classes. > > And beyond that, property procedures also work just fine in standard > modules. VB6 is a very flexible tool when you know how to use it. > > -- > Reply to the group so all can participate > VB.Net: "Fool me once..." > "Veign" <NOSPAMinveign@veign.com> wrote in message I've used it when I want to initialize a "global" object on first use ornews:e5p1hF$VFHA.228@TK2MSFTNGP12.phx.gbl > True - Just never think of putting property procedures in standard > modules. I guess if you wanted to encapsulate something that requires > a hook / subclass maybe if would make the module neater looking... have other checks on changes made to some value. Keeping the actual variable private in the module and using a public property gives the best of both worlds. -- Reply to the group so all can participate VB.Net: "Fool me once..." On Fri, 13 May 2005 12:30:23 -0700, "Bob Butler"
<tiredofit@nospam.com> wrote: >"Veign" <NOSPAMinveign@veign.com> wrote in message It is also neat for writing things that work like :>news:e5p1hF$VFHA.228@TK2MSFTNGP12.phx.gbl >> True - Just never think of putting property procedures in standard >> modules. I guess if you wanted to encapsulate something that requires >> a hook / subclass maybe if would make the module neater looking... > >I've used it when I want to initialize a "global" object on first use or >have other checks on changes made to some value. Keeping the actual >variable private in the module and using a public property gives the best of >both worlds. Mid$( S$, 2, 1 ) = "?" Where one is not really 'Let'ting any Property
Show quote
"Bob Butler" <tiredofit@nospam.com> wrote in message Yes, you are right - I tried it.news:ONwNiB$VFHA.2424@TK2MSFTNGP10.phx.gbl... > "Veign" <NOSPAMinveign@veign.com> wrote in message > news:up8jNX%23VFHA.584@TK2MSFTNGP15.phx.gbl >> Forms are Classes - just a special type that has a graphical >> interface. >> "Peter Aitken" <pait***@CRAPnc.rr.com> wrote in message >> news:%231potP%23VFHA.3076@TK2MSFTNGP12.phx.gbl... >>> I think that property procedures are reserved for classes. > > And beyond that, property procedures also work just fine in standard > modules. VB6 is a very flexible tool when you know how to use it. > > -- -- Peter Aitken Remove the crap from my email address before using. On Fri, 13 May 2005 13:50:10 -0400, "Peter Aitken"
<pait***@CRAPnc.rr.com> wrote: > Not really. They work fine in forms too. (A Form is essentially a>I think that property procedures are reserved for classes. class with a UI and some built-in methods.) FWIW prop proceedures will also work in a bas module, though I'm not sure how useful that is. -Tom MVP - Visual Basic (please post replies to the newsgroup) I figured it out after forcing VB to do a full compile. It is because I was
declaring the variables after I had already declared some other properties. I hate how anal VB is about where things are placed and in what order they appear. C# would care less and allow me to declare each private variable right above its public property declaration. Oh well, one more peculiarity to get used to, I guess. Chris Show quote "Chris Lieb" wrote: > I am restructuring a program and copied over some code for some properties > from a module to a form. The code is in this style: > > Private priVar as Boolean > > Public Property Get pubVar() as Boolean > pubVar = priVar > End Property > > Public Property Let pubVar(nv as Boolean) > priVar = nv > > 'Do stuff to form > End Property > > When I run the code, I get an error about the variable not being defined. > It highlights the reference to priVar in the Let method and every other time > that I reference it in the Let method. It does not give me this error in the > Get method, nor did I ever get this error when the code was in the module. > Needless to say, it has me stumped. Anyone have any idea what I did wrong? > > -- > Chris Lieb > UPS CACH, Hodgekins, IL > Tech Support Group - Systems/Apps "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message fwiw, I've removed the normal little, right-pointing blue arrow on the news:6104844E-63EB-4C02-85BA-61E6DD3A3013@microsoft.com... >I figured it out after forcing VB to do a full compile. It is because I >was > declaring the variables after I had already declared some other > properties. toolbar and have replaced it with one that shows a slightly larger, right-pointing blue arrow that always does a full compile... as well as clearing the checkbox on "Tools/Options/General" that says "Compile on Demand". Setting VB up this way will give you fewer "surprises". > I hate how anal VB is about where things are placed and in what order they That's funny. I don't find it anal at all to place all private variables in > appear. C# would care less and allow me to declare each private variable > right above its public property declaration. Oh well, one more > peculiarity > to get used to, I guess. > > Chris the declarations section. If C# truly allows things like this then why's everyone saying that VB generates spaghetti code? Sounds like keeping stuff where it belongs is the first step away from spaghetti. fwiw, I've seen just as much (if not more) junk C#/B# code as I have junk VB code. It's not the tool, it's the author. VB Classic Rules the Win32/Desktop world. -- Ken Halter - MS-MVP-VB - http://www.vbsight.com DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm Sign up now to help keep VB support alive - http://classicvb.org/petition Please keep all discussions in the groups..
Other interesting topics
|
|||||||||||||||||||||||