Prev: Redirection
Next: Correct Way To Wait
From: Nobody on 5 Mar 2010 00:52 "Webbiz" <nospam(a)noway.com> wrote in message news:62e0p512kr5gmvpe7fmbhaaoqirfetnbbl(a)4ax.com... > Conditional Compile Arguments > > Hmm. Never gave that box much thought. Will have to find documentation > on how it is used. It's a place where you can define #Const that apply to the whole project instead of one file. If you use #Const, then it applies only to the file where it appears. If you need to specify more than one constant, use ":". Example: DEBUGLVL = 1 : DEMO = 1 In your code: Private Sub mnuSave_Click() #If DEMO Then MsgBox "This feature is disabled in the demo version." #Else SaveFile #End If End Sub
From: Dee Earley on 5 Mar 2010 04:58 On 04/03/2010 22:57, Karl E. Peterson wrote: > Webbiz wrote: >> In the 19 years I've been using VB (yep, since 1991 when I switched >> from Delphi), not only am I still a novice but I have NEVER, EVER used >> the # debugging code stuff nor found the time to learn about it. > > Wow, well, there was one period where I found conditional compilation > invaluable -- the transition from 16 to 32bits. I could write code > that'd drop into either environment. Very nice. Haven't had a lot of use > for it otherwise, though. Good to know about. I tend to use it for conditional stuff (no surprises :) I have a large number of modules and class shared between projects and can turn on/off certain features like whether to try and localise string variables or just correct fonts, or what the error handler module does (write to log, show message, show link to website to report, end, etc) I also use it for a particular component that I need to be able to insert lots of small chunks of code for ease of development, but never want to be in a released version so the flag is part of the vbp that I double check when I check in the changes. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems
From: ralph on 5 Mar 2010 10:48 On Thu, 04 Mar 2010 16:53:11 -0600, Webbiz <nospam(a)noway.com> wrote: >On Thu, 04 Mar 2010 09:53:03 +0000, Dee Earley ><dee.earley(a)icode.co.uk> wrote: > >>On 03/03/2010 20:14, Webbiz wrote: >>> Over the last months/years, I've been shown some simple approaches to >>> debugging here for which I'm grateful. >> >>Further to the other answers, this page explains some other general >>debugging concepts: >>http://hashvb.earlsoft.co.uk/Debugging > > >Thanks Dee. > >In the 19 years I've been using VB (yep, since 1991 when I switched >from Delphi), not only am I still a novice but I have NEVER, EVER used >the # debugging code stuff nor found the time to learn about it. > >Life just goes by way too fast. Guess now I'd better get to it. > >:-) >Webbiz To add to the list. Originally you talked about line and functional profiling. Both of these are usually implement through 'instrumentation' - ie, adding code to provide a trace. As profiling almost always adds 'Heisenbugs' and to the amount of time to run a test, such intrumentation is normally wrapped with Conditional Compiles allowing you to turn it on or off for particular threads or modules. Probably the most useful application of conditional compile statements is to work around the annoying "case bug" with VB6 Enums. Public Enum E_Junk lJunk As Long sJunk As String End Enum #If 0 Then ' to preserve case Dim lJunk, sJunk #EndIf I also use them in more complex scenarios where I'm trying out different code blocks or paths during development. Normally one can just comment/uncomment code. But if the alternatives are long or exclusive it is often too d*mn easy to forget a line here and there. So I like to place alternatives within discrete blocks and turn them off and on. -ralph
From: Webbiz on 5 Mar 2010 13:38 On Fri, 5 Mar 2010 00:52:29 -0500, "Nobody" <nobody(a)nobody.com> wrote: > >"Webbiz" <nospam(a)noway.com> wrote in message >news:62e0p512kr5gmvpe7fmbhaaoqirfetnbbl(a)4ax.com... >> Conditional Compile Arguments >> >> Hmm. Never gave that box much thought. Will have to find documentation >> on how it is used. > >It's a place where you can define #Const that apply to the whole project >instead of one file. If you use #Const, then it applies only to the file >where it appears. If you need to specify more than one constant, use ":". >Example: > >DEBUGLVL = 1 : DEMO = 1 > >In your code: > >Private Sub mnuSave_Click() > >#If DEMO Then > MsgBox "This feature is disabled in the demo version." >#Else > SaveFile >#End If >End Sub > So if I understand you correctly, you set a Constant that is Global to the whole project in this Conditional Compile Arguments area and then plop them all over your code using # before then name. If you want to activate those chunks of code when the constant = 1, you need to set that value also in the Conditional Compile Arguments (CCA) box, right? When you want to set to false, again you have to change it in the CCA itself, correct? :) Webbiz
From: Webbiz on 5 Mar 2010 13:39
On Fri, 05 Mar 2010 09:58:27 +0000, Dee Earley <dee.earley(a)icode.co.uk> wrote: >On 04/03/2010 22:57, Karl E. Peterson wrote: >> Webbiz wrote: >>> In the 19 years I've been using VB (yep, since 1991 when I switched >>> from Delphi), not only am I still a novice but I have NEVER, EVER used >>> the # debugging code stuff nor found the time to learn about it. >> >> Wow, well, there was one period where I found conditional compilation >> invaluable -- the transition from 16 to 32bits. I could write code >> that'd drop into either environment. Very nice. Haven't had a lot of use >> for it otherwise, though. Good to know about. > >I tend to use it for conditional stuff (no surprises :) >I have a large number of modules and class shared between projects and >can turn on/off certain features like whether to try and localise string >variables or just correct fonts, or what the error handler module does >(write to log, show message, show link to website to report, end, etc) > >I also use it for a particular component that I need to be able to >insert lots of small chunks of code for ease of development, but never >want to be in a released version so the flag is part of the vbp that I >double check when I check in the changes. When you are about to release your code, do you go through and delete all those #conditional snippets or just leave them in there? Webbiz |