Well here we are back again and I hope you have fully understood my Getting Starting in VBA.
Now for some serious stuff:
First we will create a tool to draw rectangles – hang on! - what if we only want to draw three sides or two sides, our tool would need to cater for this – Here it is :
Public Sub DrawRectangle(DRLLPnt As Point, DRXLen As Double, DRYLen As Double, _ DRLayer As String, DRColor As Integer, DRBottom As Boolean, DRTop As Boolean, _ DRRight As Boolean, DRLeft As Boolean)
' This routine will create a rectangle of lines with the designated layer and color
On Error Resume Next
' It will make the layer if it does not exist using Tools.MakeLayer
Tools.MakeLayer DRLayer, DRColor, "Continuous"
' Dimension the other three point around the rectangle
Dim DRLRPnt As Point
Dim DRULPnt As Point
Dim DRURPnt As Point
' Calculate the other three points around the rectangle
Set DRLRPnt = IntelliCAD.Library.CreatePoint(DRLLPnt.x + DRXLen, DRLLPnt.y, 0)
Set DRULPnt = IntelliCAD.Library.CreatePoint(DRLLPnt.x, DRLLPnt.y + DRYLen, 0)
Set DRURPnt = IntelliCAD.Library.CreatePoint(DRULPnt.x + DRXLen, DRULPnt.y, 0)
'Dimension the line object
Dim objDRLine As IntelliCAD.Line
' Now draw the lines using the start and end points that we calculated and set the layer and color
' Bottom Line
If DRBottom = True Then
Set objDRLine = IntelliCAD.ActiveDocument.ModelSpace.AddLine(DRLLPnt, DRLRPnt)
With objDRLine
.Layer = DRLayer
.Color = vicByLayer
.Update
End With
End If
' Left Line
If DRLeft = True Then
Set objDRLine = IntelliCAD.ActiveDocument.ModelSpace.AddLine(DRLLPnt, DRULPnt)
With objDRLine
.Layer = DRLayer
.Color = vicByLayer
.Update
End With
End If
' Right Line
If DRRight = True Then
Set objDRLine = IntelliCAD.ActiveDocument.ModelSpace.AddLine(DRLRPnt, DRURPnt)
With objDRLine
.Layer = DRLayer
.Color = vicByLayer
.Update
End With
End If
' Top Line
If DRTop = True Then
Set objDRLine = IntelliCAD.ActiveDocument.ModelSpace.AddLine(DRULPnt, DRURPnt)
With objDRLine
.Layer = DRLayer
.Color = vicByLayer
.Update
End With
End If
End Sub
Now lets look at this a little closer “Public Sub DrawRectangle ( with variable stuff in here )” should be no problems – BUT – what is a Boolean?
Well, it's just like an answer that is either True or False that you can set or test. It really comes from the Boolean Truth Tables that programmers use – more on this later.
Notice we have used a _ at the end of each line between the parenthesis, it just tells VBA there’s more on the next line to read.
The Error trapping is simple – and has been previously covered – OK – I won’t bring it up again!
Hang on – What! we are using Tools within Tools? – YES – no need to reinvent the wheel and this gives us certainty that this part of code has been tested.
After Dim we create the other point around the rectangle using ICAD’s Library CreatePoints object that we need an x, y, and z – well we can do without the z but I just put in it anyway.
Even though we are drawing 4 lines I have only Dim 1 line object because we can reuse it.
Now we bring in the Boolean and if it is set to true the line will be drawn so you can see we can set any one of these to draw or not and either create a u shape if we like or any other combination.
We already know how to add a circle and a line is not much different only use the AddLine method.
What’s with the With? – well you can use with objectname and .Property = ??? to save you retyping the objectname over and over.
Next installment I will show you how to use the tool.
------------------
Regards
John Finlay
[This message has been edited by John Finlay (edited 08-03-2001).]
#2
When you copy and paste the DrawRectangle Tool just make sure the underscore is at the end of the line in the arguments area ( between the parenthesis) because it is hard to align the code in the forum.
Now lets get started using out tool to draw a window in elevation with a central mullion.
Here’s the Code:
Sub WindowElevSingleMullion()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
On Error Resume Next ' error trap
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Input Window Sizes using InputBox method
HorizontalDist = InputBox("Input Window Width <X> ", "Window Sizes")
VerticalDist = InputBox("Input Window Height <Y> ", "Window Sizes")
' Input Frame Size using InputBox method
FrameThk = InputBox("Input Frame Thickness", "Window Sizes")
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
' Calculate glass sizes
HorizontalGlass = ((HorizontalDist - (FrameThk * 3)) / 2) ' Horizontal glass size
VerticalGlass = (VerticalDist - (FrameThk * 2)) ' Vertical glass size
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
' Calculate the second Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HorizontalGlass, LLPnt.y, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
End Sub
There is only about 17 lines of original code and unfortunately there’s nothing really new I can talk about – only to say that the InputBox and the MsgBox can be used as either a Sub or a Function.
I am going on holiday for a week – lucky ME!
While I’m away someone may like to write the code to draw a door in elevation using our DrawRectangle tool and post it here – Oh boy a challenge! – remember we can stop drawing a line using False instead of True.
When I return we will get rid of those annoying InputBoxes that flash on and off on our screen and start using Forms to control the user interface, along with some extra Error trapping.
------------------
Regards
John Finlay
Now lets get started using out tool to draw a window in elevation with a central mullion.
Here’s the Code:
Sub WindowElevSingleMullion()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
On Error Resume Next ' error trap
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Input Window Sizes using InputBox method
HorizontalDist = InputBox("Input Window Width <X> ", "Window Sizes")
VerticalDist = InputBox("Input Window Height <Y> ", "Window Sizes")
' Input Frame Size using InputBox method
FrameThk = InputBox("Input Frame Thickness", "Window Sizes")
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
' Calculate glass sizes
HorizontalGlass = ((HorizontalDist - (FrameThk * 3)) / 2) ' Horizontal glass size
VerticalGlass = (VerticalDist - (FrameThk * 2)) ' Vertical glass size
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
' Calculate the second Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HorizontalGlass, LLPnt.y, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
End Sub
There is only about 17 lines of original code and unfortunately there’s nothing really new I can talk about – only to say that the InputBox and the MsgBox can be used as either a Sub or a Function.
I am going on holiday for a week – lucky ME!
While I’m away someone may like to write the code to draw a door in elevation using our DrawRectangle tool and post it here – Oh boy a challenge! – remember we can stop drawing a line using False instead of True.
When I return we will get rid of those annoying InputBoxes that flash on and off on our screen and start using Forms to control the user interface, along with some extra Error trapping.
------------------
Regards
John Finlay
#3
There are two areas that you can program in VBA :
Modules – this is where we write our code for our programs and we have been using these for our applications to date.
Class Modules – There are two specific types of classes, the first is a UserForm Module and the other is a Class Module. Yes a UserForm (I will call these forms from now on) is a specific type of class module, and you cannot run a form from ICAD, we use code in a Module to activate the form. A class module is where we create our own objects (more on this later) and they also cannot be run from within ICAD.
Form Modules enhance the user interface for our application. First I must explain Events because that is what forms are all about – an Event is something that happens that may include a user or can be driven by the program. User events are things like a mouse click or double click while program events are things like displaying a form, button or image without user selection.
To insert a Form in an application, open the VBA IDE and select the desired drawing in the Project Window (upper left window) then select Insert->UserForm from the pull down menu. That wasn’t that hard was it! – the only problem the name is UserForm1 and we want to have our own name. Remember we changed the name of our Modules by editing the Name in the properties window and guess what? Yes its just the same for forms. We will call our form frmWindowElev (note we must use one word) just like modules, subroutine and function names. I use the prefix frm so that I know that it is a form I’m working on. When the form is created, the name appears in the Project Window and Property Window – we will now change the caption of our form by highlighting the name “UserForm1” along side Caption in the Properties Window and type Window Elevations. As we type you will notice the caption on the form change. There are many properties that we can change and more on these later.
With the form selected press F5 and the blank form will be displayed in ICAD then just click on the X on the upper right of our blank form to close it and return to the IDE. You can change the size of the form by dragging the handles on the edge/corner of the form in the IDE.
When a form is displayed, we are shown a new form called Toolbox which contains all the standard Controls that we can place on our form. If the Toolbox form disappears, just click on a blank part of the form and the Toolbox will appear. To place a control on our form simply click and drag a control from the toolbox onto our form – in this instance we will drag a CommandButton (a little blank square on our Toolbox form) to the bottom of our form.
When we let go of our CommandButton, it is still highlighted and the name CommandButton1 appears in the Properties Window; this allows us to change the name of our CommandButton by highlighting the name CommandButton1 and typing in cmdEnd. To change the name on the button type End adjacent to the Caption in the Properties Window, you can see the name change as you type. Adjacent to Accelerator type E and the E in End will be underlined to allow the user to type Alt+e to activate the button when the form is displayed.
To add code behind our End button just double click on it and a code window will appear and some code will appear
Private Sub cmdEnd_Click()
End Sub
Now just type End as shown below:
Private Sub cmdEnd_Click()
End
End Sub
To return back to our form just double click on WindowElev in the Project Window or select the form icon above the Project Window.
Now highlight the form by clicking on a blank spot on the form then press F5 to display the form in ICAD.
To close our form click on End and the form will close and return to the IDE.
Next we will add some more controls and finish the user interface
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
Modules – this is where we write our code for our programs and we have been using these for our applications to date.
Class Modules – There are two specific types of classes, the first is a UserForm Module and the other is a Class Module. Yes a UserForm (I will call these forms from now on) is a specific type of class module, and you cannot run a form from ICAD, we use code in a Module to activate the form. A class module is where we create our own objects (more on this later) and they also cannot be run from within ICAD.
Form Modules enhance the user interface for our application. First I must explain Events because that is what forms are all about – an Event is something that happens that may include a user or can be driven by the program. User events are things like a mouse click or double click while program events are things like displaying a form, button or image without user selection.
To insert a Form in an application, open the VBA IDE and select the desired drawing in the Project Window (upper left window) then select Insert->UserForm from the pull down menu. That wasn’t that hard was it! – the only problem the name is UserForm1 and we want to have our own name. Remember we changed the name of our Modules by editing the Name in the properties window and guess what? Yes its just the same for forms. We will call our form frmWindowElev (note we must use one word) just like modules, subroutine and function names. I use the prefix frm so that I know that it is a form I’m working on. When the form is created, the name appears in the Project Window and Property Window – we will now change the caption of our form by highlighting the name “UserForm1” along side Caption in the Properties Window and type Window Elevations. As we type you will notice the caption on the form change. There are many properties that we can change and more on these later.
With the form selected press F5 and the blank form will be displayed in ICAD then just click on the X on the upper right of our blank form to close it and return to the IDE. You can change the size of the form by dragging the handles on the edge/corner of the form in the IDE.
When a form is displayed, we are shown a new form called Toolbox which contains all the standard Controls that we can place on our form. If the Toolbox form disappears, just click on a blank part of the form and the Toolbox will appear. To place a control on our form simply click and drag a control from the toolbox onto our form – in this instance we will drag a CommandButton (a little blank square on our Toolbox form) to the bottom of our form.
When we let go of our CommandButton, it is still highlighted and the name CommandButton1 appears in the Properties Window; this allows us to change the name of our CommandButton by highlighting the name CommandButton1 and typing in cmdEnd. To change the name on the button type End adjacent to the Caption in the Properties Window, you can see the name change as you type. Adjacent to Accelerator type E and the E in End will be underlined to allow the user to type Alt+e to activate the button when the form is displayed.
To add code behind our End button just double click on it and a code window will appear and some code will appear
Private Sub cmdEnd_Click()
End Sub
Now just type End as shown below:
Private Sub cmdEnd_Click()
End
End Sub
To return back to our form just double click on WindowElev in the Project Window or select the form icon above the Project Window.
Now highlight the form by clicking on a blank spot on the form then press F5 to display the form in ICAD.
To close our form click on End and the form will close and return to the IDE.
Next we will add some more controls and finish the user interface
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#4
If you have been following my discussion you should have the following form in your IDE

