VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save VBA in .dvb during run time to keep key in data

11 REPLIES 11
Reply
Message 1 of 12
awie_tech
610 Views, 11 Replies

Save VBA in .dvb during run time to keep key in data

I'd develop autocad vba to automatically draw our complete drawing but cannot keep our key in data during run time. Could anyone please help me on this ?? I've spent alot of time on this.
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: awie_tech

do you want to save the data or just display it after rouitne is run?

John
wrote in message news:5936528@discussion.autodesk.com...
I'd develop autocad vba to automatically draw our complete drawing but
cannot keep our key in data during run time. Could anyone please help me on
this ?? I've spent alot of time on this.
Message 3 of 12
borgunit2003
in reply to: awie_tech

Depending on what kind of data you are referring to, you can save to a text file or save to the registry as a few suggestions.

http://mechcad-insider.blogspot.com/
Message 4 of 12
Anonymous
in reply to: awie_tech

"Key" ??

If you are trying to dynamically "hard code" a "serial number" or the like
into your .dvb at runtime, check out "VBE"

Here is a sample from help:
Sub Example_VBE()
' This example uses the VBA IDE extensibility model to dynamically
' create a VBA subroutine. After running this example, see the first
line of code
' in the VBA IDE code window to see a new subroutine. Then
' remove the new subroutine before continuing.

Dim VBEModel As Object
Dim newRoutine As String

Set VBEModel = VBE ' Get the VBE object

' Define new subroutine to be added. This could be created dynamically
from user feedback.
newRoutine = "Sub Dynamic_Procedure()" & vbCrLf
newRoutine = newRoutine & vbTab & "MsgBox ""New subroutine.""" & vbCrLf
newRoutine = newRoutine & "End Sub" & vbCrLf

' Insert new subroutine
VBEModel.CodePanes(1).CodeModule.InsertLines 1, newRoutine

MsgBox "A new subroutine was added called Dynamic_Procedure."
End Sub
Message 5 of 12
awie_tech
in reply to: awie_tech

My scenario is.. I'd made a user data with default value 0 for textbox or ..value=false for checkbox & optionbutton. Actually my requirement is very simple. User will open original project with default value then they will key in such dimension of object then click commandbutton to draw object base on their input.. To complete complete drawing, user have to key in alot of data. It is important to us to keep all key in data or checkbox or option button to keep track & not to redo & redo it again.

I'm trying to attach one of the file but warned error.

I'm using just a simple autocad vba. A lot of recommended code did'nt explore.

anyway.. thanks you guys for your feedback.
Message 6 of 12
Anonymous
in reply to: awie_tech

Check out "SaveSetting" & "GetSetting" in VBA help. There is sample code for
both in help. They work well for setting up defaults on a given machine.

Gary
Message 7 of 12
DwgToolbox
in reply to: awie_tech

This is what I use to save userform info:
'add this to a command button
Dim ctl As Control
For Each ctl In Controls
' Next line skips certain controls.
Select Case TypeName(ctl)
Case "PictureBox", "Image", _
"Line", "Shape", "Timer", _
"CommandButton", "Label"
Case Else
' Saves the control's value to the registry.
SaveSetting "SaveFormSettings", _
"Values", ControlName(ctl), ctl
End Select
Next ctl

Then use GetSetting to read the data as Gary McMaster suggested. I read GetSetting at UserForm_Initialize.

www(dot)DwgToolbox(dot)com
Message 8 of 12
awie_tech
in reply to: awie_tech

I FAILED TO figure it out about savesetting & getsetting as Gary or DwgToolBox advise. I see you all are far more advance than me. Could you guys please made example in my attach partial program ?? Pleaseee.. at least to keep One of the textboxes after run time.
Message 9 of 12
awie_tech
in reply to: awie_tech

He..He..
Maybe I ask too much from you guys. Anyway.. Thanks for all your support..
Message 10 of 12
Anonymous
in reply to: awie_tech

Paste the code below into the indicated subs of the .dvb you supplied. It
will save the contents of first two text boxes to the registry each time the
contents of the text boxes are updated. I chose the "AfterUpdate" event, it
could be a different event if you like.

The values that are saved to the registry will be loaded into the "TL" &
"skh" text boxes each time the "Pvessel" form is activated. You could also
choose a different way to do that ... maybe a "Refresh" button instead of
"UserForm_Activate"

I chose the following names for the "GetSetting" & "SaveSetting" functions.
They can be almost anything. Use whatever makes the most sense to you or
your successor.

appname = "Pvessel_App"
section = "SU_Defaults" (Startup defaults)
key = The name of the textbox with "_Textbox" appended
default = equals the values you had displayed on your form

Private Sub UserForm_Activate()

Me.TL.Text = GetSetting(appname:="Pvessel_App", section:="SU_Defaults",
key:="TL_Textbox", Default:="1130")
Me.skh.Text = GetSetting(appname:="Pvessel_App", section:="SU_Defaults",
key:="skh_Textbox", Default:="1000")

End Sub

Private Sub TL_AfterUpdate()

SaveSetting "Pvessel_App", "SU_Defaults", "TL_Textbox", Me.TL.Text

End Sub

Private Sub skh_AfterUpdate()

SaveSetting "Pvessel_App", "SU_Defaults", "skh_Textbox", Me.skh.Text

End Sub
Message 11 of 12
awie_tech
in reply to: awie_tech

My Dear Mr. Gary..

CHEERS!!!..
This have solve one of My MAJOR problems.. What can I do to repay you.. Thank you very..very much..
Message 12 of 12
Anonymous
in reply to: awie_tech

You're welcome. Glad I could help.

You should also investigate the "DeleteSetting" statement. It will allow you
to clean up after yourself (the registry) if you decide to change
Application names or Key names etc.

There are also some pitfalls when coding inside of event handlers. Please
see "Guidelines for Writing Event Handlers" in VBA help.

As I mentioned, there are other events that may be better suited to your app
than the "After_Update" event. "UserForm_Deactivate", for example, might be
a better (faster) place to save your settings. You could write the settings
all at once when the user is finished with the form instead of doing them
one at a time as in "After_Update".

Good luck.

Gary

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost