473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Constant - InDebugMode

Instead of having Public Variables all over my code, I have decided to make
a class called "CONSTANT"
and move them all into it.

Public Class Constants
Private Const strMiro = "MIRO" ' This example Works
Private Const boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error

The error I get is that it underlines the
System.Diagnostics.Debugger.IsAttached() with a blue line and says
"constant expression is required". I cant seem to find how to fix this in
google nor msdn.

I have that variable, cause i want certain things to happen when I am
running my app thru the debugger vs, running
the exe when it is in "release" mode. So this way I can do a quick If Else
Endif statement to do certain things.
-Unless there is an easier way ? :)

Thanks,

Miro

Sep 23 '06 #1
3 1403
Miro,
Have you tried ReadOnly?
Private Readonly boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error
A Const is a value that is known at compile time.

Readonly is like a constant in that the value itself cannot change, however
it is different in that it value is computed at runtime.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Miro" <mi******@golden.netwrote in message
news:ex**************@TK2MSFTNGP04.phx.gbl...
Instead of having Public Variables all over my code, I have decided to
make a class called "CONSTANT"
and move them all into it.

Public Class Constants
Private Const strMiro = "MIRO" ' This example Works
Private Const boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error

The error I get is that it underlines the
System.Diagnostics.Debugger.IsAttached() with a blue line and says
"constant expression is required". I cant seem to find how to fix this in
google nor msdn.

I have that variable, cause i want certain things to happen when I am
running my app thru the debugger vs, running
the exe when it is in "release" mode. So this way I can do a quick If
Else Endif statement to do certain things.
-Unless there is an easier way ? :)

Thanks,

Miro
Sep 23 '06 #2
Yes it did help,
and it makes sence now.

Thank you

Miro

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
message news:C1**********************************@microsof t.com...
Miro,
Have you tried ReadOnly?
> Private Readonly boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error

A Const is a value that is known at compile time.

Readonly is like a constant in that the value itself cannot change,
however it is different in that it value is computed at runtime.

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Miro" <mi******@golden.netwrote in message
news:ex**************@TK2MSFTNGP04.phx.gbl...
>Instead of having Public Variables all over my code, I have decided to
make a class called "CONSTANT"
and move them all into it.

Public Class Constants
Private Const strMiro = "MIRO" ' This example Works
Private Const boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error

The error I get is that it underlines the
System.Diagnostics.Debugger.IsAttached() with a blue line and says
"constant expression is required". I cant seem to find how to fix this
in google nor msdn.

I have that variable, cause i want certain things to happen when I am
running my app thru the debugger vs, running
the exe when it is in "release" mode. So this way I can do a quick If
Else Endif statement to do certain things.
-Unless there is an easier way ? :)

Thanks,

Miro

Sep 23 '06 #3
Miro wrote:
Instead of having Public Variables all over my code, I have decided to make
a class called "CONSTANT" and move them all into it.

Public Class Constants
Private Const strMiro = "MIRO" ' This example Works
Private Const boolInDebugMode As Boolean =
System.Diagnostics.Debugger.IsAttached() 'Gets error
Firstly, I don't think the above will achieve what you want.
The class is Public and accessible throughout your code, /but/ the
Constants /within/ that class are Private and accessible only within
that Class. Make them Public.

Secondly, I would suggest either using a Module to contain all of these,
or make your "Constants" Shared (that's probably implicit, but see
below). This means you don't need an /instance/ of the Constants class
anywhere (or pass one around); you can just code

If Constants.InDebugMode Then

Lastly, I would recommend using ReadOnly Properties over Constants.
"Constants" have a nasty habit of /changing/ over time and, by using
properties, you remove the need to recompile everything that uses that
"Constant".

So, from your code, you wind up with

Public Class Constants

Public Shared ReadOnly Property Miro() As String
Return "MIRO"
End Property

Public Shared ReadOnly Property InDebugMode() As Boolean
Get
Return System.Diagnostics.Debugger.IsAttached
End Get
End Property

End Class

HTH,
Phill W.
Sep 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrea M. Segovia | last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300 server (IP35) running IRIX 6.5.20m. Make test reported one test error, which I narrowed down to .../lib/ExUtils/t/Constant.t...
6
by: fctk | last post by:
hello, i'm trying to compile this small program: int main(void) { unsigned long int max; max = 4000000000;
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
3
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5...
25
by: galapogos | last post by:
Hi, I'm trying to compare an array of unsigned chars(basically just data without any context) with a constant, and I'm not sure how to do that. Say my array is array and I want to compare it with...
33
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is...
18
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
7
by: John Koleszar | last post by:
Hi all, I'm porting some code that provides compile-time assertions from one compiler to another and ran across what I believe to be compliant code that won't compile using the new compiler. Not...
7
by: Hendrik Schober | last post by:
Hi, this #include <string> class test { typedef std::string::size_type size_type; static const size_type x = std::string::npos; }; doesn't compile using either VC9 ("expected constant...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.