OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-02-2012, 18:31
noj noj is offline
Member
 
Join Date: Oct 2011
Location: Sydney
Posts: 31
Default Userform control default value

Hi again,

I've tried everything I can think of.

Can anyone tell me if it's possible to change the default value of a control on a userform with code?

I have a userform with a checkbox which reads 'Save settings as default.'

I have two scrollbars which the user can change when the form is open.

There are two hidden textboxes who's values change based on the scrollbars being moved.

The scrollbars have initial values which I entered in the properties window when designing the userform. These values set the scrollbars to a particular setting when the userform first opens.

The same with the textboxes. They have initial values which correspond to the scrollbars.

What I'd like to do is, if the user clicks the checkbox marked 'Save settings as default.' The initial (default) values of the scrollbars and hidden textboxes change to whatever they are set to by the user at that time.

I can't work out the right code to make this happen. I've tried using the 'Default' property of the controls but I keep getting various errors. Changing the 'Value' property doesn't work either.

I'm assuming it has to be done in 'design mode' somehow?

Any help would be appreciated. Thanks.
Reply With Quote
  #2  
Old 07-02-2012, 00:03
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,782
Blog Entries: 11
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Save User Settings

One of the easiest way to save user preferences is to save the settings to the registry and then to get them on the Initialize event of the form. You can save settings in this format:

SaveSetting appname, section, key, setting

so an example to save what a user has typed into a textbox might look like this:
Code:
SaveSetting "liveFillet", "Preferences", "Radius", txtRadius.Text
When I want to retrieve this setting I use GetSetting which follow this format:

GetSetting(appname, section, key[, default])

so an example of getting the user setting might look like this:
Code:
Private Sub UserForm_Initialize()
     txtRadius.Text = GetSetting("liveFillet", "Preferences", "Radius", ".05")
End Sub
Here are a few examples together for SaveSetting
Code:
    SaveSetting "liveFillet", "Preferences", "Radius", txtRadius.Text
    SaveSetting "liveFillet", "Preferences", "DistanceB", txtDistanceB.Text
    SaveSetting "liveFillet", "Preferences", "Step", txtIncValue
And here we get them:
Code:
    txtRadius.Text = GetSetting("liveFillet", "Preferences", "Radius", ".05")
    txtDistanceB.Text = GetSetting("liveFillet", "Preferences", "DistanceB", ".05")
    txtIncValue.Text = GetSetting("liveFillet", "Preferences", "Step", ".01")
Hopefully that helps,

-Shelby
Reply With Quote
  #3  
Old 07-02-2012, 07:18
noj noj is offline
Member
 
Join Date: Oct 2011
Location: Sydney
Posts: 31
Default

Thanks Shelby,

It's not quite was I was trying to do but I think it would get the same result.

But before I try your method, I just want to make sure I'm being clear about what I'm trying to do. I'll put it in the simplest scenario I can think of:

Say I create a form, stick a simple textbox in it, then over in the properties window I type "50" in the 'Value' property of this textbox, save the form and hit f5 to preview it.

What I see when that form pops up is a simple textbox in the middle with the value "50" sitting in it. If I type over that 50 with a new value - say "100", close the form, then reopen it again by hitting f5, it will always come up with the "50" value, I'm assuming because this is what I put in the 'Value' property when I created it.

That is what I'd like to change - that fundamental 'Value' property - but with code through some user initiated event (like clicking a checkbox with the caption 'Save settings as default').

I'm sorry if you already new what I meant from my first post. I just wanted to be sure before I give up and do it using the method you described.

Cheers,
Jon.
Reply With Quote
  #4  
Old 07-02-2012, 11:27
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,782
Blog Entries: 11
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Remembering Settings

This is exactly what I am describing, an example of how I use this is to remember the location of a form on the screen, so that the next time the macro is run the form is in the last location it was run from.

By default the form opens to the center of the screen, the user moves the form say to the top right of the screen. I capture this location on my Apply button click like so:
Code:
Private Sub cmdApply_Click()
    SaveSetting "liveFillet", "FormLocation", "Top", Me.Top
    SaveSetting "liveFillet", "FormLocation", "Left", Me.Left
    
    Unload Me
End Sub
The next time the user opens the form, I want to restore it to the top right of the screen so I read these setting and move the form to the location:
Code:
Load frmLiveFillet
sngTop = CSng(GetSetting("liveFillet", "FormLocation", "Top", "0"))
sngLeft = CSng(GetSetting("liveFillet", "FormLocation", "Left", "0"))
              
If (sngTop = 0) And (sngLeft = 0) Then
     frmLiveFillet.StartUpPosition = 2
Else
     frmLiveFillet.Top = sngTop
     frmLiveFillet.Left = sngLeft
End If

frmLiveFillet.Show
Similarly this would work for you, the user changes a number in the textbox on your button click you save the setting, then when you load the form use the form Initialize event to load the saved setting.

Hopefully that is a little more clear,

-Shelby
Reply With Quote
  #5  
Old 08-02-2012, 03:54
noj noj is offline
Member
 
Join Date: Oct 2011
Location: Sydney
Posts: 31
Default

Thanks again Shelby. I'll give that a try. Do you know of any good resources for getting to know the type of VBA you have introduced me to in your examples?
Reply With Quote
  #6  
Old 08-02-2012, 11:44
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,782
Blog Entries: 11
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default SaveSetting

The SaveSetting is right from the VBA help file. I would also recomment the CorelDRAW VBA help file. You can find details on how I do this here:

Where to begin with CorelDRAW and VBA

Hope that helps,

-Shelby
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Window Less UserForm Adrian_Juman CorelDRAW/Corel DESIGNER VBA 2 09-04-2011 10:18
Listview control aakkaarr CorelDRAW/Corel DESIGNER VBA 2 26-06-2009 12:02
Userform norbert_ds CorelDRAW/Corel DESIGNER VBA 8 14-01-2008 11:39
Automatically Populating a userform norbert_ds CorelDRAW/Corel DESIGNER VBA 11 15-06-2007 17:41
help: VBA minimize userform = frozen appwindow wOxxOm CorelDRAW/Corel DESIGNER VBA 1 30-04-2006 05:13


All times are GMT -5. The time now is 23:18.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com