Click here to Skip to main content
14,734,263 members
Home » Discussions » C#
   

C#

 
Questioncrystal reports problem after installing the application. Pin
praveenkumar_vittaboina10-Jun-09 5:57
Memberpraveenkumar_vittaboina10-Jun-09 5:57 
AnswerRe: crystal reports problem after installing the application. Pin
Tom Deketelaere10-Jun-09 6:19
professionalTom Deketelaere10-Jun-09 6:19 
QuestionChecking a registry key exists Pin
Martin3108810-Jun-09 5:21
MemberMartin3108810-Jun-09 5:21 
AnswerRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 5:45
MemberHenry Minute10-Jun-09 5:45 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 5:57
MemberMartin3108810-Jun-09 5:57 
GeneralRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 6:07
MemberHenry Minute10-Jun-09 6:07 
GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 6:35
MemberMartin3108810-Jun-09 6:35 
GeneralRe: Checking a registry key exists Pin
Henry Minute10-Jun-09 7:16
MemberHenry Minute10-Jun-09 7:16 
I do not use the registry any more, or very rarely, so I have had to go back and look at some of my old code.

The only obviously different things that I used to do is as below.

string myAppSaveDataSubKey = @"software\MyApp\SaveData"; <=== use a variable. saves having to keep typing it in and possible typos
using (RegistryKey MyRegKey = Registry.LocalMachine.OpenSubKey(myAppSaveDataSubKey)) <== using 'using' saves having to remember 'close'
{
    if (MyRegKey == null)  <=========== Check == null instead of != null
    {
        RegistryKey CreateMyRegKey = Registry.LocalMachine.CreateSubKey(myAppSaveDataSubKey);
        CreateMyRegKey.SetValue("Currency", 0);
        string OptCurrency = "0";
    }
    else
    {
        string OptCurrency = MyRegKey.GetValue("Currency").ToString(); <== you need to load OptCurrency anyway so don't 'else' it
    }
}


which used to work OK for me.

The only other thing you might consider is to use CreateSubKey instead of OpenSubKey. This has the advantage of creating the subkey if it doesn't exist, and simply opening it for writing if it does.

Hope some of this is useful. Smile | :)

Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

GeneralRe: Checking a registry key exists Pin
Martin3108810-Jun-09 7:28
MemberMartin3108810-Jun-09 7:28 
GeneralRe: Checking a registry key exists Pin
Martin3108811-Jun-09 0:57
MemberMartin3108811-Jun-09 0:57 
Questioncheckedlistbox - save checked items for future run Pin
havejeet10-Jun-09 4:50
Memberhavejeet10-Jun-09 4:50 
AnswerRe: checkedlistbox - save checked items for future run Pin
Manas Bhardwaj10-Jun-09 4:51
professionalManas Bhardwaj10-Jun-09 4:51 
AnswerRe: checkedlistbox - save checked items for future run Pin
Rajesh R Subramanian10-Jun-09 5:01
professionalRajesh R Subramanian10-Jun-09 5:01 
Questiontaking null instead of value Pin
KIDYA10-Jun-09 4:01
MemberKIDYA10-Jun-09 4:01 
AnswerRe: taking null instead of value Pin
Tom Deketelaere10-Jun-09 4:05
professionalTom Deketelaere10-Jun-09 4:05 
AnswerRe: taking null instead of value Pin
Colin Angus Mackay10-Jun-09 6:04
MemberColin Angus Mackay10-Jun-09 6:04 
GeneralRe: taking null instead of value Pin
KIDYA11-Jun-09 19:35
MemberKIDYA11-Jun-09 19:35 
QuestionSQL Database is not saved after data inserted!! Pin
Zohair8310-Jun-09 3:25
MemberZohair8310-Jun-09 3:25 
AnswerRe: SQL Database is not saved after data inserted!! Pin
EliottA10-Jun-09 3:57
MemberEliottA10-Jun-09 3:57 
GeneralRe: SQL Database is not saved after data inserted!! Pin
Zohair8310-Jun-09 4:26
MemberZohair8310-Jun-09 4:26 
AnswerRe: SQL Database is not saved after data inserted!! Pin
DaveyM6910-Jun-09 4:33
professionalDaveyM6910-Jun-09 4:33 
GeneralRe: SQL Database is not saved after data inserted!! Pin
Zohair8310-Jun-09 7:05
MemberZohair8310-Jun-09 7:05 
GeneralRe: SQL Database is not saved after data inserted!! Pin
DaveyM6910-Jun-09 7:11
professionalDaveyM6910-Jun-09 7:11 
QuestionCom Port [modified] Pin
sahu.shikha10-Jun-09 3:09
Membersahu.shikha10-Jun-09 3:09 
AnswerRe: Com Port Pin
Manas Bhardwaj10-Jun-09 3:23
professionalManas Bhardwaj10-Jun-09 3:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.