hairyuga Posted February 20, 2009 Posted February 20, 2009 Hello All, I'm new to this VBA stuff. I'm trying write a routine that will draw a box from the combo box with dimensions. I keep getting a "Out of Range" run time error at the 'draw the entity' code line. I'm not even sure the program works! The box will contain attributes but I haven't gotten that far yet. The box uses the double data type and the combo box contains integers, could this be the problem? Any help would be greatly appreciated. Thanks, Mike 'Combo Box for Panel Sizes Private Sub UserForm_Activate() cmbWidth.AddItem "1'-0""" cmbWidth.AddItem "1'-0 1/2""" cmbWidth.AddItem "1'-1" cmbLength.AddItem "10'-0""" cmbLength.AddItem "10'-0 1/2""" cmbLength.AddItem "10-1""" cmbThickness.AddItem "6""" cmbThickness.AddItem "8""" cmbThickness.AddItem "10""" cmbThickness.AddItem "12""" End Sub 'Create Panel Private Sub cmdCreatePanel_Click() Dim varPick As Variant Dim dblLength As Double Dim dblWidth As Double Dim dblHeight As Double Dim dblCenter(2) As Double Dim objEnt As Acad3DSolid UserForm1.hide 'get the input from user With ThisDrawing.Utility .InitializeUserInput 1 varPick = .GetPoint(, vbCr & "Pick a corner point: ") .InitializeUserInput 1 + 2 + 4, "" dblLength = (cmbLength = "") .InitializeUserInput 1 + 2 + 4, "" dblWidth = (cmbWidth = "") .InitializeUserInput 1 + 2 + 4, "" dblHeight = (cmbHeight = "") End With 'calculate center point from input dblCenter(0) = varPick(0) + (dblLength / 2) dblCenter(1) = varPick(1) + (dblWidth / 2) dblCenter(2) = varPick(2) + (dblHeight / 2) 'draw the entity Set objEnt = ThisDrawing.ModelSpace.AddBox(dblCenter, dblLength, _ dblWidth, dblHeight) objEnt.Update UserForm1.Show End Sub Private Sub cmdExit_Click() Unload Me End Sub Quote
fixo Posted February 20, 2009 Posted February 20, 2009 Welcome on board, Mike There are strings in the combobox so you must convert these to double Take a look at DistanceToReal method in the Help file (change options to your standards, I set 'acEngineering' there) See example(tested on A2008 only) Option Explicit 'Combo Box for Panel Sizes Private Sub UserForm_Activate() cmbWidth.AddItem "1'-0""" cmbWidth.AddItem "1'-0 1/2""" cmbWidth.AddItem "1'-1" cmbLength.AddItem "10'-0""" cmbLength.AddItem "10'-0 1/2""" cmbLength.AddItem "10-1""" cmbThickness.AddItem "6""" cmbThickness.AddItem "8""" cmbThickness.AddItem "10""" cmbThickness.AddItem "12""" End Sub 'Create Panel Private Sub cmdCreatePanel_Click() Dim varPick As Variant Dim dblLength As Double Dim dblWidth As Double Dim dblHeight As Double Dim dblCenter(2) As Double Dim objEnt As Acad3DSolid Me.hide 'get the input from user With ThisDrawing.Utility .InitializeUserInput 1 varPick = .GetPoint(, vbCr & "Pick a corner point: ") .InitializeUserInput 1 + 2 + 4, "" dblLength = .DistanceToReal(cmbLength.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblWidth = .DistanceToReal(cmbWidth.Text, acEngineering) .InitializeUserInput 1 + 2 + 4, "" dblHeight = .DistanceToReal(cmbThickness.Text, acEngineering) End With 'calculate center point from input dblCenter(0) = CDbl(varPick(0)) + (dblLength / 2) dblCenter(1) = CDbl(varPick(1)) + (dblWidth / 2) dblCenter(2) = CDbl(varPick(2)) + (dblHeight / 2) 'draw the entity Set objEnt = ThisDrawing.ModelSpace.AddBox(dblCenter, dblLength, _ dblWidth, dblHeight) objEnt.History = True objEnt.Update ThisDrawing.Regen acActiveViewport Me.Show End Sub Private Sub cmdExit_Click() Unload Me End Sub ~'J'~ Quote
hairyuga Posted February 20, 2009 Author Posted February 20, 2009 Thanks Fixo for the welcome and your input! It works perfect, you are brilliant!!!! I still have attributes to add but I've been stuck on this for a while. Can't wait to learn more about VBA, it's something Ive been wanting to learn for a while! Mike Quote
fixo Posted February 20, 2009 Posted February 20, 2009 Glad if that helps Btw many moons ago I have started to learn VBA from this place: http://www.afralisp.net/ scroll down around half page ... Cheers ~'J'~ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.