473,323 Members | 1,560 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,323 software developers and data experts.

Help me understand this block of code!!!

Hi,
I have pasted the code below.
This sub is getting a temp file name......can someone please explain me this code from the #If DEBUG_IO line.
Any help will be appreciated!!!



private static string getTempFileName(string Type, string Server, string Time, string InputFile)
{
string tempPath = null;
#if DEBUG_IO
tempPath = debugoutput;

if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
#else
tempPath = Path.GetTempPath();
#endif
return string.Format("{0}{1}-{2}-{3}-{4}-{5}", tempPath, Type, Server.Replace(':', '-'), Time.Replace('/', '_').Replace(' ', '_').Replace(':', '_'), Guid.NewGuid().ToString("N"), Path.GetFileName(InputFile));
}
Jun 3 '07 #1
6 963
kenobewan
4,871 Expert 4TB
I'm sorry to ask why you are using a piece of code you don't understand? I suggest spending more time learning asp.net and less time copying and pasting. Just a suggestion.
Jun 3 '07 #2
Agreed!!!!
But at this point of time, my job demands me to understand what is already written and reproduce the same functionality with additional logic and security, for which I cant keep learning the whole episode..but will have to quickly touchbase what that piece of code is doing and proceed with what is expected out of me.
And if am not wrong, this is how any developer would learn what he has not studied...through experience.

So, again...any help will be appreciated.
Jun 3 '07 #3
in my opinion you can not increase the security of code that has less without knowing what the code with less security means and in retrospect how it fucntions...
Jun 4 '07 #4
Frinavale
9,735 Expert Mod 8TB
Hi,
I have pasted the code below.
This sub is getting a temp file name......can someone please explain me this code from the #If DEBUG_IO line.
Any help will be appreciated!!!



private static string getTempFileName(string Type, string Server, string Time, string InputFile)
{
string tempPath = null;
#if DEBUG_IO
tempPath = debugoutput;

if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
#else
tempPath = Path.GetTempPath();
#endif
return string.Format("{0}{1}-{2}-{3}-{4}-{5}", tempPath, Type, Server.Replace(':', '-'), Time.Replace('/', '_').Replace(' ', '_').Replace(':', '_'), Guid.NewGuid().ToString("N"), Path.GetFileName(InputFile));
}
I'm dusting off some cobwebs in the far reaches of my mind but I'll try to help you understand the following code:
Expand|Select|Wrap|Line Numbers
  1. #if DEBUG_IO
  2. ...
  3. #else
  4. ...
  5. #endif
  6.  
The #if directive is read by the pre-compiler.
The pre-processor (pre-compiler) checks your code and splits it up into sections. It's kind of complicated and I learned this a long time ago so please bear with me me here:

Your DEBUG_IO variable will be defined as a Directive....for instance, since you're not in debug mode it would be defined as:
Expand|Select|Wrap|Line Numbers
  1. #define DEBUG_IO False 
  2.  
...you can set this to True and debugging code will be executed....otherwise the debugging code is ignored.

I remember the preprocessing directives in my C and C++ projects I created for multiple platforms: eg. if my program were running on Windows, I would include a certain set of libraries and if it was run on Unix, I would include a completely different set of libraries...

Expand|Select|Wrap|Line Numbers
  1. #define OS 'Windows'
  2. ...
  3. #if OS == 'Windows'
  4. include ...windows libraries
  5. #else 
  6. include ...unix libaries.
  7. #endif
  8.  
  9.  
This way when I compiled my code, the pre-processor would look at my directives and only give to the compiler anything that is relevant...so, anything pertaining to the other operating system would be ignored by the compiler at compile time...

Does this make sense?

Look up Preprocessing and #if directives. It's been a long time since I've used this stuff and don't know if I've been helpful.


-Frinny
Jun 4 '07 #5
Plater
7,872 Expert 4TB
That function seems a bit silly to me.
All it does is decide if you you should use the temp directory or a special debug directory (depending on if you are in debug mode or not)
then it creates a string from that path and all the values passed into it. Not sure why they bothered to pass in all thos variables when that concat'ing could have been done outside the function, but, whatever.
Jun 4 '07 #6
Thanks Guys....that was a lot of help. I'll further dig into it!
Thanks again!
Jun 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: TCMA | last post by:
I am looking for some tools to help me understand source code of a program written in C++ by someone else. Are there any non-commercial, open source C or C++ tools to reverse engineer C or C++...
6
by: baumann | last post by:
hi all, i couldn't understand why code 1) can solve the problem of code 2) has. code 1) template<class T> T* clone(const T* tp) { return tp->clone(); } and change our make_unique member to...
0
by: Hugh Haggerty | last post by:
I need help with VB6 code to direct a WAV file to the computer speaker. Anyone know how to do this?
2
by: DC | last post by:
Hi, I need to asynchronously read from a network (TCP) stream, and I am having trouble with retrieving whole blocks; I get a break in the data block every 1460 bytes which relates to network...
0
by: HegdeS | last post by:
Hi, We are making use of Microsoft Exception Block Code for logging Errors of our ASP.NET Application in to EventLog of Windows. This works fine with Windows 2000 Servers. But when we try to...
8
by: RompStar | last post by:
I am in the learning stages on MS Access and VBA for access, know more about some parts then others. But it dones't look that bad, the VBA, because I am used to VBA for Excel, but I am not sure...
9
by: psantosh12 | last post by:
Hello everyone I need help to develop code for bug tracking system by using servlet and jsp technologies.. If anybody having code please send me the code. Regards Santosh
4
by: psycho007 | last post by:
Hi I have a caller ID software that I would like to change from Microsoft Access database to Mysql and was wondering if somebody could help me. The code i currently have is: Private Sub...
1
by: matan9234 | last post by:
hi, I need help in fitting code of buttons of website to all browsers (right now the code works only for explorer), can you tell me what i need to add to the code for the option of chrome/fire fox...
3
by: Ramesh Jos | last post by:
Hi, While i was going through this code, I couldn't understand what these pieces of code are going to do ... Can anyone help me understand it ?? #!/usr/bin/perl package Person;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.