Getstring with default value

Getstring with default value

seabrahenrique
Advocate Advocate
366 Views
2 Replies
Message 1 of 3

Getstring with default value

seabrahenrique
Advocate
Advocate

Hello guys!

 

I know that question may sound by a elemental point, but i can't finded a answer here with a vba...

 

So, how can i do someting like that: https://forums.autodesk.com/t5/net/set-a-default-answer-to-editor-getstring/td-p/5677604 in a VBA code?

 

Thanks in adance!

0 Likes
367 Views
2 Replies
Replies (2)
Message 2 of 3

Ed__Jobe
Mentor
Mentor

VBA has the functions GetSetting and SaveSetting. They save values to the registry. This enables you to save an option that you can recover the next time the command is run.

 

GetSetting Function
      

Returns a key setting value from an application's entry in the Windows registry or (on the Macintosh) information in the application’s initialization file.

Syntax

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

The GetSetting function syntax has these named arguments:

Part Description 
appname Required. String expression containing the name of the application or project whose key setting is requested. On the Macintosh, this is the filename of the initialization file in the Preferences folder in the System folder. 
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.

 

 

Alternatively, you can just phrase your GetString prompt to include a default value. Just use the standard AutoCAD prompt string format. The structure for a prompt is "text message\ : \[optional keywords]", e.g.  You should also use GetKeyword to limit user input and make it easier for them to enter a choice.

 

Dim strChoice As String
'use GetKeyword here to se up your options.
strChoice = ThisDrawing.Utilty.GetString(False, "Enter your choice : [default/option1/option2] ")
Case Select strChoice 
  case = vbCr or "default" 
    'perform default action
  case = "option1"
  case = "option2"
End Select

'Combined with GetSetting you could have:
Dim strChoice As String
strChoice = Getsetting("MyApp","MyCommands","Command1")
If strChoice = "" Then strChoice = "default" 
'use GetKeyword here to se up your options.
strChoice = ThisDrawing.Utilty.GetString(False, "Enter your choice : [" & strChoice & "/option1/option2] ")
Case Select strChoice 
  case = vbCr or "default" 
    'perform default action
    SaveSetting("MyApp","MyCommands", "Command1", "default"
  case = "option1"
    'perform option1 action
    SaveSetting("MyApp","MyCommands", "Command1", "option1"
  case = "option2"
    'perform option2 action
    SaveSetting("MyApp","MyCommands", "Command1", "option2"
End Select

 

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 3

seabrahenrique
Advocate
Advocate

Thanks for the answer @Ed__Jobe! I'll test soon.

0 Likes