How-to use off-the-shelf software packages to perform power systems analysis

download How-to use off-the-shelf software packages to perform power systems analysis

If you can't read please download the document

Transcript of How-to use off-the-shelf software packages to perform power systems analysis

How-to use off-the-shelf software packages to perform power systems analysis Power systems, modern languages, open source OS, software & programmingContents:
Chapter 1: Spread sheets fundamentals.
Chapter 2: Basic operation and fundamental calculations of power systems analysis.
Chapter 3: Fault calculations.
Chapter 4: Load flow studies.
Appendix A: Using Quickbasis to perform power systems studies.
Appendix B:Using HTML and Javascript to perform power systems studies.
Note: This on-line version of this book does not include the sketches and illustrations.

Chapter 1
Spread sheets fundamentalsIntroduction:
Power systems analysis and calculations can be performed using off-the-shelf spread sheet software packages. The workbook (notebook) can be customized through the addition of menus and other toolbars (or modifying the existing ones). In this book Borland Quattro Pro and Microsoft Excel will be used to demonstrate how spread sheet programs can be modified and customized to become a tool for the electrical power systems analyst. Spread sheet fundamentals:
A standard spread sheet program that operates under DOS/Windows operating system will have the following main parts:
1) The cells of the work sheet: the working area is divided into rectangles (which are called cells), each rectangle is identified by a letter (indicating a column) and a number (indicating a row). The workbook (or notebook as other suppliers of these packages call) will have more than one worksheet (or page). The workbook is a file that can accept user input and then be saved to the hard disk or floppy diskette. The user can move from one worksheet to another, add more worksheets or remove any of them.
2) The menu bar: it will have menu elements and sub-elements that will allow the user to perform the tasks he/she would like to do like having a new worksheet appearing on the screen (on the monitor) in-front of him/her, adding data, formatting it and then saving the file (by giving it a name) or opening an existing file making some modifications to it then saving it.
3) The toolbar: it is a bar with small squares (icons), if any of the icons is pressed the specific task is performed.
4) The data entry box: when the cursor (selector) is on a cell (i.e. a cell is chosen), the content (data) in the cell will appear in this box for the user to change. If the cell is empty, the user can enter the new data, it will appear in this box until he/she presses Enter or click the correct sign (adjacent to this box), after which the data is placed in the, previously, highlighted (chosen) cell.
5) The message box (status bar): it is a box close to the bottom of the screen. When the mouse (cursor) is moved to a command (on the member) of the menu bar or to the icon on the toolbar, a brief description (help tip) of what this command or icon will do is displayed in such a box.
Customizing such types of software packages is achieved through the use of macros and/or programming languages, function of the package itself. A macro is a stored series of keystrokes special keys, commands that can be played back. Macros are created by recording or typing them in. More about macros later in this chapter. The menu bars of spread sheets:
For a typical software package operating under Windows platform on a PC, the following main items may be seen on the main menu of the program: FILE, EDIT, BLOCK, DATA, TOOLS, GRAPH, PROPERTY, VIEW, INSERT and FORMAT. The file entry may have underneath it the following options: NEW (which will give the user a blank i.e. new work book), OPEN (which enables the user to open an existing file - the worksheets - to add to or modify), CLOSE which will cllose the file without saving the changes made from the last SAVE command), SAVE (which will save the document i.e. worksheets including all the changes or additions made up till this point), SAVEAS (save the worksheet on the screen under the name the user will enter at the prompt i.e. in the dialog box), PRINT PREVIEW (will show the user what he will get on the printer, if he gives the command PRINT to the machine), PRINT (will print the range to the printer i.e. producing a hard copy of what is shown on the screen), PAGE SETUP (enables the user to enter the page setup eg. margins, size,...). The last important item that may be found under FILE is Printer Setup (which gives the options to the user to select the printer, the port to which the printer is connected or to redirect to file - rather than to the printer port) Under the EDIT menu, there may be the following sub-menu items: Undo (revert to the condition before the last change/modification/typing,..etc.), Cut (remove the highlighted portion from the working document and put it in another location in the RAM, where it can be put - pasted- into another portion of the current document or a new one), Copy (copies the highlighted portion in the current document into the RAM where it can be used later), Paste (taking what has been copied into the clipboard -RAM- to the current document at the position indicated by the cursor), Clear (delete all highlighted parts), Paste Special (gives the user the options of choosing to paste formula or value only avoid pasting blanks,..etc.), Paste Format (the pasted information will include formatted data), Goto (page, cell, column, row), Search & Replace (searches the first occurrence or all occurrences of the word or data inputted by the user and replace it or them with that or those specified by the user), Define Style (for the different styles eg. normal, currency, heading 1, heading 2,..etc., indicate the properties eg. alignment, format, protection, shading, text colour,..etc.). For the BLOCK menu item, the following can be found underneath it: Move (the user indicated data from which cell range -block- to which block of cells), Copy from which block to which one), Insert (allows the user to enter rows, columns, files & pages), Delete (allows the user to remove full rows, columns or pages), Fill (allows the user to automatically fill blocks, rows or columns with numbers depending on the series selected by the user), Names (allows the user to create names to certain areas - ranges or blocks- of the worksheet to facilitate the manipulation of data, it also allows the user to delete unwanted names or all names), Transpose (exchange columns by rows and vice versa, the user enter the range -from to- that has to be transposed), Move Pages or worksheet (allows the user to move a page from a position to another within the file -set of pages or worksheets- before that specified by the user). Under the menu element, the following subitems: Sort (allows the user to enter the block to be sorted, the sort keys - primary & secondary, column ascending or descending and data i.e. labels -text & values), Form (lets the user creates a form for entering & finding records), Query (allows the user to set the data base block, criteria table & output blocks), Parse (breaks down long labels into individual cells used for example when word processing files are imported int worksheets of spread sheets programs), What-if (allows the user to modify one or two variables in the worksheet and observe the changes in other dependent variables in the worksheet, this feature is very important as an analysis tool to see, lets say, the profit due to the increase or decrease in volume of sales, or due to change in the number of the workforce or in the unit price of the different available products). Under the TOOLS main menu item, the following subitems may be found: Macro which provides the user with the necessary commands to create, run & debug macros; Spell check checks the spelling of the words in the notebook & graphics, Consolidator merges blocks (of cells) thus altering the data with the functions as selected by the user; Define group defines page groups for simultaneous operations on several pages; Combine merges 2 notebook files into one; Extract copies a part of a notebook to a separate file; Update links opens, updates, changes or deletes a notebook links; Analysis tools displays a list of advanced statistical, financial & engineering analysis tools; Speedbar designer allows the user to create his custom speedbar; Advanced math allows the user to access matrix & math tools. Under the GRAPH menu the following may be found: Type which changes the graph type (line, pie, ribbon, 3-D..etc.); Series defines or redefines the spread sheet data (which cells) to be plotted in the graph; Titles allows the user to add a title, subtitle & axis titles to the graph; New creates a new graph from the selected (cells); Edit brings a graph into a graph window ready for editing; Insert places an existing graph as a floating graph on a spread sheet page; Delete erases a graph from an active notebook; Copy copies a graph or selected attributes of a graph to a new or existing graph within the same notebook, what can be copied are graph style (all graph properties), graph , annotation objects or a combination thereof; View displays a full screen view of the graph. Under the PROPERTIES, the following may be found: Current object displays a dialog box for the current object which may be any of a check box, bitmap button, combo box, colour control; Application allows the user to change any of the following application properties display, currency, date/time formats, startup directory, currency/punctuation/date & time format; Active notebook allows the user to determine calculation mode, zoom factor, display of notebook macro library; Active page allows the user to enter page name, line colour, label alignment, display of zeros, default width, borders & gridlines. Under the VIEW menu item, the user may find Normal which allows the user to view the spread sheet as is; Page break preview shows the user where the page ends & allows him to adjust it; Toolbars allows the user to choose the toolbars he wants displayed on the screen like standard toolbar, formatting, chart, control tool box, drawings, forms, picture, Visual Basic,..etc.; Formula bar or Status bar allows the user to show or not show the formula or status bar; Full screen shows the notebook as full screen without any menus, control, tool or status bars; Zoom allows the user to set the magnification percentage of the displayed notebook on the screen (for example from 200% to custom magnification). Under the INSERT menu item, the user may find Cells insert which allows the user to shift cells to the right, shift them to the left, insert an entire row or an entire column; Insert rows inserts a row at the cursor (highlighter); Insert columns inserts a column at the cursor; Worksheet inserts a worksheet and shows as the top sheet on the screen; Chart it gives the user the sequence of dialog boxes that would allow him to insert a chart including chart type (column, bar, line, pie, XY scatter, area, doughnut, surface, cylinder, cone, pyramid,..etc.), range, series, titles (chart, X-axis & Y-axis), axis, guidelines, legend, labels & table; Page break inserts a page break; Function gives the user the choice from function category or function name; Name allows the user to define, paste, create, apply or label a name to a range, Picture inserts a picture from a gallery or inserts a picture file; Object allows the user to insert an object in the worksheet in front of him, as create new (becomes part of the current file) or as create from file (i.e. to later modify, the original application program is opened and the changes are made under the original application program control-DDE). Under the FORMAT, there are: Cells allows the user to format the highlighted cells; Rows allows the user to set the height, hide/ unhide & auto fit; Columns allows the user to set the width, auto fit, hide/ unhide & standard width; Sheet allows the user to rename it, hide/unhide, background; Style which can be modified by the user based on predefined characteristics (parameters in the style name) number appearance, alignment, font, borders, pattern & protection and Autoformat which allows the user to choose a pre formatted style with specific text font types, size, cell background colour, borders,...etc. (the dialog box shows a sample of the preformatted style). The macros:
A macro is a stored series of keystrokes, special keys and commands that can be played back. Macros are created by typing or recording them. Macro commands can be divided into the following categories: keyboard, screen, interactive, program flow, cell, file, command equivalents, DDE, user interface building, object, miscellaneous and analysis tools. The first category can be subdivided into 4 sub-categories: movement keys, function keys, status keys and other and is responsible for the emulation action of the various keys on the keyboard. The second is responsible for the display, the third will enable the user to create macros that display dialog boxes and pause for the user to enter data from the keyboard, the fourth gives the person preparing the macro the ability to loop and branch in a macro, the fifth will affect the data stored in specified cells, the sixth allows the operation on data in files other than the active ones, the seventh will allow the emulation of menu commands, the eighth (Dynamic Exchange) allows the communication with other Windows applications, the ninth allows the person preparing the macro to change the appearance of the menu bar, the tenth allows the macro creator to create/move resize/select/change the properties of objects (blocks, notebooks, graphs, graph objects, dialog boxes objects, floating objects & applications), the eleventh allows the insertion of characters & commands in the macro in addition to a variety of other tasks and finally the twelfth allows the performance of numerical analyses. Macros are the heart of every application, they are the primary method, the user utilizes to pull all his application components together. Macros are used to display dialog boxes, to automate tasks, to duplicate keyboard & mouse actions, change the active menus, affect the screen display, select reposition resize objects, to prompt users for input. Planning before writing a macro may save a lot of time later. If the macro involves menu commands, step through them first, writing down each action involved. If it involves special macro commands, know exactly what the user has to enter as the command arguments after each macro command; its position can affect the macro's behaviour. Certain available application programs uses programming language like Visual Basic for application to customize the look and behaviour of such programs rather than macros. In either case the use of flow chart as part of the planning process can assist the programmer while entering the macro (by typing or recording) or writing the program. A flow chart is a diagram showing the actions & decisions a macro (or a program) steps through while running. Boxes in the chart contain an action the macro performs. Diamonds contain decisions the macro must make to determine the next step. Arrows show where to go after a step is completed. Arrows exiting a diamond have a decision listed next to them dictating the next step. Flow charts do not show actual macro (or programming language statements), they show the planning & logic behind a macro (a module or a program).
When applications are created for the user's specific needs a couple of macros become very important. The first is the startup macro, which runs automatically upon opening the pertinent file. This macro must adjust the user interface tools of the program like the menu bars and tool bars. The second important macro is the exit one, which is responsible for the clean up steps when the user decides to exit or close the application. Such macro will reset the user interface tools to their default i.e. the menu bar and the tool bars will revert to their standard as furnished by the supplier software package. In Quattro Pro, each time the user opens a file (notebook), the software looks for a macro with _NBSTARTMACRO and if is found, the macro is run (executed). The exit macro (in Quattro Pro, it is named _NBEXITMACRO) is run after the command to close the notebook is given. The software branches to that macro and executing it before closing. In Quattro Pro, the user input is usually obtained through the dialog boxes. These are rectangular in shape with labels, push buttons, edit fields and other controls. The other controls are: check box, radio (option) button, spin control, rectangle and group box. The labels clarifies to the user what a control does. The push buttons perform a specific action when the user clicks it the developer (the person designing and writing the macros of the application) determines what that action is based on the user needs. The edit fields are the locations in the dialog boxes where the user types his input (specific information). When the OK push button is clicked by the user, it is such data that get acted upon by the macro. The check box presents a yes or no choice to the user. They are usually placed within group boxes. The option buttons are usually grouped to give the user a mutually exclusive list. The spin control allows the user clicking an arrow to increase or decrease the value it displays or to type a value in. The rectangle allows grouping (in appearance) two or more controls together. A group box contains other controls like radio buttons and check boxes with a title at the top. Link commands (statements) are most of the time attached to controls as link commands indicate to the controls what should happen when the user changes or selects the control. Link command will specify at least three things: event, action, object. The number of things to be specified is function of the control type, for instance a push button will specify three things event (eg. clicked), an action (do macro) and an object (the macro name). The edit field will specify five things: event (eg. valuechanged), an action (eg. send), an object (eg. value), another object (cell address eg. A:C2) and finally another object (eg. value). Most of the times the developer will have a list to pick from: events list, action list and object lists. Sometimes the objects are specified by the developer like a name of a macro or a cell in the notebook where he/she wants the inputted data to be placed in. A control can have more than one link command that has to respond to the same event. The list of link events will have the following options: init (the dialog box is about to appear, initial settings are set using this option), Init complete (it occurs after immediately after all controls have run all link commands that respond to Init, it is only available with dialog boxes themselves), OKExit (the user closes the dialog box, the link command runs before the dialog box closes), CancelExit (the user cancels the dialog box, the link command runs before the dialog box closes), Clicked (the user clicks the control), Right_bdown (the user right-clicks), Left_bdown (the user points to the control and is holding down the left mouse button, releasing the button generates a Clicked event), Doubleclick (theuser double clicks the control), Valuechanged (the user changes the value of the control eg. a text edit field, the event occurs any time the value is changed by user, link or macro command), Activate (the user has chosen the control for manipulation eg. clicking an edit field generates this event, Valuechanged trapped the final result), Deactivate (the user has chosen another control), Enter (the user presses Enter in an edit field), Lineup (the user increases the scroll bar's value by clicking a scroll arrow - available only on scroll bar controls), Linedown (the user decreases the scroll bar's value by clicking a scroll arrow), Pageup (the user increases the scroll bar's value by clicking it between a scroll arrow and the scroll box), Pagedown (the user decreases the scroll bar's value by clicking it between the down scroll arrow and the scroll box), Thumb (the user clicks or drags the scroll bar's scroll box), Editdynamic (the user is inserting or deleting characters in the combo box's edit field, combo box controls only), Trigger (it is used to set link commands that can only be run by other link commands, it can not be generated by any user action), Alarm (the time of day specified in the timer's Alarm Time property has been reached - time controls only), Timer (the amount of time indicated in the timer's Timer Interval property has elapsed). The properties that are available to the developer to change and modify when it comes to the DIALOG BOX (WINDOW) are: the dimensions (specifies the exact size and position of the dialog window), the title (specifies the title of the dialog box, which the user will see), the position adjust (specifies how the dialog box moves when the controlling program window is resized), the grid options (shows or hides a grid and sets the number of pixels between grid lines), the name (it is used to identify the dialog box in macros, link commands and formulas), disabled option (disables all controls in the dialog box) and value (current setting of dialog box). The OK push button control which is a special case of the push button control has the following properties: bitmap(specifies a bit map file to appear on a button), label text (specifies the text appearing on the button), text draw flags (defines the location of label text on the bitmap button), default button (specifies the default button in the dialog box, which button is executed when Enter is pressed), button type (specifies the type of button), dimension (specifies the exact size and position of the bitmap button), hidden choice (specifies whether the bitmap button is visible in the dialog box, it is visible when editing), object ID (specifies the bitmap button's identification number), position adjust (specifies how an attached element moves when the bitmap button is resized), name (used to identify the bitmap button in macros, link commands & formulas), help line (a brief description indicating the purpose of such control), grayed choice (specifies whether the bitmap button can be used, if grayed it can not be used), disabled choice (behaves like grayed but does not dim the control), depend on (specifies the area in the parent program in which the bitmap will appear when the dialog box displays), tab stop (determines whether the bitmap button can be activated by pressing the tab key from the keyboard) , object help (determines the contents of Object help for the selected object), enabled choice (its function is the opposite of disabled), show (its function is the opposite of hidden), value (current setting of bitmap button). The developer can use the field type property to restrict the type of information the user can enter into edit field control (i.e. restrict the type of information the edit field will accept). There five types of fields: integer (restricts user entry to integers, this types adds three more properties: maximum, minimum and default referring to the integers to be inputted by the user), string (this is the default edit field type, it accepts any text a user enters including numbers), real (accepts any number or formula), block (accepts only cell addresses or block coordinates) and hidden (accepts any text but displays a pound (#) sign for each character entered). The edit field properties are: field type (determines the allowable type of input), edit length (specifies the maximum number of characters in the edit field), allow point mode (lets the pointer be used to select a block while a dialog box is displayed), show frame (displays a box around the field), terminate dialog option (if set to yes, pressing Enter triggers the default button -mentioned above), convert text (allows insertion of a new line and tabs in an edit field), dimension (specifies the exact size & position of the edit field), hidden (specifies whether the edit field is visible in the dialog box), object ID (the edit field's identification number), position adjust (specifies how an attached element moves when the edit field is resized), name (is used to identify the edit field in macros, link commands and formulas), help line (a brief description that appears at the bottom of the parent program window), grayed option (specifies whether the edit field can be used or not), disabled option (behaves like grayed but does not dim the control), depend on (specifies the area in the parent program in which the edit field appears when the dialog box is displayed), process value (setting this property to yes lets the macro command {DODIALOG} access the edit field's value), tab stop (determines whether the edit field can be activated by Tab key), object help (determines the contents of Object Help for the selected object), enabled option (it is the opposite of disabled), show (it is the opposite of hidden), value (it is the current setting of the edit field). The label control properties are: label text (inputs text to appear adjacent to a dialog control), label font (determines label format), text draw flags (defines the location of label text adjacent to a dialog box control), dimension (specifies the exact and position of the label text), hidden (specifies whether the label is visible in the dialog box), object ID (it is the label text's identification number), position adjust (specifies how an attached element moves when its parent is resized), name (it is used to identify the label text), grayed option (specifies whether the can be used or not), disabled option (behaves like grayed but does not dim the control), depend on (specifies the area of the parent program in which the label text appears when the dialog box displays), process value (setting this property to yes lets the macro command {DODIALOG} access the label text's value), enabled (the opposite of disabled), show (the opposite of hidden) and value (the current setting of the label text). As can be seen from the aforementioned, certain properties are duplicated between the different types of controls. All the properties that may be found in the dialog box (UI) or in all the different types of controls are: add down button, alarm on, alarm time, allow point mode, attach child, bitmap, button type, convert text, current time, default, default button, depend on, dimension, disabled, draw to right, edit disabled, edit length, enabled, field type, fill color, frame color, grayed, grid option, group text, help line, hidden, history list, interval in units, label font, label text, list, list length, maximum, minimum, name, number of columns, object help, object ID, ordered, parameters, position adjust, process value, rectangle style, resize, selected, selection text, show, show frame, show time, tab stop, terminate dialog, text draw flags, timer on, title, units in milliseconds, value. The other controls that have not been mentioned so far are: bitmap button, color control, combo box, edit integer, file control, horizontal scroll bar, list box, pick list, scroll bar, and time control. A special notebook can be reserved for only macros. The macros stored in such notebook can be accessed from any other notebook. Some of the advantages of storing macros in a library are: it simplifies linked access; it makes easier to keep track of where macros are; the macros will not interfere with the notebook data and vice versa (although the last page iv can always be reserved for macros only); if macros are used for more than one notebook, using a library will save disk space; a separate set of macros can be created for each application or each notebook. Before starting to build an application, the developer should follow the following steps:
1) Planning for an application: which includes determining the tasks that the user would like to accomplish; finding existing features or applications that perform tasks similar to those required by the user and obtain the user's opinion (how to modify these features to suit him best); keeping the application (the set of macros) simple, the user interface (menus and toolbars) easy to use and all the development work well documented, always provide help messages and help lines for the users within the application (if the main user interface elements are not clear enough).
2) Designing an application: during the development process, involve the user always and obtain his/her feedback; keeping all the macros, dialog boxes and menus for a single application organized in one notebook; define and follow a set of rules for naming and storing components of the applications; keeping all the application files in a specific directory; including all pertinent development notes in the application; limiting user access to critical components of the application; restoring the standard settings of the software after the user exits the application. The computer programming languages:
Computer languages are code or statements or functions that control the operation of the personal computer and let it do what the user wants. These languages can broadly classified into procedural (for example Quickbasic) and object oriented (example C++). The basic tasks of any programming language can be summarized into: building loops and decision structures, defining & calling procedures (subroutines or functions), inputting/outputting to devices (printers, keyboard or monitor), inputting/outputting to files (on hard or floppy disks), manipulating and transforming strings (to & from the different structures), displaying graphics images and setting traps for events & errors (making software package more robust). For example in Quickbasic there are statements (approximately 280 of them), functions, keywords and meta-commands. In Visual Basic for applications which come with Microsoft Excel program for example, there are statements (about 87), functions (about 156), methods (about 11), 17 operators, 13 data types, 24 constants and 67 keywords. Procedural languages can be defined as a series of procedures that act upon. It is a set of specific instructions executed one after the other. The data is quite separate from the procedures. A derived type of programming called structured which means breaking down complex tasks into self contained smaller ones. The most commonly used type of programming languages is the object oriented programming (OOP). This type of programming is built on 4 principles: encapsulation, hiding, inheritance (reuse) and polymorphism. The property of being self-contained unit is called encapsulation, the encapsulated unit when is used without (necessarily) knowing how it works is called -hiding.
The creation of (new) user-defined types (classes) offers the encapsulation hiding properties to the program. A new type can be declared from an existing one (thus it is an extension of an existing object). It inherits the properties of the existing type (class) as well as additions to the new object can be made to modify its response and output. Polymorphism means the same name may take many forms but makes the right (expected) thing (through the choice of the right objects). The source code is a file written in one of the programming languages using the appropriate statements, techniques and syntax.
This file is saved in an ASCII format. Most available development packages (programming software) have their own editing environment where the programmer can type/enter his/her source code and then saves the file. The next step would be to make the source code file an executable one, with which the computer can run it from its operating system. In order to achieve this goal, the source code file has to be compiled (the source code file remains as is, but two other files are created the one with .OBJ extension & the executable one with .EXE extension). The programmer can compile the source code file into an executable one at the operating system prompt (by inputting the appropriate command) or from the menu from within the development environment. Thus the compiler is a software that takes the high level language file and converts it into machine language. A library is a collection of linkable files that the programmer creates, are supplied by the compiler or are purchased separately. A function is a block of code that performs a service (adding 2 numbers together or printing a character to a screen). A class is a collection of data and related functions. The programmer may use the linker to create an operable program with libraries using the following steps: he/she prepares the source code file (written in high level language), compiles the source code file and finally links the files with .OBJ extension with the needed libraries to produce an operable program. In C++ language, the main files that are used to produce a program are: the header, methods and implementation. The methods file will refine the functions declared in the header file, the implementation one (having the main function in it) will use the header file (.H extension) & the methods file (.CPP extension) to get the required results from the program. For a short program, it will, typically, have the following components: list of header files, list of global variables & their types, the base class, the definition of the functions declared in the class and finally the main function (the entry point to the program). The main topics of C++ language are: predefined & created classes, pointers & references, overloading functions & operators, creating objects at run time, arguments & return values, containers and templates. The main statements, keywords & functions in C++ language can be classified broadly into: prompts & user input,output to screen or file, control of program flow, looping (iteration) of certain program instruction, operators & trigonometric functions, classes, specifiers, identifiers, pointers & references, constructors and operators. On the other hand, for the Quickbasic (which is a procedural language) the statements, functions and keywords can be classified broadly into: prompts & user input, output to screen or file, control of program flow, subroutines & programs chaining, looping (iterations) operators. Examples to show the syntax of Quickbasic language: INPUT which allows input from keyboard, PRINT prints on screen, IF...THEN allows conditional execution based on the evaluation of the expression following IF. For the C++ language: cin allows input from the keyboard while the program is running, iostream.h (a header file) should be included in the source code file (# include ), cout outputs to the screen, same header file as cin should be include in the source code file, if allows conditional execution based on the evaluation of the expression following the if, switch...case allows conditional execution based on the evaluation of the expression after switch and performs the instructions following the applicable case statement, while repeats a block of statements while a condition a true. Most of the examples using Excel program that will be given in this book use programs that were originally written in Quickbasic language, although slightly modified to suit the programming language provided with Excel (Visual Basic for Applications - VBA). The original programs were writtten in Quickbasic, by the author, they had their own user interface through menu screens and prompts. When they are adapted to the off-the-shelf software packages, the interface of the latter is used instead of the original interface. These original programs were written and given the title "The Series of Short Programs for Power Systems Analysts". Simple examples and analysis in Excel VBA language and Quattro Pro macros:
Excel of Microsoft: Before getting to the examples, a few important definitions and other explanation of control and properties will be presented.
Definition of common terms:
Class module: is a module that contains the definition of a class, including its property & method definitions.
Method: an action that an object performs (on itself).
Collection: an object that contains several other objects.
Event: an action recognized by an object.
Module: a set of declarations followed by procedures. Procedures in a module are classified into functions and subroutines procedures.
Module-level declarations: describe the code in the declaration section of a module. Any code outside a procedure is referred to as module level code. Declarations must be listed first, followed by procedures.
Object: is an element of an application.
Property: is an attribute of an object that defines one of the object's characteristics. Purpose of common commands and statements:
Sub: declares the name, arguments and code that form the body of a Sub procedure.
Private: is used at module level to declare private variables and allocate storage space.
Set: assigns an object reference to a variable or property.
With: executes a series of statements on a single object or a user defined type.
Sheets property: returns a sheets collection that represents all the sheets in the workbook.
Select method: selects the required object.
Range property: return a Range object that represents a cell or a range of cells.
CommandBars property: returns a CommandBars object that represents the software program command bars.
ActiveMenuBar property: returns a CommandBar object that represents the active menu bar in the container application.
Controls property: returns a CommandBarControls object that represents all the controls on the specified command bar or popup control.
CommandBarControls property: is a collection of CommandBarControl objects that represent the command bar controls on a command bar.
Add method: adds an object to a collection.
InputBox method: displays a dialog box for user input, it returns the information entered into the dialog box (replaces Input statement in Quickbasic).
MsgBox function: displays a message in a dialog box, waits for the user to click a button and returns an Integer indicating which button the user clicked.
Print method: prints text in the Immediate pane of the Debug window.
Print #: writes display-formatted data to a sequential file (equivalent to Quickbasic).
Open: enables input/output to a file (equivalent to Quickbasic statement).
Debug object: sends output to Immediate window at run time (it is used in conjunction with Print eg. Debug.Print) Microsoft Excel contents of Controls toolbox: the standard controls included in the controls tool box are: Check box, Text box, Command Button, Radio button, List box, Combo box, Toggle button, Spin button, Scroll bar, Label and Image. Properties of each of the commonly used controls:
1) The properties of the check box that can be set by the developer (or user) are: Accelerator, Alignment, AutoSize, BackColor, BackStyle, BoundValue, Caption, ControlSource, ControlTipText, Enabled, Font object, ForeColor, Height/Width, HelpContextID, LayoutEffect, Left/Top, Locked, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, Picture, PicturePosition, SpecialEffect, TabIndex, TabStop, Tag, TrippleState, Value, Visible & Wordwrap.
2) The properties of the text box: AutoSize, AutoTab, AutoWordSelect, BackColor, BackStyle, BorderColor, BorderStyle, BoundValue, CanPaste, ControlSource, ControlTipText, CurLine, CurTargetX, CurX, DragBehavior, DropButtonStyle, Enabled, EnterFieldBehavior, EnterKeyBehavior, Font object, ForeColor, Height/Width, HelpContextID, HideSelection, IMEMode, IntegralHeight, LayoutEffect, Left/Top, LineCount, Locked, MaxLength, MouseIcon, Multiline, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, PasswordChar, ScrollBArs, SelectionMargin, SelLength, SelStart, SelText, ShowDropButtonWhen, SpecialEffect, TabIndex, TabKeyBehavior, TabStop, Tag, Text, TextAlign, TextLength, Value, Visible, WordWrap.
3) The properties of the command button: Accelerator, AutoSize, BackColor, BoundValue, Cancel, BackStyle, Caption, ControTipText, Default, Enabled, ForeColor, Height/Width, HelpContextID, LayoutEffect, Left/Top, Locked, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, Picture, PicturePosition, TabIndex, TabStop, Tag, TakeFocusOnClick, Value, Visible, WordWrap.
4) The properties of the radio (option) button: Accelerator, Alignment, AutoSize, BackColor, BackStyle, BoundVAlue, Caption, ControlSource, ControlTipText, Enabled, Font object, Forecolor, GroupName, Height/Width, HelpContextID, LayoutEffect, Left/Top, Locked, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, Picture, PicturePosition, SpecialEffect, TabIndex, TabStop, Tag, TripleState, Value, Visible, WordWrap.
5) The properties of the list box: BackColor, BorderColor, BorderStyle, BoundColumn, BoundValue, Column, ColumnCount, ColumnHeads, ColumnWidths, ControlSource, ControlTipText, Enabled, Font object, ForeColor, Height/Width, HelpContextID, IMEMode, IntegralHeight, LayoutEffect, Left/Top, List, ListCount, ListIndex, ListStyle, Locked, MatchEntry, MouseIcon, MousePointer, MultSelect, Name, Object, OldHeight/OldWidth, OldLrft/OldTop, Parent, RowSource, Selected, SpecialEffect, TabIndex, TabStop, Tag, Text, TextColumn, TopIndex, Value, Visible.
6) The Properties of the combo box: AutoSize, AutoTab, AutoWordSelect, BackColor, BackStyle, BorderColor, BorderStyle, BoundColumn, BoundValue, CanPaste, ColumnCount, ColumnHeads, ColumnWidths, ControlSource, ControlTipText, CurTargetX, CurX, DragBehavior, DropButtonStyle, Enabled, EnterFieldBehavior, Font object, ForeColor, Height/Width, HelpContextID, HideSelection, IMEMode, LayoutEffect, Left/Top, LineCount, List, ListCount, ListIndex, ListRows, ListStyle, ListWidth, Locked, MatchEntry, MatchFound, MatchRequired, MaxLength, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, RowSource, SelectionMargin, SelLength, SelStart, SelText, ShowDropButtonWhen, SpecialEffect, Style, TabIndex, TabStop, Tag,Text, TextAlign, TextColumn, TextLength, TopIndex, Value, Visible.
7) The properties of the toggle button: Accelerator, Alignment, AutoSize, BackColor, BackStyle, BoundValue, Caption, ControlSource, ControlTipText, Enabled, Font, ForeColor, Height/Width, HelpContextID, LayoutEffect, Left/Top, Locked, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, Picture, PicturePosition, SpecialEffect, TabIndex, TabStop, Tag, TripleState, Value, Visible, WordWrap.
8) The properties of the spin button: BackColor, BoundValue, ControlSource, ControlTipText, Delay, Enabled, ForeColor, Height/Width, HelpContextID, LayoutEffect, Left/Top, Max/Min, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Orientation, Parent, SmallRange, TabIndex, TabStop, Tag, Value, Visible.
9) The properties of the scroll bar: BackColor, BounValue, ControlSource, ControlTipText, Delay, Enabled, ForeColor, Height/Width, HelpContextID, LargeChange, LayoutEffect, Left/Top, Max/Min, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Orientation, Parent, ProportionalThumb, SmallChange, TabIndex, TabStop, Tag, Value, Visible.
10) The properties of the label: Accelerator, AutoSize, BackColor, BackStyle, BorderColor, BorderStyle, Caption, ControlTipText, Enabled, Font Object, ForColor, Height/Width, LayoutEffect, Left/Top, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, Picture.
11) The properties of the image: AutoSize, BackColor, BackStyle, BorderColor, BorderStyle, ControlTipText, Enabled, Height/Width, LayoutEffect, Left/Top, MouseIcon, MousePointer, Name, Object, OldHeight/OldWidth, OldLeft/OldTop, Parent, PictureAlignment, PictureSizeMode, PictureTiling, SpecialEffect, Tag, Visible. A brief description for the purpose of each of the available properties of the controls contained in the toolbox:
1) Accelerator: sets or retrieves the accelerator key for a control (ctrl + key from keyboard, eg. a or b or c or...etc.).
2) Alignment: specifies the position of a control with respect to its caption, i.e. to its left or to its right.
3) AutoSize: specifies whether an object automatically resizes to display its entire contents in the control (or does not resize and the contents are clipped).
4) AutoTab: specifies whether an automatic tab occurs when a user enters the maximum allowable number of characters into the TextBox control or the text box portion of a ComboBox.
5) AutoWordSelect: specifies whether a word or character is the basic unit used to extend a selection, it specifies how the selection extends or contracts in the edit region of a TextBox or ComboBox.
6) BackColor: specifies the background colour of the object.
7) BackStyle: returns or sets the background style for an object.
8) BorderColor: specifies the color of an object's border.
9) BorderStyle: specifies the type of border used by a control or form.
10) BoundColumn: identifies the source of data in a multicolumn ComboBox or ListBox.
11) BoundValue: contains the value of a control when that control receives the focus.
12) CanPaste: specifies whether the Clipboard contains data that the object support.
13) Caption: descriptive text that appears on an object to describe it.
14) Column: specify one or more items in a ListBox or ComboBox.
15) ColumnCount: specifies the number of columns to display in a ListBox or ComboBox control.
16) ColumnHeads: displays a single row of column headings for list boxes and combo boxes and other similar objects.
17) ColumnWidths: specifies the width of each column in a multicolumn combo or list box.
18) ControlSource: identifies the data location used to set or store the Value property of a control.
19) ControlTipText: specifies text that appears when the user briefly holds the mouse pointer over a control without clicking it.
20) CurLine: specifies the current line of a control.
21) CurTargetX: retrieves the preferred horizontal position of the insertion point in a multiline TextBox or ComboBox.
22) CurX: specifies the current horizontal position of the insertion point in a multiline TextBox or ComboBox.
23) Delay: specifies the delay for the SpinUp SpinDown & Change events on SpinButton or ScrollBar.
24) DragBehavior: specifies whether the system enables the drag-and-drop feature for a TextBox or ComboBox
25) DropButtonStyle: specifies the symbol displayed on the drop button in a combo box , eg. a plain button with no symbol, a down arrow button,...etc.
26) Enabled: specifies whether a control can receive the focus and respond to user generated events
27) EnterFieldBehavior: specifies the selection behaviour when entering a TextBox or ComboBox (selects the entire content i.e. highlights it or leaves the selection unchanged).
28) EnterKeyBehavior: defines the effect of pressing ENTER in a TextBox (either creates a new line or moves on to the next control in the tab order, when the Multiline property is set to TRUE) .
29) Font object: defines the characteristics of the text used by a control or form.
30) ForeColor: specifies the foreground colour of an object
31) GroupName: creates a group of mutually exclusive OptionButtton controls (clicking one button in the group will set the rest, in the group,to false).
32) Height/Width: sets the height and width of an object (control).
33) HelpContextID: associates a specific help file with a specific control.
34) HideSelection: specifies whether selected text remains highlighted when a control does not have the focus.
35) IMEMode: specifies the default run time mode of Input Method Editor for a control.
36) LargeChange: specifies the amount of movement that occurs when the user clicks between the scroll box and scroll arrow.
37) LayoutEffect: indicates whether a control was moved during a layout change.
38) Left/Top:sets the distance between a control and the left or top edge of the corm containing it.
39) LineCount: returns the number of text lines in a TextBox or ComboBox.
40) List: returns or sets the list entries of a ListBox or ComboBox.
41) ListCount: returns the number of list entries in a control.
42) ListIndex: identifies the currently selected item in a ListBox or ComboBox
43) ListRows: specifies the maximum number of rows to be displayed in a list.
44) ListStyle: specifies the visual appearance of the list in a ListBox or ComboBox.
45) ListWidth: specifies the width of the list in a ComboBox.
46) Locked: specifies whether a control can be edited or not.
47) MatchEntry: returns or sets a value indicating how a ListBox or ComboBox searches its list as the user types in his choice.
48) MatchFound: indicates whether the text that the user has typed into a ComboBox matches any of the entries in the list.
49) MatchRequired: specifies whether a value entered in the text portion of a combo box must match an entry in the existing list portion of the control. The user can enter non-matching values, but may not leave the control until a matching value is entered.
50) MaxLength: specifies the maximum number of characters a user can enter in a TextBox or ComboBox.
51) Max/Min: specifies the maximum & minimum acceptable values for the value property of a ScrollBar or SinButton.
52) MouseIcon: assigns a custom icon to an object.
53) MousePointer: specifies the type of pointer when the user positions the mouse over a particular object.
54) MultiLine: specifies whether a control can accept and display multiple line of text (EnterKeyBehavior depends on this property).
55) MultiSelect: indicates whether the object permits multiple selection or not.
56) Name: specifies the name of a control or an object or the name of a Font to associate wit a font object.
57) Object: overrides a standard property or method when a new control has a property or method of the same name.
58) OldHeight/OldWidth: returns the previous height or width in points of the control.
59) OldLeft/OldTop: returns the distance (in points) between the previous position of a control and the left or top edge of the form that contains it.
60) Orientation: specifies whether the SpinButton or ScrollBar is oriented vertically or horizontally.
61) Parent: returns the name of the form/object /collection that contains a specific control, object or control.
62)PasswordCharacter: specifies whether placeholder characters are displayed instead of the characters actually entered in a TextBox.
63) Picture: specifies the bitmap to display on an object.
64) PictureAlignment: specifies the location of a background picture.
65) PicturePosition: specifies the location of the picture relative to its caption.
66) PictureSizeMode: specifies how to display the background picture on a control, form or page.
67) PictureTiling: to allow a picture to be tiled in a form or page.
68) ProportionalThumb: specifies whether the size of the scroll box is proportional to the scrolling region or is fixed.
69) RowSource: specifies the source providing a list for a ComboBox or ListBox.
70) ScrollBars: specifies whether a control, form or page has vertical scroll bars, horizontal scroll bars or both.
71) Selected: returns or sets the selection state of items in a ListBox.
72) SelectionMargin: specifies whether the user can select a line of text by clicking in the region to the left of the text.
73) SelLength: the number of characters selected in a text box or the text portion o a conbo box.
74) SelStart: indicates the starting point of selected text or the insertion point if no text is selected.
75) SelText: returns or sets the selected text of a control.
76) ShowDropButtonWhen: specifies when to show the drop-down button for a ComboBox or TextBox.
77) SmallChange: specifies the amount of movement that occurs when the user clicks either scroll arrow in a ScrollBar or SpinButton.
78) SpecialEffect: specifies the visual appearance of an object.
79) Style: specifies how the user can choose or set the control's value, this for ComboBox controls and for MultiPage & TabStrip controls it identifies the style of the tabs (on the control).
80) TabIndex: specifies the position of a single object in the form's tab order.
81) TabKeyBehavior: determines whether tabs are allowed in the Edit Region.
82) TabStop: indicates whether an object can receive focus when the user tabs to it.
83) Tag: stores additional information about an object.
84) Text: returns or sets the text in a TextBox and in combo boxes or ListBoxes, it changes the selected row.
85) TextAlign: specifies how text is aligned in a control.
86) TextColumn: identifies the column in a ComboBox or ListBox to display to the user.
87) TextLength: returns the length (in characters) of text in the edit region of a text box or combo box.
88) TopIndex: sets and returns the item that appears in the topmost position in the list.
89) TripleState: determines whether a user can specify, from the user interface, the Null state for a CheckBox or ToggleButton.
90) Value: specifies the state or content of a given control.
91) Visible: specifies whether an object is visible or hidden.
92) WordWrap: indicates whether the contents of a control automatically wrap at the end of a line.
93) Default: designates the default command (push) button on a form. VBA for Excel examples. Quattro Pro of Borland:
Borland Quattro Pro contents of Controls toolbox: as mentioned, previously, the controls are: bitmap button, edit (text) field, label, check box, radio button, spin control, rectangle, group box, push button, combo box, color control, file control, horizontal scroll bar, list box, pick list, scroll bar & time control. The example given hereafter will show the following:
1) How to add custom menu element between two of the standard elements appearing in the active menu bar supplied as part of the software package. It will be placed between the Edit and the Block menu elements. It shows the blocks (groups of cells) names in this example file. The macros and their locations on the page (worksheet) are also shown. An example for the look of a dialog box (dialog 3) related to a specific macro or action is also given. The dialog box has the OK button. When this button is clicked, the links instruction is executed running parallel2 macro. Parallel2 macro shows the active page (which is a in this example) with the selector (highlighter or cursor) on cell number d1.
2) The page with the labels and descriptive text for each entry in the text boxes of each of the dialog boxes are shown. Also, the results of the calculation (rather than the formulas used to arrive to the results) are shown.
3) The print out of the spreadsheet with the option Cell Formulas marked is also shown. It shows labels, values entered by the user and formulas (in place of the calculated values). For example, the page is a (the first sheet of the workbook) and the cell J4 has the descriptive text Equivalent element, L4 cell has the formula [(1)/(1/L2)+1/L3)]. Cell L4 will have the result of the equation when the pertinent macro is run (it will nit show this equation).
Note: the on-line version of this book does not include the Quattro Pro examples