We will be enhancing our form to display the sizes we need for our window and the form shown below uses Combo Boxes from our toolbox to allow easy selection using a mouse rather than typing in the window sizes. The names cbo??? Is just my naming convention for a combo box just like cmd??? Is a command button.

Drag three labels and three combo boxes to our form and one command button. Alter the captions of the labels as per above – you can leave them named Label1, 2 3 etc.
Name the combo boxes as per the names I have used to ensure the code aligns with the names of these variables.
We have already added code to the End command button so if we double click on the End button and copy and paste the code below:
Name the cmdDraw command button and alter the caption to suit.
Private Sub cmdDraw_Click()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
' Hide the frmWindowElev
Me.Hide
' First stage error trap
On Error Resume Next
' Second stage error trap
'Advise user if there are no selected values and redisplay the form
If cboWidth.Value = "" Or cboHeight.Value = "" Or cboFrame.Value = "" Then
MsgBox "You MUST Select Values for ALL Sizes", vbCritical, "Error - Windows Elevations Form"
Me.Show
End If
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Obtain the selected sizes from the form
HorizontalDist = CDbl(cboWidth.Value)
VerticalDist = CDbl(cboHeight.Value)
FrameThk = CDbl(cboFrame.Value)
'********* Below - Same Code as WindowElevSingleMullion Subroutine ****************
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
' Calculate glass sizes
HorizontalGlass = ((HorizontalDist - (FrameThk * 3)) / 2) ' Horizontal glass size
VerticalGlass = (VerticalDist - (FrameThk * 2)) ' Vertical glass size
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
' Calculate the second Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HorizontalGlass, LLPnt.y, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
End
End Sub
Private Sub UserForm_Initialize()
'This is the UserForm Initialize subroutine that is read prior to the
' Form being displayed. This is where we can set any standard settings
' for our form such as the most popular frame size.
' set the standard frame size
cboFrame.Value = 2
' populate the combo box with some widths
cboWidth.AddItem 12
cboWidth.AddItem 24
cboWidth.AddItem 36
cboWidth.AddItem 48
cboWidth.AddItem 60
cboWidth.AddItem 72
cboWidth.AddItem 84
' populate the combo box with some heights
cboHeight.AddItem 36
cboHeight.AddItem 48
cboHeight.AddItem 60
cboHeight.AddItem 72
cboHeight.AddItem 84
cboHeight.AddItem 94
' populate the combo box with some Frame
cboFrame.AddItem 2
cboFrame.AddItem 3
cboFrame.AddItem 4
End Sub
That completes the code we need to get our window form working.
In the Initialize sub you can alter the values to suit your needs and you can set the cboWidth and cboHeight values to your preferred defaults as per the cboFrame.
In the Draw Sub I have added some additional error trapping to make sure that the user has entered values in all the combo boxes. I have used the Or operand in the If statement and the code reads “this Or this Or this” to find out if any statements are True and then run the code inside the If statement. I cheated and used the code from our previous WindowElevSingleMullion Subroutine an noted this.
Note the use of the Me word to hide or show the form, and you can use the full name of the form if you like. Me is a reserved word and is used extensively in Class Modules to refer to an instance of the Class.
As you can see the command buttons have Click events and the main form has an Initialization event to automatically port information into the combo boxes without user input. See, I told you forms are all about events!
Our Window Elevations form can only be used for two panes of glass and next we will add to this form to make it more commercially acceptable with more panes of glass including standards for window sizes on another form. Oh Oh forms within forms that use file handling to store our standards –Yes – Just got more interesting.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au

