Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

SW API and the Registry

Status
Not open for further replies.

Tobin1

Petroleum
Nov 9, 2007
176
Howdy all,

I just need to ask this question before I waste any time trying to do something. I know there are some limitations to the SW API, I'm not sure what they all are.

Is the Windows Registry open to the SW API? Can I use the Windows Registry in a SW macro? [bigears]

Thanks


Tobin Sparks
 
Replies continue below

Recommended for you

Registry is wide open. Ability to write to registry depends on your login privileges. You can always writ to HKCU. Privileges to write to HKLM can vary.

Registry Utilities for VB Projects
<This is a module to add to VB6 or VBA project with functions to get access to registry.


[bat]Honesty may be the best policy, but insanity is a better defense.[bat]
-SolidWorks API VB programming help
 
TheTick,

Thank you for your "Registry Utilities for VB Projects". That must have taken some time and effort to complete. I used it with a SW Macro and it seems to work just fine.

However, I did have to make a little adjustment for my particular application. Since this is way over my head I'm not sure if it's a correction or not. I ran into problems when I tried to save just one character in the Registry. I've not read of such a limitation when saving to the Registry. Also I couldn't consistently save a number that started with a decimal point and I couldn't figure out why. I'm not sure if that is a limitation of the Registry.

Attached is a .bmp file that shows the changes I made for my application.

Thanks again for this effort, I'm sure I'll use it again [thumbsup2]

Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=15961bec-7235-48b6-a68a-03ed723dfc84&file=Reg_Code_Change.bmp
I haven't dug into the rest of the code at all, but the change you've circled (I assume you changed "2" to "1") makes no sense. Left(CStr(varRegData), 1) can never, ever, ever be equal to "&h", because Left(CStr(varRegData), 1) can only return one character. The change you have made works for you, but only because (I assume) you never try to save hex or octal data.

-handleman, CSWP (The new, easy test)
 
handleman,

Thanks for looking at this. I totally agree with you, it doesn't make sense. For some reason an exception was thrown at this point when I tried to save just one character. I was not trying to save hex or octal data. The change stops the exception and that makes me happy. :)

Thanks

Tobin Sparks
 
That statement throws an exception because of this portion:

(Right(CStr(varRegData), Len(Cstr(varRegData)) - <b>2</b>))

if varRegData is only one character, then Len(Cstr(varRegData)) - <b>2</b> equals -1. A negative number is an invalid argument for the "Right" function, so you get an error.


Rather than making the change you made (which renders that entire If statement meaningless and reduces future code functionality/modularity), I would suggest a nested If be added to each instance of that type of code block, for example:

Code:
If Len(CStr(varRegData)) > 2 Then
	[the original "If" statement]
End If



If you don't do this, I would suggest removing that line entirely rather than leaving it in with the change you made.

-handleman, CSWP (The new, easy test)
 
handleman,

WOW - okay I'll look into it and let you know what we decide.

Thanks so much for looking at this

Tobin Sparks
 
handleman,

Thank you for your involvement in this issue. You are absolutely right of course. I looked at it too quickly and thought it wouldn't matter. Thanks for getting me to do the right thing :) . Attached is a .bmp of the additions I made. The original functionality is still intact, although it still makes no sense.

I would think TheTick would be interested in this. Someone with experience understanding this module might want to look this over. I tried to contact Kenneth Ives who claims responsibility for this code but the email was undeliverable.

Thanks Again

Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=09344069-ac50-4287-8700-6a549c5b0245&file=RegEditCodeChange.bmp
You didn't quite stick the If where I meant. You will only enhance functionality if <b>only</b> the offending If statement is nested in another If. This would mean adding three separate If structures.

-handleman, CSWP (The new, easy test)
 
handleman,

Okay - are you messing with me now :) . I have no idea what "if <b>only</b>" means.
The reason I did it this way is because "Case ForceDataType" is the only one of the Cases in the Sub that is declared. The other three are not functioning. This is what the Sub declaration looks like: <Public Sub regCreate_Key_Value(ByVal lngRootKey As Long, ByVal strRegKeyPath As String, _
ByVal strRegSubKey As String, varRegData As Variant, Optional ForceDataType As regValueType_e = regDoNotForce)>
Nothing in the rest of the code declares the other three Cases. Therefore - regDoNotForce is the only one of those Cases set up in the whole code. Doesn't make sense to me but if that's the situation I can live with it.

So - attached is what I'm thinking you're trying to get me to do. I can see the logic behind this. I hope I got it right this time. :) If not please let me know - I do want to get it right.

Thanks



Tobin Sparks
www.nov.com
 
 http://files.engineering.com/getfile.aspx?folder=f01a9eba-95d4-4bca-a8fa-f3e408babe77&file=RegEditCodeChange2.bmp
I think the "<b>" thing was an HTML/TGML mixup. I'll bet handleman was trying to make the word only in bold and used the HTML brackets instead of TGML brackets.
 
TheTick,

OOHH - that makes sense. I thought it might be something like that. So - are you going to weigh-in on this issue?

Thanks

Tobin Sparks
 
TheTick,

WOW - that's fantastic! Congratulations! I would've never guessed you were a female :) . Just Kidding. What did you name him? Is it related to some sort of insect? :)

Enjoy

Tobin Sparks
 
New son named Falco William Henry {Tick}.

In the remarks, you will see that much of the code came from codetoad.com. I did add a few functions, but what you modified is one of the original codetoad functions.

I never had a problem like you describe. The reason is probably because I am always specific with my data types, and the problem code is for untyped data. I recommend you do the same. Get familiar w/ registry data types and be type-specific when writing to registry.

There may be a few other glitches, as well. I know that enumerating keys does not always catch everything. That is a Windows API issue, out of my control.

The reg utilities are offered on an as-is use-at-your-own-risk basis. This is in part because I have not fully tested the entire module. Also because registry is a sensitive thing. I want programmers to be able to see what they are getting into, code-wise.

 
TheTick,

Thanks for your input. I really appreciate it.

I guess I'm learning this backwards :) . First I learned the VB 2005 (.net 3.5). Now I'm going backwards to, I think I read somewhere SW API is now, .net 2.0. .net 3.5 is so easy you don't have to think (or write extra code) about data types. Determining the data type is all done internally. I'm spoiled :) . Hopefully it won't be too long until Sw catches up.

Yes I understand reg utilities is an as-is use-at-your-own-risk module. I'm actually glad it is. It's free! Just thought you would like to be aware of the discovery. I sometimes seem to have a Knack for finding little glitches :) . That doesn't always make me happy either :) .

Thanks for your input, you've been very helpful in many ways


Tobin Sparks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor