×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

SW API and the Registry

SW API and the Registry

SW API and the Registry

(OP)
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
www.nov.com

RE: SW API and the Registry

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
<http://www.esoxrepublic.com/devtools/>
This is a module to add to VB6 or VBA project with functions to get access to registry.
 

batHonesty may be the best policy, but insanity is a better defense.bat
http://www.EsoxRepublic.com-SolidWorks API VB programming help

RE: SW API and the Registry

(OP)
TheTick,

Excellent information! Thank you so much.

Tobin Sparks
www.nov.com

RE: SW API and the Registry

(OP)
Howdy Matt,
Man - I can't hide anything. How am I going to do any magic winky smile .

Tobin Sparks
www.nov.com

RE: SW API and the Registry

(OP)
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

RE: SW API and the Registry

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)

RE: SW API and the Registry

(OP)
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. smile

Thanks

Tobin Sparks
www.nov.com

RE: SW API and the Registry

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)

RE: SW API and the Registry

(OP)
handleman,

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

Thanks so much for looking at this

Tobin Sparks
www.nov.com

RE: SW API and the Registry

(OP)
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

RE: SW API and the Registry

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)

RE: SW API and the Registry

(OP)
handleman,

Okay - are you messing with me now smile . 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. smile If not please let me know - I do want to get it right.

Thanks

Tobin Sparks
www.nov.com

RE: SW API and the Registry

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.

RE: SW API and the Registry

(OP)
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
www.nov.com

RE: SW API and the Registry

Been busy.  New son born yesterday.

RE: SW API and the Registry

(OP)
TheTick,

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

Enjoy

Tobin Sparks
www.nov.com

RE: SW API and the Registry

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.

 

RE: SW API and the Registry

(OP)
TheTick,

Thanks for your input. I really appreciate it.

I guess I'm learning this backwards smile . 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 smile . 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 smile . That doesn't always make me happy either smile .

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

Tobin Sparks
www.nov.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources