Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Checking if registry key exists?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-20-2008, 02:32 AM
Senior Member
 
Join Date: Sep 2008
Posts: 161
Default Checking if registry key exists?

I want to save my application settings to the registry. I want to check if keys exist and create a key if they don't.

It's easy to do it for one key only with errorlabel:
Code:
Sub Loadsettings
ErrorLabel(KeyNotFound)
TxtServerPath.Text=Registry.GetValue(Regpath,
"ServerURL")
Return
KeyNotFound:
 Registry.CreateSubKey(
"",Regpath)
 Registry.SetStringValue(Regpath,
"ServerURL","http://ayvegh.com/~nico/")
End Sub
But if there is more than one entry (it's for the whole skin + all the settings), it makes much less safe. Let's say only 1 of the entries is missing. Using this method, we would have to rewrite every registry entry to the default value, thus erasing the user's settings.

Is there a "FileExist" for the registry keys?
Reply With Quote
  #2 (permalink)  
Old 10-20-2008, 10:59 AM
Basic4ppc Veteran
 
Join Date: Feb 2008
Location: Hilversum, The Netherlands
Posts: 295
Awards Showcase
Beta Tester 
Total Awards: 1
Default

What if you made a 2nd sub which checks this for you?

Code:
Sub Global
      key = 
"Software\My Application"
End Sub 

Sub Loadsettings

    CheckReg(
"ServerURL","http://ayvegh.com/~nico/")
End Sub

Sub CheckReg(What,Value)
  reg.New1
  reg.RootKey(reg.rtCurrentUser)
  ErrorLabel(NotCreatedYet)
  
msgbox("The value is: " & reg.GetValue(key,What))
  
return
NotCreatedYet: 
'creates the subkey if it didn't exist
  reg.CreateSubKey(Value,key&"\"&What)
  
msgbox("The key was created.")    
End Sub
BTW you might want to check the code, I'm not sure if
reg.CreateSubKey(Value,key&"\"&What)
is the correct way
Reply With Quote
  #3 (permalink)  
Old 10-21-2008, 04:23 AM
Senior Member
 
Join Date: Sep 2008
Posts: 161
Default

That wouldn't work because errorlabel ends the sub. That's why Loadsettings is the last thing I do in App_start
Reply With Quote
  #4 (permalink)  
Old 10-21-2008, 06:30 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Did you try it?
I think it should work properly.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
CASE - checking for a range ? TWELVE Questions (Windows Mobile) 1 06-21-2008 09:00 PM
How can I know if an object exists? jesb4ppc Questions (Windows Mobile) 7 05-20-2008 11:57 AM
SQL Table Exists? tsteward Questions (Windows Mobile) 3 05-02-2008 01:18 PM
Checking available fonts? MitchDabo Questions (Windows Mobile) 5 02-10-2008 11:43 PM
checking textbox string derez Questions (Windows Mobile) 13 10-25-2007 12:58 PM


All times are GMT. The time now is 04:22 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0