We will be enhancing our form to display the sizes we need for our window and the form shown below uses Combo Boxes from our toolbox to allow easy selection using a mouse rather than typing in the window sizes. The names cbo??? Is just my naming convention for a combo box just like cmd??? Is a command button.

Drag three labels and three combo boxes to our form and one command button. Alter the captions of the labels as per above – you can leave them named Label1, 2 3 etc.
Name the combo boxes as per the names I have used to ensure the code aligns with the names of these variables.
We have already added code to the End command button so if we double click on the End button and copy and paste the code below:
Name the cmdDraw command button and alter the caption to suit.
Private Sub cmdDraw_Click()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
' Hide the frmWindowElev
Me.Hide
' First stage error trap
On Error Resume Next
' Second stage error trap
'Advise user if there are no selected values and redisplay the form
If cboWidth.Value = "" Or cboHeight.Value = "" Or cboFrame.Value = "" Then
MsgBox "You MUST Select Values for ALL Sizes", vbCritical, "Error - Windows Elevations Form"
Me.Show
End If
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Obtain the selected sizes from the form
HorizontalDist = CDbl(cboWidth.Value)
VerticalDist = CDbl(cboHeight.Value)
FrameThk = CDbl(cboFrame.Value)
'********* Below - Same Code as WindowElevSingleMullion Subroutine ****************
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
' Calculate glass sizes
HorizontalGlass = ((HorizontalDist - (FrameThk * 3)) / 2) ' Horizontal glass size
VerticalGlass = (VerticalDist - (FrameThk * 2)) ' Vertical glass size
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
' Calculate the second Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HorizontalGlass, LLPnt.y, 0) ' glass lower left point
Tools.DrawRectangle LLPnt, HorizontalGlass, VerticalGlass, "Glass", 3, True, True, True, True ' draw glass
End
End Sub
Private Sub UserForm_Initialize()
'This is the UserForm Initialize subroutine that is read prior to the
' Form being displayed. This is where we can set any standard settings
' for our form such as the most popular frame size.
' set the standard frame size
cboFrame.Value = 2
' populate the combo box with some widths
cboWidth.AddItem 12
cboWidth.AddItem 24
cboWidth.AddItem 36
cboWidth.AddItem 48
cboWidth.AddItem 60
cboWidth.AddItem 72
cboWidth.AddItem 84
' populate the combo box with some heights
cboHeight.AddItem 36
cboHeight.AddItem 48
cboHeight.AddItem 60
cboHeight.AddItem 72
cboHeight.AddItem 84
cboHeight.AddItem 94
' populate the combo box with some Frame
cboFrame.AddItem 2
cboFrame.AddItem 3
cboFrame.AddItem 4
End Sub
That completes the code we need to get our window form working.
In the Initialize sub you can alter the values to suit your needs and you can set the cboWidth and cboHeight values to your preferred defaults as per the cboFrame.
In the Draw Sub I have added some additional error trapping to make sure that the user has entered values in all the combo boxes. I have used the Or operand in the If statement and the code reads “this Or this Or this” to find out if any statements are True and then run the code inside the If statement. I cheated and used the code from our previous WindowElevSingleMullion Subroutine an noted this.
Note the use of the Me word to hide or show the form, and you can use the full name of the form if you like. Me is a reserved word and is used extensively in Class Modules to refer to an instance of the Class.
As you can see the command buttons have Click events and the main form has an Initialization event to automatically port information into the combo boxes without user input. See, I told you forms are all about events!
Our Window Elevations form can only be used for two panes of glass and next we will add to this form to make it more commercially acceptable with more panes of glass including standards for window sizes on another form. Oh Oh forms within forms that use file handling to store our standards –Yes – Just got more interesting.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#5
Hello John,
It is me again I have a problem that I can't figure out. I checked out my spelling and stuff and look into some other things but I can't get this error to go away. I am getting a Compile Error ByRef argument type mismatch. It highlights the VerticalDist in the Draw the ouline of the window using out Tools. I don't know how to fix it. I plan on getting some reference books so i can learn more about the progra but if you could help me out here I would like it very much.
Thanks again
It is me again I have a problem that I can't figure out. I checked out my spelling and stuff and look into some other things but I can't get this error to go away. I am getting a Compile Error ByRef argument type mismatch. It highlights the VerticalDist in the Draw the ouline of the window using out Tools. I don't know how to fix it. I plan on getting some reference books so i can learn more about the progra but if you could help me out here I would like it very much.
Thanks again
#6
tooldesigner,
Check in the Private Sub_Draw
1) Dim VerticalDist As Double
2) VerticalDist = CDbl(cboHeight.Value)
The cboHeight.Value is a variant and I have used the VBA Conversion Function CDbl() to change this variant to a Double that we use in our Tools.DrawRectangle Sub.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
Check in the Private Sub_Draw
1) Dim VerticalDist As Double
2) VerticalDist = CDbl(cboHeight.Value)
The cboHeight.Value is a variant and I have used the VBA Conversion Function CDbl() to change this variant to a Double that we use in our Tools.DrawRectangle Sub.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#8
tooldesigner,
When you double click on the Draw button in the Window Elevations Form, VBA will automatically goto the Form Code window and insert:
Private Sub cmdDraw_Click()
End Sub
Sorry I told you "Check in the Private Sub_Draw"
For storage of VBA code, forms etc. - there are two places:
1/ CommonProjects.vbi - this is a common storage file that is referenced by all IntelliCAD drawings. In the IDE project window you will always see CommonProjects.
2/ DrawingName.vbi - this is where all the code, forms and class modules are stored for a particular drawing.(DrawingName is your Drawing Name) Also under the DrawingName in the IDE Project window you will see References, expanding this will display References to CommonProjects.vbi and this is how all drawings automatically use code in the CommonProjects; it is automatically referenced by VBA.
You can send a DrawingName.vbi file to another PE user and when they save a drawing with the same name as your drawing's name, they will have access to your VBA macros. Also the code (providing it is not password protected)
You can save each individual module or form by highliting it in the project window, then select File->Export File from the pull-down menu.
Also to retrieve select File->Import File from the pull-down menue in the IDE.
Trust this helps
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
[This message has been edited by John Finlay (edited 08-26-2001).]
When you double click on the Draw button in the Window Elevations Form, VBA will automatically goto the Form Code window and insert:
Private Sub cmdDraw_Click()
End Sub
Sorry I told you "Check in the Private Sub_Draw"
For storage of VBA code, forms etc. - there are two places:
1/ CommonProjects.vbi - this is a common storage file that is referenced by all IntelliCAD drawings. In the IDE project window you will always see CommonProjects.
2/ DrawingName.vbi - this is where all the code, forms and class modules are stored for a particular drawing.(DrawingName is your Drawing Name) Also under the DrawingName in the IDE Project window you will see References, expanding this will display References to CommonProjects.vbi and this is how all drawings automatically use code in the CommonProjects; it is automatically referenced by VBA.
You can send a DrawingName.vbi file to another PE user and when they save a drawing with the same name as your drawing's name, they will have access to your VBA macros. Also the code (providing it is not password protected)
You can save each individual module or form by highliting it in the project window, then select File->Export File from the pull-down menu.
Also to retrieve select File->Import File from the pull-down menue in the IDE.
Trust this helps
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
[This message has been edited by John Finlay (edited 08-26-2001).]
#9
We have had a bit of a break from our windows elevation program and now we will extend our program into a more commercially viable program by adding the following features:
1) Give the user the ability to set their own default window and frame sizes via a form.
2) Add a glass/window standards form to allow the user to place the maximum glass sizes and other data that we want our program to use without user input by making the program calculate the number of window panes and sizes from standards.
3) Automate the program from a pull-down menu or toolbar button.
Item 1 above
Giving the user the ability to set their own defaults will speed execution - for example the project may have all the same height windows and standard frame thickness, with the user only needing to alter the window width.
All variables in VBA have scope that only remains when the program is running. Ending our routine clears out any values stored and we need a storage and retrieval method for our defaults and standards. There are many methods to store and retrieve data from databases, spreadsheets, text files and even in drawings themselves.
We will be using text files because it is available to all users, is very fast and is easy to program from VBA.
What you need to know to use Text Files from VBA:
You can create, write, read and append to Text Files providing you have a pointer (called a Handle) to it. The Handle is issued by the operating system and is stored as a Long variable. To create a Text File from VBA use the four steps below:
Step A
Obtain the next free file handle
FileHandle = FreeFile
Step B
Open a file to Write in sequential access
Open "Path and Name of File" For Output Access Write As FileHandle
Step C
To add information to our newly created Text File:
Print #FileHandle, Variable Name
Step D
To Close the File after Writing our variable name in it:
Close FileHandle
To read from a Text File substitute Steps B and C above with Steps B and C below:
Step B
Open a file to Read in sequential access
Open "Path and Name of File" For Input Access Read As FileHandle
Step C
To read information to our newly created Text File:
Input #FileHandle, Variable Name
We need to write and read three variables “cboHeight”, “cboWidth” and “cboFrame” in the Text File.
To Write to the Text File add a new Command Button on our form labeled cmdDefault with the caption Default as shown below.

Double click on the Default button to display our code window with:
Private Sub cmdDefault_Click()
End Sub
And add the code:
Dim FileHandle As Long
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Write in sequential access
Open "C:\DefaultWindowElev.txt" For Output Access Write As FileHandle
'To add information to our newly created Text File:
Print #FileHandle, frmWindowElev.cboHeight.Value
Print #FileHandle, frmWindowElev.cboWidth.Value
Print #FileHandle, frmWindowElev.cboFrame.Value
'To Close the File after Writing our variable name in it:
Close FileHandle
Lets try it out and see what happens - select the form and F5 to display our form in IntelliCAD. Add sizes for our window height, width and frame then click on the Default button – nothing happened? – now select End.
Using Windows Explorer, look in the C:\ directory and you should see a file named DefaultWindowElev.txt - double click on it and you will see the three sizes you input into our form.
Now try some more defaults in our Windows Elevations form and check these out the Text File DefaultWindowElev.txt
We have carried out the first stage of our defaults by creating a file for our defaults and next we will retrieve these defaults and place them in our form every time the form is initialized. – Stay tuned!
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
1) Give the user the ability to set their own default window and frame sizes via a form.
2) Add a glass/window standards form to allow the user to place the maximum glass sizes and other data that we want our program to use without user input by making the program calculate the number of window panes and sizes from standards.
3) Automate the program from a pull-down menu or toolbar button.
Item 1 above
Giving the user the ability to set their own defaults will speed execution - for example the project may have all the same height windows and standard frame thickness, with the user only needing to alter the window width.
All variables in VBA have scope that only remains when the program is running. Ending our routine clears out any values stored and we need a storage and retrieval method for our defaults and standards. There are many methods to store and retrieve data from databases, spreadsheets, text files and even in drawings themselves.
We will be using text files because it is available to all users, is very fast and is easy to program from VBA.
What you need to know to use Text Files from VBA:
You can create, write, read and append to Text Files providing you have a pointer (called a Handle) to it. The Handle is issued by the operating system and is stored as a Long variable. To create a Text File from VBA use the four steps below:
Step A
Obtain the next free file handle
FileHandle = FreeFile
Step B
Open a file to Write in sequential access
Open "Path and Name of File" For Output Access Write As FileHandle
Step C
To add information to our newly created Text File:
Print #FileHandle, Variable Name
Step D
To Close the File after Writing our variable name in it:
Close FileHandle
To read from a Text File substitute Steps B and C above with Steps B and C below:
Step B
Open a file to Read in sequential access
Open "Path and Name of File" For Input Access Read As FileHandle
Step C
To read information to our newly created Text File:
Input #FileHandle, Variable Name
We need to write and read three variables “cboHeight”, “cboWidth” and “cboFrame” in the Text File.
To Write to the Text File add a new Command Button on our form labeled cmdDefault with the caption Default as shown below.

Double click on the Default button to display our code window with:
Private Sub cmdDefault_Click()
End Sub
And add the code:
Dim FileHandle As Long
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Write in sequential access
Open "C:\DefaultWindowElev.txt" For Output Access Write As FileHandle
'To add information to our newly created Text File:
Print #FileHandle, frmWindowElev.cboHeight.Value
Print #FileHandle, frmWindowElev.cboWidth.Value
Print #FileHandle, frmWindowElev.cboFrame.Value
'To Close the File after Writing our variable name in it:
Close FileHandle
Lets try it out and see what happens - select the form and F5 to display our form in IntelliCAD. Add sizes for our window height, width and frame then click on the Default button – nothing happened? – now select End.
Using Windows Explorer, look in the C:\ directory and you should see a file named DefaultWindowElev.txt - double click on it and you will see the three sizes you input into our form.
Now try some more defaults in our Windows Elevations form and check these out the Text File DefaultWindowElev.txt
We have carried out the first stage of our defaults by creating a file for our defaults and next we will retrieve these defaults and place them in our form every time the form is initialized. – Stay tuned!
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#10
Now we have a file that can save our defaults we need to insert these defaults whenever we run our form.
We will use the initialize event on our form to run code that will fill our cboWidth, cboHeight and cboFrame with the information in our Text File DefaultWindowElev.txt
I already showed you how to set a default value in the initialize event:
' set the standard frame size
cboFrame.Value = 2
We need to remove this default and add the code in its place:
Start New Code ………………………………
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\DefaultWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWindowElev.cboHeight.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboWidth.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboFrame.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End New Code ………………………………
Notice we have added a new variable strInput as a string and used this to Input our values from the Text File – then set our defaults to the form.
You can try this out by selecting some values and then the Default button then End. Next time you run the form it will use these defaults.
The only problem with the initialize event is on first use – when there is no default file to read – VBA will experience an exception error.
To overcome this we must use some error trapping to the initialize event, to test for the existence of our default file prior to running our Open, Read and Close Text File.
Dim strFileExists As String
strFileExists = VBA.Dir("C:\DefaultWindowElev.txt")
If strFileExists <> "" Then
Place our Open, Read and Close Text File Here!
End If
We are using a VBA Function called Dir that returns a string containing the name of a file matching a specified filter. In our case the filter is "C:\DefaultWindowElev.txt" and if the file doesn’t exist Dir returns an empty string.
The full code for our form initialize event:
Start Full Code ………………………………………………………
Private Sub UserForm_Initialize()
'This is the UserForm Initialize subroutine that is read prior to the
' Form being displayed. This is where we can set any standard settings
' for our form.
'Start New Code ........................................
Dim strFileExists As String
strFileExists = VBA.Dir("C:\DefaultWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\DefaultWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWindowElev.cboHeight.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboWidth.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboFrame.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End If
'End New Code ........................................
' populate the combo box with some widths
cboWidth.AddItem 12
cboWidth.AddItem 24
cboWidth.AddItem 36
cboWidth.AddItem 48
cboWidth.AddItem 60
cboWidth.AddItem 72
cboWidth.AddItem 84
' populate the combo box with some heights
cboHeight.AddItem 36
cboHeight.AddItem 48
cboHeight.AddItem 60
cboHeight.AddItem 72
cboHeight.AddItem 84
cboHeight.AddItem 94
' populate the combo box with some Frame
cboFrame.AddItem 2
cboFrame.AddItem 3
cboFrame.AddItem 4
End Sub
End Full Code ………………………………………………………
Next we will set our standards for window pane sizes and alter our code to handle any size window.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
We will use the initialize event on our form to run code that will fill our cboWidth, cboHeight and cboFrame with the information in our Text File DefaultWindowElev.txt
I already showed you how to set a default value in the initialize event:
' set the standard frame size
cboFrame.Value = 2
We need to remove this default and add the code in its place:
Start New Code ………………………………
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\DefaultWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWindowElev.cboHeight.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboWidth.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboFrame.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End New Code ………………………………
Notice we have added a new variable strInput as a string and used this to Input our values from the Text File – then set our defaults to the form.
You can try this out by selecting some values and then the Default button then End. Next time you run the form it will use these defaults.
The only problem with the initialize event is on first use – when there is no default file to read – VBA will experience an exception error.
To overcome this we must use some error trapping to the initialize event, to test for the existence of our default file prior to running our Open, Read and Close Text File.
Dim strFileExists As String
strFileExists = VBA.Dir("C:\DefaultWindowElev.txt")
If strFileExists <> "" Then
Place our Open, Read and Close Text File Here!
End If
We are using a VBA Function called Dir that returns a string containing the name of a file matching a specified filter. In our case the filter is "C:\DefaultWindowElev.txt" and if the file doesn’t exist Dir returns an empty string.
The full code for our form initialize event:
Start Full Code ………………………………………………………
Private Sub UserForm_Initialize()
'This is the UserForm Initialize subroutine that is read prior to the
' Form being displayed. This is where we can set any standard settings
' for our form.
'Start New Code ........................................
Dim strFileExists As String
strFileExists = VBA.Dir("C:\DefaultWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\DefaultWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWindowElev.cboHeight.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboWidth.Value = strInput
Input #FileHandle, strInput
frmWindowElev.cboFrame.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End If
'End New Code ........................................
' populate the combo box with some widths
cboWidth.AddItem 12
cboWidth.AddItem 24
cboWidth.AddItem 36
cboWidth.AddItem 48
cboWidth.AddItem 60
cboWidth.AddItem 72
cboWidth.AddItem 84
' populate the combo box with some heights
cboHeight.AddItem 36
cboHeight.AddItem 48
cboHeight.AddItem 60
cboHeight.AddItem 72
cboHeight.AddItem 84
cboHeight.AddItem 94
' populate the combo box with some Frame
cboFrame.AddItem 2
cboFrame.AddItem 3
cboFrame.AddItem 4
End Sub
End Full Code ………………………………………………………
Next we will set our standards for window pane sizes and alter our code to handle any size window.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#11
We have now completed Item 1 in my post dated 08-30-2001.
Now we will start Item 2.
To set our standards for pane sizes we need to place a command button on our Window Elevations form to show our standards form.
Set the Window Elevations form as below:

Name the Standards command button cmdStandards.
Now add another form to your project by selecting the drawing name in the Project Window and select the Insert UserForm button on the VBA IDE toolbar. Setup the form as show below:

Name the form frmWEStandards and set the Caption Window Elevation Standards.
Drag the Text Boxes onto the form and name them txtHP (Horizontal Pane) and txtVP (Vertical Pane). We are using Text Boxes on this form instead of Combo Boxes on the main form because we want to be able to input any size.
Drag a command button to the form and name it cmdSet with the Caption Set.
Return to our Window Elevations main form by double clicking on it in the project window then double click on the new Standards command button to display the code window and add:
Private Sub cmdStandard_Click()
Me.Hide
frmWEStandards.Show
End Sub
We are using a reserved keyword called “Me” which means the active class, in this case the form (Me is used throughout class modules). We also use the hide method sot that Me.Hide removes the form from ICAD’s display.
To display a form we use the Show method and frmWEStandards.Show will display our new Standards form.
Return to our standards form by double clicking on it in the Project Window, then double click on the Set command button to display the code window and add:
Private Sub cmdSet_Click()
Me.Hide
Dim FileHandle As Long
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Write in sequential access
Open "C:\SettingsWindowElev.txt" For Output Access Write As FileHandle
'To add information to our newly created Text File:
Print #FileHandle, frmWEStandards.txtHP.Value
Print #FileHandle, frmWEStandards.txtVP.Value
'To Close the File after Writing our variable name in it:
Close FileHandle
frmWindowElev.Show
End Sub
Insert the following code underneath the End Sub:
Private Sub UserForm_Initialize()
Dim strFileExists As String
strFileExists = VBA.Dir("C:\SettingsWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\SettingsWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWEStandards.txtHP.Value = strInput
Input #FileHandle, strInput
frmWEStandards.txtVP.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End If
This code is similar to the previous Text File code only there is a Me.Hide and frmWindowElev.Show to Hide the Standards form and redisplay the main Window Elevations form.
We are holding our standards in a file named SettingsWindowElev.txt and locating it in the root directory C:\
We can try out our code by highlighting our main form Window Elevations and press F5. When we select our Standards button the new form Windows Elevation Standards is displayed and when we select Set we are returned to the main form.
As you can see it is very easy to show and hide forms with Text File handling ensuring our standard settings are not lost.
All we have to do is add the code to our Draw command button on the main Window Elevations form to complete step 2. For code efficiency we will add loops inside loops so make sure you have a clear mind or you might just go loopy!
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
Now we will start Item 2.
To set our standards for pane sizes we need to place a command button on our Window Elevations form to show our standards form.
Set the Window Elevations form as below:

Name the Standards command button cmdStandards.
Now add another form to your project by selecting the drawing name in the Project Window and select the Insert UserForm button on the VBA IDE toolbar. Setup the form as show below:

Name the form frmWEStandards and set the Caption Window Elevation Standards.
Drag the Text Boxes onto the form and name them txtHP (Horizontal Pane) and txtVP (Vertical Pane). We are using Text Boxes on this form instead of Combo Boxes on the main form because we want to be able to input any size.
Drag a command button to the form and name it cmdSet with the Caption Set.
Return to our Window Elevations main form by double clicking on it in the project window then double click on the new Standards command button to display the code window and add:
Private Sub cmdStandard_Click()
Me.Hide
frmWEStandards.Show
End Sub
We are using a reserved keyword called “Me” which means the active class, in this case the form (Me is used throughout class modules). We also use the hide method sot that Me.Hide removes the form from ICAD’s display.
To display a form we use the Show method and frmWEStandards.Show will display our new Standards form.
Return to our standards form by double clicking on it in the Project Window, then double click on the Set command button to display the code window and add:
Private Sub cmdSet_Click()
Me.Hide
Dim FileHandle As Long
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Write in sequential access
Open "C:\SettingsWindowElev.txt" For Output Access Write As FileHandle
'To add information to our newly created Text File:
Print #FileHandle, frmWEStandards.txtHP.Value
Print #FileHandle, frmWEStandards.txtVP.Value
'To Close the File after Writing our variable name in it:
Close FileHandle
frmWindowElev.Show
End Sub
Insert the following code underneath the End Sub:
Private Sub UserForm_Initialize()
Dim strFileExists As String
strFileExists = VBA.Dir("C:\SettingsWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\SettingsWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, strInput
frmWEStandards.txtHP.Value = strInput
Input #FileHandle, strInput
frmWEStandards.txtVP.Value = strInput
'To Close the File after Reading our variables:
Close FileHandle
End If
This code is similar to the previous Text File code only there is a Me.Hide and frmWindowElev.Show to Hide the Standards form and redisplay the main Window Elevations form.
We are holding our standards in a file named SettingsWindowElev.txt and locating it in the root directory C:\
We can try out our code by highlighting our main form Window Elevations and press F5. When we select our Standards button the new form Windows Elevation Standards is displayed and when we select Set we are returned to the main form.
As you can see it is very easy to show and hide forms with Text File handling ensuring our standard settings are not lost.
All we have to do is add the code to our Draw command button on the main Window Elevations form to complete step 2. For code efficiency we will add loops inside loops so make sure you have a clear mind or you might just go loopy!
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#12
We can complete our Item 2 by double clicking on cmdDraw button and inserting the code below:
Start Code ………………………………………
Private Sub cmdDraw_Click()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
' Hide the frmWindowElev
Me.Hide
' First stage error trap
On Error Resume Next
' Second stage error trap
'Advise user if there are no selected values and redisplay the form
If cboWidth.Value = "" Or cboHeight.Value = "" Or cboFrame.Value = "" Then
MsgBox "You MUST Select Values for ALL Sizes", vbCritical, "Error - Windows Elevations Form"
Me.Show
End If
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Obtain the selected sizes from the form
HorizontalDist = CDbl(cboWidth.Value)
VerticalDist = CDbl(cboHeight.Value)
FrameThk = CDbl(cboFrame.Value)
' retrieve the standards from the file –A--
Dim strFileExists As String
strFileExists = VBA.Dir("C:\SettingsWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
Dim HP As Variant
Dim VP As Variant
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\SettingsWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, HP
Input #FileHandle, VP
'To Close the File after Reading our variables:
Close FileHandle
' convert the text to a double
HP = CDbl(HP)
VP = CDbl(VP)
End If
' ********* Start code to calculate window panes –B--
' calculate the number of panes and sizes
Dim NoHPane As Integer
Dim NoVPane As Integer
Dim HPaneSize As Double
Dim VPaneSize As Double
' Horizontal Claculations
Dim HDlessF2 As Double
HDlessF2 = HorizontalDist - (FrameThk * 2)
If HDlessF2 < HP Then
NoHPane = 1
HPaneSize = HDlessF2
Else
NoHPane = RoundUp(HDlessF2 / (HP + FrameThk))
HPaneSize = (HDlessF2 - ((NoHPane - 1) * FrameThk)) / NoHPane
End If
' Vertical Calculations
Dim VDlessF2 As Double
VDlessF2 = VerticalDist - (FrameThk * 2)
If VDlessF2 < HP Then
NoVPane = 1
VPaneSize = VDlessF2
Else
NoVPane = RoundUp(VDlessF2 / (VP + FrameThk))
VPaneSize = (VDlessF2 - ((NoVPane - 1) * FrameThk)) / NoVPane
End If
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
Dim IH As Integer
Dim IV As Integer
Dim LLVPnt As Point
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Set LLVPnt = LLPnt
For IV = 1 To NoVPane
For IH = 1 To NoHPane
Tools.DrawRectangle LLPnt, HPaneSize, VPaneSize, "Glass", 3, True, True, True, True ' draw glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HPaneSize, LLPnt.y, 0)
Next IH
Set LLPnt = IntelliCAD.Library.CreatePoint(LLVPnt.x, LLVPnt.y + FrameThk + VPaneSize, 0)
Set LLVPnt = LLPnt
Next IV
End
End Sub
Private Function RoundUp(myNum As Double) As Integer
Dim intTemp As Integer
Dim dblRemainder As Double
' obtain the integer portion of the number
intTemp = Fix(myNum)
' find out remainder
dblRemainder = myNum - intTemp
If dblRemainder > 0# Then
RoundUp = intTemp + 1
Else
RoundUp = intTemp
End If
End Function
End Code ………………………………………
When we select the Draw button nothing has changed, we still need to select the lower left corner and obtain the window information from the form.
The change is added when we need to obtain the Window Pane Sizes so we just open our Text File and read the Standards sizes – nothing new here.
Next we need to do some calculations for both the Horizontal and Vertical Window Pane Sizes – we know that all windows have two frame thickness and our available pane size is the window size less two frame thickness in both directions.
We have used an If – Then - Else statement to handle the calculations for either a one pane window or a multiple pane window.
The multiple pane window calculates the number of panes using a Function called RoundUp to convert any Double value into a rounded up Integer by first finding the whole number using the built in VBA method Fix then if there is a remainder add one to the whole number.
Once we find out how many panes we calculate the pane size using:
Available pane size = (HDlessF2)
Less the total size of any additional frames = ((NoHPane - 1) * FrameThk))
Divided by the number of panes. = (NoHPane)
The calculations are the same for both Horizontal and Vertical panes.
Now we want to draw these panes and we first need to draw the outline of the window and as we did before calculate the lower left start point for the first pane.
The inside loop:
For IH = 1 To NoHPane
Tools.DrawRectangle LLPnt, HPaneSize, VPaneSize, "Glass", 3, True, True, True, True ' draw glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HPaneSize, LLPnt.y, 0)
Next IH
This loops from one through to the total number of horizontal panes, drawing a pane and calculating the next lower left point for the next pane.
When we want to draw the next group of panes above the first group we need to calculate a new lower left point and I saved the original start point to calculate this:
Set LLVPnt = LLPnt
The outside loop will loop from 1 to the Vertical number of panes and recalculate a new lower left starting point for the inside loop which draws a new group of panes above the last.
I hope I have explained these loops within loops.
We have covered a substantial amount of code in creating a professional looking VBA routine and all is left to complete our program is to automate our code so it runs from the menu or a toolbar. We will look at this last step next.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
Start Code ………………………………………
Private Sub cmdDraw_Click()
Dim LLPnt As Point
Dim HorizontalDist As Double
Dim VerticalDist As Double
Dim FrameThk As Double
Dim HorizontalGlass As Double
Dim VerticalGlass As Double
' Hide the frmWindowElev
Me.Hide
' First stage error trap
On Error Resume Next
' Second stage error trap
'Advise user if there are no selected values and redisplay the form
If cboWidth.Value = "" Or cboHeight.Value = "" Or cboFrame.Value = "" Then
MsgBox "You MUST Select Values for ALL Sizes", vbCritical, "Error - Windows Elevations Form"
Me.Show
End If
' Locate the lower left corner of proposed window
Set LLPnt = IntelliCAD.ActiveDocument.Utility.GetPoint(, "Lower Left Point ")
' Obtain the selected sizes from the form
HorizontalDist = CDbl(cboWidth.Value)
VerticalDist = CDbl(cboHeight.Value)
FrameThk = CDbl(cboFrame.Value)
' retrieve the standards from the file –A--
Dim strFileExists As String
strFileExists = VBA.Dir("C:\SettingsWindowElev.txt")
If strFileExists <> "" Then
Dim FileHandle As Long
Dim strInput As String
Dim HP As Variant
Dim VP As Variant
'Obtain the next free file handle
FileHandle = FreeFile
'Open a file to Read in sequential access
Open "C:\SettingsWindowElev.txt" For Input Access Read As FileHandle
'To retrieve information from our existing Text File:
Input #FileHandle, HP
Input #FileHandle, VP
'To Close the File after Reading our variables:
Close FileHandle
' convert the text to a double
HP = CDbl(HP)
VP = CDbl(VP)
End If
' ********* Start code to calculate window panes –B--
' calculate the number of panes and sizes
Dim NoHPane As Integer
Dim NoVPane As Integer
Dim HPaneSize As Double
Dim VPaneSize As Double
' Horizontal Claculations
Dim HDlessF2 As Double
HDlessF2 = HorizontalDist - (FrameThk * 2)
If HDlessF2 < HP Then
NoHPane = 1
HPaneSize = HDlessF2
Else
NoHPane = RoundUp(HDlessF2 / (HP + FrameThk))
HPaneSize = (HDlessF2 - ((NoHPane - 1) * FrameThk)) / NoHPane
End If
' Vertical Calculations
Dim VDlessF2 As Double
VDlessF2 = VerticalDist - (FrameThk * 2)
If VDlessF2 < HP Then
NoVPane = 1
VPaneSize = VDlessF2
Else
NoVPane = RoundUp(VDlessF2 / (VP + FrameThk))
VPaneSize = (VDlessF2 - ((NoVPane - 1) * FrameThk)) / NoVPane
End If
' Draw the outline of the window using our Tools
Tools.DrawRectangle LLPnt, HorizontalDist, VerticalDist, "Window", 2, True, True, True, True
Dim IH As Integer
Dim IV As Integer
Dim LLVPnt As Point
' Calculate the first Lower Left Point for glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk, LLPnt.y + FrameThk, 0) ' glass lower left point
Set LLVPnt = LLPnt
For IV = 1 To NoVPane
For IH = 1 To NoHPane
Tools.DrawRectangle LLPnt, HPaneSize, VPaneSize, "Glass", 3, True, True, True, True ' draw glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HPaneSize, LLPnt.y, 0)
Next IH
Set LLPnt = IntelliCAD.Library.CreatePoint(LLVPnt.x, LLVPnt.y + FrameThk + VPaneSize, 0)
Set LLVPnt = LLPnt
Next IV
End
End Sub
Private Function RoundUp(myNum As Double) As Integer
Dim intTemp As Integer
Dim dblRemainder As Double
' obtain the integer portion of the number
intTemp = Fix(myNum)
' find out remainder
dblRemainder = myNum - intTemp
If dblRemainder > 0# Then
RoundUp = intTemp + 1
Else
RoundUp = intTemp
End If
End Function
End Code ………………………………………
When we select the Draw button nothing has changed, we still need to select the lower left corner and obtain the window information from the form.
The change is added when we need to obtain the Window Pane Sizes so we just open our Text File and read the Standards sizes – nothing new here.
Next we need to do some calculations for both the Horizontal and Vertical Window Pane Sizes – we know that all windows have two frame thickness and our available pane size is the window size less two frame thickness in both directions.
We have used an If – Then - Else statement to handle the calculations for either a one pane window or a multiple pane window.
The multiple pane window calculates the number of panes using a Function called RoundUp to convert any Double value into a rounded up Integer by first finding the whole number using the built in VBA method Fix then if there is a remainder add one to the whole number.
Once we find out how many panes we calculate the pane size using:
Available pane size = (HDlessF2)
Less the total size of any additional frames = ((NoHPane - 1) * FrameThk))
Divided by the number of panes. = (NoHPane)
The calculations are the same for both Horizontal and Vertical panes.
Now we want to draw these panes and we first need to draw the outline of the window and as we did before calculate the lower left start point for the first pane.
The inside loop:
For IH = 1 To NoHPane
Tools.DrawRectangle LLPnt, HPaneSize, VPaneSize, "Glass", 3, True, True, True, True ' draw glass
Set LLPnt = IntelliCAD.Library.CreatePoint(LLPnt.x + FrameThk + HPaneSize, LLPnt.y, 0)
Next IH
This loops from one through to the total number of horizontal panes, drawing a pane and calculating the next lower left point for the next pane.
When we want to draw the next group of panes above the first group we need to calculate a new lower left point and I saved the original start point to calculate this:
Set LLVPnt = LLPnt
The outside loop will loop from 1 to the Vertical number of panes and recalculate a new lower left starting point for the inside loop which draws a new group of panes above the last.
I hope I have explained these loops within loops.
We have covered a substantial amount of code in creating a professional looking VBA routine and all is left to complete our program is to automate our code so it runs from the menu or a toolbar. We will look at this last step next.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
#13
Automating our routine is a simple task – all we need is a toolbar with a button or menu item and add the following command:
^C^C^C(command "-VBARUN" "modStartMe.WindowElev" )
The ^C^C^C portion is our old faithful keyboard Ctrl+C command to escape from a command and we use three in row to escape from deeply nested commands.
The rest is just a Lisp statement – Yes I said Lisp! – we use Lisp to start VBA modules and to disable the dialog box from the VBARUN command we place a – (minus) sign in front of it.
Considering we are attempting to offer a professional solution for our users of the fantastic window elevation drawing program, there is one drawback – our code and forms must reside in the Commonprojects.vbi or in an opened drawing for the user to call the program Lisp command.
If the Lisp command is called without access to the module through the IDE - nothing happens!
One way to overcome this is to write a program that adds the module or form to the active drawing prior to running our Lisp command. This will free the commonprojects.vbi for use by all users and we not have to load other drawing(s) in the background with the modules we need.
The next stage of the program is to remove these modules and forms from the drawing’s .vbi file when they are no longer needed to keep the drawing’s .vbi file to a minimum.
Fortunately, for CMS professional users I have just finished the first stage of the program and will test this out on other systems. CMS are prepared to release my program with their next professional version download and I hope to have the second portion to remove modules and forms from the active drawing in the CMS release.
Next I need a real world project and would like to here from any person who would like to have a project developed in VBA.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au
^C^C^C(command "-VBARUN" "modStartMe.WindowElev" )
The ^C^C^C portion is our old faithful keyboard Ctrl+C command to escape from a command and we use three in row to escape from deeply nested commands.
The rest is just a Lisp statement – Yes I said Lisp! – we use Lisp to start VBA modules and to disable the dialog box from the VBARUN command we place a – (minus) sign in front of it.
Considering we are attempting to offer a professional solution for our users of the fantastic window elevation drawing program, there is one drawback – our code and forms must reside in the Commonprojects.vbi or in an opened drawing for the user to call the program Lisp command.
If the Lisp command is called without access to the module through the IDE - nothing happens!
One way to overcome this is to write a program that adds the module or form to the active drawing prior to running our Lisp command. This will free the commonprojects.vbi for use by all users and we not have to load other drawing(s) in the background with the modules we need.
The next stage of the program is to remove these modules and forms from the drawing’s .vbi file when they are no longer needed to keep the drawing’s .vbi file to a minimum.
Fortunately, for CMS professional users I have just finished the first stage of the program and will test this out on other systems. CMS are prepared to release my program with their next professional version download and I hope to have the second portion to remove modules and forms from the active drawing in the CMS release.
Next I need a real world project and would like to here from any person who would like to have a project developed in VBA.
------------------
Regards
John Finlay
Don't want to post a question - email me direct on john@acecad.com.au