Results 1 to 4 of 4

Thread: Add-In Question #3

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    An add-in I've written creates a toolbar containing several buttons. On connection the toolbar is created via msoBarTop and this results in my toolbar being placed by itself on a new toolbar line below the other toolbars of my IDE and that takes up valuable real estate. I can manually move the toolbar, but the next time I start a VB project, my toolbar returns to it's original position. Is there some way for my add-in to store it's position on disconnection, and then retrieve the position and use it the next time it starts up?

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Posts
    81

    Use the savesettings command

    Here is a good descusion on how to save controls settings.

    Hope it helps
    Brooke

    I can’t figure out how to save options in my program take a look at the post entitled Saving Program Options for a better description.
    GiD


    when your program exits, use the SaveSetting command (vb generic) to store application information in the registry. for example, to save the position of the form when the user shuts down the form, use:
    SaveSetting “someApp”,”pos”,”xcoord”,form1.left SaveSetting “someApp”,”pos”,”ycoord”,form1.top and when your form loads again, check the registry for the settings that you previously saved, and apply them to your form: xx=GetSetting(“someApp”,”pos”,”xcoord”) yy=GetSetting(“someApp”,”pos”,”ycoord”)
    form1.left=xx
    form1.top=yy



    Ok...let me sound stupid again.
    Say I want to save the value of a check box and
    the backcolor of a text box. what would the code
    look like them the name of the project is project1
    And the name of the form I am trying to save options
    from is called frmOptions. Help would really be appreciated

    SaveSetting _
    “someApp”,”formsettings”,”Boxsetting”,chkbox.value
    SaveSetting _
    “someApp”,”formsettings”,”Backcolor”,txt1.backcolor



    Is there a resource on the internet(url) where I
    can get a little more info on the subject
    matter...I am just really having a hard time
    understanding how/why that works. Any
    explination to go along with any of the code in
    this thread would (once again really be appreciated Thanks again,
    GiD

    Here’s the text from the VB Help File:
    Saves or creates an application entry in the application’s entry in the Windowsregistry. Syntax SaveSetting appname, section, key, setting The SaveSetting statement syntax has thesenamed arguments:appname - Required.String expression containing the name of the application orproject to which the setting applies. section - Required. String expression containing the name of the section where the key setting is being saved. key - Required. String expression containing the name of the key setting being saved. setting Required.Expression containing the value that key is being set to.

    In the above code: SaveSetting
    “someApp”,”formsettings”,”Boxsetting”,chkbox.value
    SaveSetting
    “someApp”,”formsettings”,”Backcolor”,txt1.backcolor
    someApp = appName
    formsettings = section
    Boxsetting = Key
    txt1.backcolor = Value
    SaveSetting saves your information into the Registry Editor (click on your start button, goto Run and type RegEdit)
    It would look like this:
    Say you have a program called GiDWare Editor (GidWare being the name of your company Say you have a checkbox and you want to save the value of the checkbox when the user clicks OK or when they close a window that sets the color of an object (The only thing important here is that there is a checkbox and you want to save the value. The name of the Application and what it does doesn’t matter.). chkBox is the name of your checkbox.
    Here’s the code to save it.
    Private Sub Form_Unload(Cancel As Integer)
    ‘Save value of chkBox
    SaveSetting “GiDWare”, “ObjectColor”,
    “CurrentColor”, chkBox.Value
    End Sub
    he Application name is “GiDWare” (the name of your program, The Section name is “ObjectColor” (the name of what your saving information about) and the Key is “CurrentColor” (the specifics about what you’re saving.)
    Below is a link to a picture I just made of what
    your registry edito will look like with the
    setting saved as chkBox value = vbChecked
    (vbChecked = 1)
    http://www.geocities.com/Area51/Shad.../regeditor.jpg
    If you notice, the GiDWare setting is located under HKEY_CURRENT_USER\Software\VB and VBA Program Settings\GiDWare\ObjectColor. All of your SaveSetting settings will be saved under ...\VB and VBA Program Settings\... Now, to retrieve your settings, use the GetSettings function.
    Hers’s what the VB Help File says about GettSettings:
    Returns a key setting value from an application’s entry in the Windowsregistry.
    Syntax
    GetSetting(appname, section, key[, default]) The GetSetting function syntax has thesenamed arguments: appname - Required.String expression containing the name of the application or project whose key setting is requested. section - Required. String expression containing the name of the section where the key setting is found. key - Required. String expression containing the name of the key setting to return. default - Optional.Expression containing the value to return if no value is set in the key setting. If omitted, default is assumed to be a zero-length string (“”).
    Remarks
    If any of the items named in the GetSetting arguments do not exist, GetSetting returns the value of default.
    Using GetSettings is pretty much the same a sSave Settings, just think a little backwards. First, Declare a variable to save the setting into once you’ve gotten it:
    Private Sub Form_Load() Dim x x = GetSetting(“GiDWare”, “ObjectColor”, “CurrentColor”, 1)
    If x = 1 Then
    chkBox.Value = vbChecked
    Else
    chkBox.Value = vbUnchecked
    End If
    End Sub

    This will load the value of your setting into the x variable. Then, an If...Then statement compares to see if x is 1, then check the checkbox. If x is 0 then uncheck the checkbox. The 1 at the end of GetSetting is the Default Value. If nothing is retrieved by GetSetting, or their is no key in the registry editor matching what you are looking for, GetSetting will populate x automatically with 1 (or whatever default setting you provide). You can use this for basically any settings you need to save for example:
    Window position (Left, Top, Width, Height), Default Color and Font settings, Etc.
    Hope this helps.

    YES!! Now I understand...THANKS A LOT! Say, did you get that from MSDN 6.0? I have that...guess I need to pay more attention huh? Well anyways, thanks again!



    Glad I could Help.
    -------------------------
    There is never only one right answer. That is the magic of programming.
    -------------------------

  3. #3

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Thanks, but I know about SaveSetting and GetSetting. The problem is that I have no idea how to determine the values to feed into SaveSetting. Note that what I'm doing is creating a toolbar in the VB IDE itself and not in a user-program. In the latter it's a simple matter to find out where things are but I don't know how to do that in the IDE. Let me put it another way via an example. Let's say when you start a project, the Debug toolbar is the 2nd toolbar in the 3rd toolbar row. You then drag it up a row and reposition it so that it's the 1st toolbar in the 2nd row. If you then close VB and restart it, VB knows to place the Debug toolbar as you last left it. So my question is, how do I find out where a user of my Add-In has placed my toolbar.

  4. #4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width