contents

Chapter 2
Basic operations and fundamental calculations of power systems analysisIntroduction: in any of the power systems problems that have to be solved, certain basic steps have to be performed ahead of the beginning of the analysis or the solution process. These preliminary operations can be any of the following:
1) The combination of the a few series or parallel impedance elements (resistance or reactance).
2) The conversion from wye to delta or vice versa of passive electrical system components.
3) Per unit (pu) calculations for the electrical power distribution zone under study.
4) Matrix manipulation and simultaneous equations solution.
5) The formation of the system admittance-bus and impedance-bus models (matrices). Examples showing how to use Excel and Quattro Pro to solve for these fundamental variables or constants of the electrical power systems:
Excel of Microsoft:
For definition of common terms, contents of controls toolbox, properties of each of the commonly used controls, refer to Chapter 1.
Chapter 2, eg. 1, Excel, Fundamental operations and basic calculations:
1) The Workbook program
Private Sub Workbook_Deactivate() 'When this file is deactivated (closed), this sub is run resetting the active
Application.CommandBars.ActiveMenuBar.Reset 'menu bar to its previous state.
End Sub
Private Sub Workbook_Open() 'When this workbook is opened , this sub is run adding the customized menu
Set myMenubar = Application.CommandBars.ActiveMenuBar 'elements to the active menu bar. When it is activate
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True) ' and then reactivated, the
newMenu.Caption = "&Choice ????????" ' customized menu elements will not appear. The user has to click any of
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1) ' the workbook tabs to have such elements
ctrl1.Caption = "&Series/parallel" ' added. If Sub Workbook_Activate is used, instead, then upon deactivation
ctrl1.TooltipText = "Series/parallel" 'and activation of the workbook the customizes elements will appear as part
ctrl1.Style = msoButtonCaption 'of the active menu bar.
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Worksheets("Fault calc. for simple system").Activate
End Sub 2) First Worksheet program (series and parallel operations):
Private Sub CommandButton1_Click()
Range("O1").Select
End Sub
Private Sub CommandButton10_Click()
Range("w8").Select
End Sub
Private Sub CommandButton2_Click()
Range("AA1").Select
End Sub
Private Sub CommandButton4_Click()
Range("A1").Select
End Sub
Private Sub CommandButton5_Click()
Range("A1").Select
End Sub
Private Sub CommandButton6_Click()
Range("R1").Select
End Sub
Private Sub CommandButton7_Click()
Range("l3").Select
End Sub
Private Sub CommandButton8_Click()
Range("i1").Select
End Sub
Private Sub CommandButton9_Click()
Range("w2").Select
End Sub
Private Sub Worksheet_activate()
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Series/parallel"
Set ctrl11 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl11.Caption = "Se&ries calc.."
ctrl11.TooltipText = "Series calc."
ctrl11.Style = msoButtonCaption
With ctrl11
.OnAction = "MySub11"
End With
Set ctrl12 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl12.Caption = "&Eight element calc."
ctrl12.TooltipText = "Eight elements calc."
ctrl12.Style = msoButtonCaption
With ctrl12
.OnAction = "MySub12"
End With
Set ctrl13 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl13.Caption = "Se&ven element calc."
ctrl13.TooltipText = "Seven elements calc."
ctrl13.Style = msoButtonCaption
With ctrl13
.OnAction = "MySub13"
End With
Set ctrl14 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl14.Caption = "S&ix element calc."
ctrl14.TooltipText = "Six elements calc."
ctrl14.Style = msoButtonCaption
With ctrl14
.OnAction = "MySub14"
End With
Set ctrl15 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl15.Caption = "&Five element calc."
ctrl15.TooltipText = "Five elements calc."
ctrl15.Style = msoButtonCaption
With ctrl15
.OnAction = "MySub15"
End With
Set ctrl16 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl16.Caption = "F&our element calc."
ctrl16.TooltipText = "Four elements calc."
ctrl16.Style = msoButtonCaption
With ctrl16
.OnAction = "MySub16"
End With
Set ctrl17 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl17.Caption = "&Three element calc."
ctrl17.TooltipText = "Three elements calc."
ctrl17.Style = msoButtonCaption
With ctrl17
.OnAction = "MySub17"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Controls("Series/parallel").Delete
CommandBars.ActiveMenuBar.Controls("Choice").Delete
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
End Sub
3) Second Worksheet program (wye to delta conversion and vice versa):
Private Sub CommandButton1_Click()
Range("m1").Select
End Sub
Private Sub CommandButton2_Click()
Range("m5").Select
End Sub
Private Sub CommandButton3_Click()
Range("A1").Select
End Sub
Private Sub CommandButton4_Click()
Range("A1").Select
End Sub
Private Sub Worksheet_activate()
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) End Sub
4) Third Worksheet program (fault calculation for a simple system):
Private Sub CommandButton1_Click()
Range("m1").Select
End Sub
Private Sub CommandButton2_Click()
Range("q1").Select
End Sub
Private Sub CommandButton3_Click()
Range("u1").Select
End Sub
Private Sub CommandButton4_Click()
Range("y1").Select
End Sub
Private Sub CommandButton5_Click()
Range("a1").Select
End Sub
Private Sub CommandButton6_Click()
Range("a1").Select
End Sub
Private Sub CommandButton7_Click()
Range("a1").Select
End Sub
Private Sub CommandButton8_Click()
Range("a1").Select
End Sub
Private Sub Worksheet_activate()
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) End Sub 5) Fourth Worksheet program (matrices manipulation):
Private Sub Worksheet_activate()
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Matrix manipulation"
Set ctrl41 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl41.Caption = "&Two by two matrix"
ctrl41.TooltipText = "2 by 2 matrix"
ctrl41.Style = msoButtonCaption
With ctrl41
.OnAction = "MySub41"
End With
Set ctrl42 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl42.Caption = "T&hree by three matrix"
ctrl42.TooltipText = "3 X 3 matrix"
ctrl42.Style = msoButtonCaption
With ctrl42
.OnAction = "MySub42"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub
6) Fifth Worksheet program (simultaneous equations solution):
Private Sub Worksheet_activate()
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Simultaneous equations"
Set ctrl51 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl51.Caption = "&Five equations solution"
ctrl51.TooltipText = "Solution of 5 equations"
ctrl51.Style = msoButtonCaption
With ctrl51
.OnAction = "MySub51"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub 7) Sixth Worksheet program (per unit calculations):
Private Sub Worksheet_activate()
Set myMenubar = Application.CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice ????????"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Number of transfo./system"
Set ctrl61 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl61.Caption = "&One transfo."
ctrl61.TooltipText = "One transfo. per system"
ctrl61.Style = msoButtonCaption
With ctrl61
.OnAction = "MySub61"
End With
Set ctrl62 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl62.Caption = "&Two transfo."
ctrl62.TooltipText = "Two transfo. per system"
ctrl62.Style = msoButtonCaption
With ctrl62
.OnAction = "MySub62"
End With
End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub 8) Seventh Worksheet program (system bus modelling):
Private Sub Worksheet_activate()
Set myMenubar = Application.CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&Choice ????????"
Set ctrl1 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl1.Caption = "&Series/parallel"
ctrl1.TooltipText = "Series/parallel"
ctrl1.Style = msoButtonCaption
With ctrl1
.OnAction = "MySub1"
End With
Set ctrl2 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl2.Caption = "&Wye/delta conv."
ctrl2.TooltipText = "Wye/delta conv."
ctrl2.Style = msoButtonCaption
With ctrl2
.OnAction = "MySub2"
End With
Set ctrl3 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl3.Caption = "Short &circuit calc."
ctrl3.TooltipText = "S.C. Calc."
ctrl3.Style = msoButtonCaption
With ctrl3
.OnAction = "MySub3"
End With
Set ctrl4 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl4.Caption = "&Matrix manipulation"
ctrl4.TooltipText = "Matrix manipulation"
ctrl4.Style = msoButtonCaption
With ctrl4
.OnAction = "MySub4"
End With
Set ctrl5 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl5.Caption = "Simultaneous e&quations solution"
ctrl5.TooltipText = "Simultaneous Equations"
ctrl5.Style = msoButtonCaption
With ctrl5
.OnAction = "MySub5"
End With
Set ctrl6 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl6.Caption = "Per &unit calc."
ctrl6.TooltipText = "Per-unit calculations"
ctrl6.Style = msoButtonCaption
With ctrl6
.OnAction = "MySub6"
End With
Set ctrl7 = newMenu.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl7.Caption = "S&ystem bus modelling"
ctrl7.TooltipText = "System bus modelling"
ctrl7.Style = msoButtonCaption
With ctrl7
.OnAction = "MySub7"
End With
Set myMenubar = CommandBars.ActiveMenuBar
Set newMenu = myMenubar.Controls.Add(Type:=msoControlPopup, temporary:=True)
newMenu.Caption = "&System bus modelling"
Set ctrl71 = newMenu.Controls.Add(Type:=msoControlPopup, Id:=1)
ctrl71.Caption = "&Y-bus calculation"
Set ctrl711 = ctrl71.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl711.Caption = "&Four-bus network Y calculation"
ctrl711.TooltipText = "Calculation of system admittance-bus "
ctrl711.Style = msoButtonCaption
With ctrl711
.OnAction = "MySub711"
End With
Set ctrl72 = newMenu.Controls.Add(Type:=msoControlPopup, Id:=1)
ctrl72.Caption = "&Z-bus calculation"
Set ctrl721 = ctrl72.Controls.Add(Type:=msoControlButton, Id:=1)
ctrl721.Caption = "F&our-bus network Z calculation"
ctrl721.TooltipText = "Calculation of system impedance-bus "
ctrl721.Style = msoButtonCaption
With ctrl721
.OnAction = "MySub721"
End With End Sub
Private Sub Worksheet_Deactivate()
CommandBars.ActiveMenuBar.Reset
End Sub Modules for all programs in the Workbook:
Sub MySub1() 'This sub selects (moves the focus-user- to) the sheet named "series or parallel elements"
' MySub1 Macro
' Macro recorded 8/31/00 by Hany Kheir
Sheets("series or parallel elements").Select
End Sub Sub MySub2()
' MySub2 Macro
' Macro recorded 8/31/00 by Hany Kheir
Sheets("Y-D & vice versa transformation").Select
End Sub Sub MySub3()
' MySub3 Macro
' Macro recorded 8/31/00 by Hany Kheir
Sheets("Fault calc. for simple system").Select
End Sub Sub MySub4()
' MySub4 Macro
' Macro recorded 8/31/00 by Hany Kheir
Sheets("Matrices").Select
End Sub Sub MySub5()
Sheets("Simultaneous equations solution").Select
End Sub Sub MySub6()
Sheets("Per-unit calc.").Select
End Sub Sub MySub7()
Sheets("System bus modelling").Select
End Sub 1) Modules for first Worksheet (series/parallel operations)
Sub MySub11()
' Macro recorded 8/31/00 by Hany Kheir
Range("aa1").Select
End Sub Sub MySub12()
' Macro recorded 8/31/00 by Hany Kheir
Range("o1").Select
End Sub Sub MySub13()
' Macro recorded 8/31/00 by Hany Kheir
Range("r1").Select
End Sub Sub MySub14()
' Macro recorded 8/31/00 by Hany Kheir
Range("l3").Select
End Sub Sub MySub15()
Range("i1").Select
End Sub Sub MySub16()
Range("w2").Select
End Sub Sub MySub17()
Range("w8").Select
End Sub 2) Modules for the fourth Worksheet (matrices manipulation):
Sub MySub41()
' MySub41 Macro
' Macro recorded 8/31/00 by Hany Kheir
Sheets("matrices").Select 'This macro selects the sheet named "matrices".
Range("b1").Select 'It moves the selector (cursor) to cell "b1" of the active sheet.
x11 = InputBox("Enter element a11") 'The input box prompts the user to enter a value for the subject element.
x12 = InputBox("Enter element a12") 'The input box prompts the user to enter a value for the subject element.
x21 = InputBox("Enter element a21") 'The input box prompts the user to enter a value for the subject element.
x22 = InputBox("Enter element a22") 'The input box prompts the user to enter a value for the subject element.
Range("b1").Select
Range("b1") = x11 'This statement assigns the variable x11 to cell "b1", it writes the value entered by the user in the
'cell number "b1".
Range("d1").Select
Range("d1") = x12 Range("b2").Select
Range("b2") = x21 Range("d2").Select
Range("d2") = x22 Range("f1").Select
Range("f1") = x11 Range("f2").Select
Range("f2") = x12 Range("g1").Select
Range("g1") = x21 Range("g2").Select
Range("g2") = x22
det = (x11 * x22) - (x12 * x21) 'The determinant of of the matrix is calculated. Range("a4").Select
Range("a4") = det 'The value of the determinant is placed in cell a4.

Range("b7").Select 'The inverse matrix elements are placed in cells: b7, b8, d7, d8.
x22i = x22 / det
Range("b7") = x22i Range("d7").Select
x12i = x12 / det
Range("d7") = -x12i Range("b8").Select
x21i = x21 / det
Range("b8") = -x21i Range("d8").Select
x11i = x11 / det
Range("d8") = x11i
End Sub Sub MySub42()
Sheets("matrices").Select
Range("b1").Select
x11 = InputBox("Enter element a11")
x12 = InputBox("Enter element a12")
x13 = InputBox("Enter element a13")
x21 = InputBox("Enter element a21")
x22 = InputBox("Enter element a22")
x23 = InputBox("Enter element a23")
x31 = InputBox("Enter element a31")
x32 = InputBox("Enter element a32")
x33 = InputBox("Enter element a33") Range("b11") = x11
Range("f15") = x11 Range("d11") = x12
Range("f16") = x12 Range("f11") = x13
Range("f17") = x13 Range("b12") = x21
Range("g15") = x21 Range("d12") = x22
Range("g16") = x22 Range("f12") = x23
Range("g17") = x23 Range("b13") = x31
Range("h15") = x31 Range("d13") = x32
Range("h16") = x32 Range("f13") = x33
Range("h17") = x33 det = (x11) * ((x22) * (x33) - (x32) * (x23)) - (x12) * ((x21) * (x33) - (x23) * (x31)) + (x13) * ((x21) * (x32) -- (x22) * (x31)) Range("b15") = det
Range("b21") = ((x22 * x33) - (x23 * x32)) / det
Range("d21") = -((x21 * x33) - (x23 * x31)) / det
Range("f21") = ((x21 * x32) - (x31 * x22)) / det Range("b22") = -((x12 * x33) - (x13 * x32)) / det
Range("d22") = ((x11 * x33) - (x13 * x31)) / det
Range("f22") = -((x11 * x32) - (x31 * x12)) / det Range("b23") = ((x12 * x23) - (x13 * x22)) / det
Range("d23") = -((x11 * x23) - (x13 * x21)) / det
Range("f23") = ((x11 * x22) - (x21 * x12)) / det
End Sub 3) Modules for the fifth Worksheet (Simultaneous equations solution):
Sub MySub51()
Sheets("Simultaneous equations solution").Select
Range("b1").Select y11 = InputBox("Enter element a11")
y12 = InputBox("Enter element a12")
y13 = InputBox("Enter element a13")
y14 = InputBox("Enter element a14")
y15 = InputBox("Enter element a15") y21 = InputBox("Enter element a21")
y22 = InputBox("Enter element a22")
y23 = InputBox("Enter element a23")
y24 = InputBox("Enter element a24")
y25 = InputBox("Enter element a25") y31 = InputBox("Enter element a31")
y32 = InputBox("Enter element a32")
y33 = InputBox("Enter element a33")
y34 = InputBox("Enter element a34")
y35 = InputBox("Enter element a35") y41 = InputBox("Enter element a41")
y42 = InputBox("Enter element a42")
y43 = InputBox("Enter element a43")
y44 = InputBox("Enter element a44")
y45 = InputBox("Enter element a45") y51 = InputBox("Enter element a51")
y52 = InputBox("Enter element a52")
y53 = InputBox("Enter element a53")
y54 = InputBox("Enter element a54")
y55 = InputBox("Enter element a55") i1 = InputBox("Enter right hand side of first equation")
i2 = InputBox("Enter right hand side of second equation")
i3 = InputBox("Enter right hand side of third equation")
i4 = InputBox("Enter right hand side of fourth equation")
i5 = InputBox("Enter right hand side of fifth equation") Range("b2") = y11 'The value of element y11 of the left hand side of the equations is placed in cell b2.
Range("d2") = y12
Range("f2") = y13
Range("h2") = y14
Range("j2") = y15 Range("b3") = y21
Range("d3") = y22
Range("f3") = y23
Range("h3") = y24
Range("j3") = y25 Range("b4") = y31
Range("d4") = y32
Range("f4") = y33
Range("h4") = y34
Range("j4") = y35 Range("b5") = y41
Range("d5") = y42
Range("f5") = y43
Range("h5") = y44
Range("j5") = y45 Range("b6") = y51
Range("d6") = y52
Range("f6") = y53
Range("h6") = y54
Range("j6") = y55 y110 = y11 / y11 'The steps of the calculations is starting