Enterprise Architect: Populating enum programmatically, but they're being alphabetized and not in the order they're entered - vbscript

I'm writing a VBScript script to assist in laying out the architecture of some software I'm developing at work. I'm parsing the header files for defined enumerations, structs, function definitions, and some auto-generated commented stuff related to the categorical structure of our modules.
It's all going swimmingly, and I can create an appropriate package (we categorize our modules by layer level, i.e. drivers vs application level, etc), add a Component, then populate the Component with a blank Diagram, Enumerations for state and error, an Interface for methods, and a struct for the data structure.
My problem is coming in when I try to populate the Enumerations with Attributes. When I do it by hand, they're listed in the proper order (where they would resolve to 0, 1, etc.), but when I populate them while parsing the header file, they get entered alphabetically, which is obviously a problem.
I tried modifying the Default member of each Attribute with it's corresponding numerical value, but it still alphabetized them (and added the numerical value, too).
Here's a snippet of my code. Hopefully it's sufficient!
set newStateEnum = newComponent.Elements.AddNew(fileName & "_state_t", "Enumeration")
dim tempState, initialValue
dim tempAttribute as EA.Attribute
initialValue = 0
for each tempState in stateParts
if InStr(tempState, "=") > 0 then
set tempAttribute = newStateEnum.Attributes.AddNew(Split(tempState, "=")(0), "enum")
else
set tempAttribute = newStateEnum.Attributes.AddNew(Split(tempState, ",")(0), "enum")
end if
tempAttribute.Default = initialValue
initialValue = initialValue + 1
tempAttribute.Update()
next
newStateEnum.Update()

You can use EA.Attribute.Pos to set a custom ordering.
So something like:
for each tempState in stateParts
if InStr(tempState, "=") > 0 then
set tempAttribute = newStateEnum.Attributes.AddNew(Split(tempState, "=")(0), "enum")
else
set tempAttribute = newStateEnum.Attributes.AddNew(Split(tempState, ",")(0), "enum")
end if
tempAttribute.Default = initialValue
initialValue = initialValue + 1
tempAttribute.Pos = initialValue 'set the custom POS here
tempAttribute.Update()
next
Make sure you allow custom attribute ordering in the settings, or this won't have any visible effect either.

Related

How to fix an import from AD

I'm not a developer, i'm trying to understand why my IT ticketing software is unable to import people from the windows AD. It was working ok a month ago. I have no access to the windows AD but they said "no changes or upgrades" recently made
I have isolated problem is related to the AD "manager" field, meaning, my ticketing software has an option not to try to import the manager field(or whatever it is) and it will work fine
Here is the code that performs the import
Option Explicit On ' Change to Off instead of On to disable the need to declare variables with Dim. (NOT recommended)
Option Strict Off ' Change to Off instead of On to cast variables automatically. (NOT recommended)
Option Compare Binary ' Change to Text instead of Binary to let string "A" equal to "a".
Imports System
Imports System.Data
Imports System.Collections
This is a transformation script class. Please take notice of the following rules:
' - You are not allowed to change the name of the class (must be "TransformationScript")
' - You are not allowed to change the namespace the class is in (the class "TransformationScript" must not be in a namespace).
' - You are not allowed to change the name of the method (must be "Transform")
' - You are not allowed to change the parameters of the "Transform" method
' This method is called by the transformation logic. The dt parameter contains the data table with the data to transform.
' Any additional arguments are passed in the additionalArguments list.
Public Class TransformationScript
Public Sub Transform (ByVal dt As System.Data.DataTable, ByVal additionalArguments As SortedList)
For Each row As DataRow In dt.Rows
Dim strValue As String
If Not String.IsNullorEmpty(row.Item("manager").ToString)
strValue = row.Item("manager").ToString
Dim strArray() As String
Dim strManager As String
Dim strManagerDisplayName As String
split the AD manager object on "OU" and the results to array
strArray = strValue.Split("OU")
get string array position "0" that contains the manager name
strManager = strArray(0)
clean up the Manager display and remove the "CN=" and "\" and the last ","
strManagerDisplayName = strManager.Replace("CN=","")
strManagerDisplayName = strManagerDisplayName.Replace("\","")
strManagerDisplayName = strManagerDisplayName.Remove(strManagerDisplayName.Length-1)
return the Manager Display Name
row.Item("manager") = strManagerDisplayName
End If
Next
End Sub
End Class
I want to understand what the code is trying to do and possible root causes of what could be causing the issue
Thanks in advance

How to store a changing webpage in a variable?

My script automates the room booking process at my school for group projects. I have created an automatic log-in script which works fine. Now I would like to access different elements from the loaded page (check boxes, radio buttons...).
How can I save various elements from the page that I have logged-in into and perform certain actions on them?
Func SignIn()
Global $window = _IECreate("https://roombooking.au.dk/classes/Login.aspx? ReturnUrl=%2fclasses%2fbook.aspx")
_IELoadWait($window)
If #error Then Return
WinSetState("[ACTIVE]", "", #SW_MAXIMIZE)
Local $username = _IEGetObjByName($window,"ctl00$Main$UsernameBox")
Local $password = _IEGetObjByName($window,"ctl00$Main$PasswordBox")
Local $button = _IEGetObjByName($window, "ctl00$Main$LoginBtn")
_IEFormElementSetValue($username,"abc")
_IEFormElementSetValue($password,"123")
_IEAction ($button, "click")
EndFunc
Func Room()
Local $SelectRoom = _IEGetObjByName(**???**,"ctl00$Main$ChangeReqsBtn")
_IELoadWait($bwindow)
_IEAction($s526,"click")
EndFunc
From the Help File:
#include <IE.au3>
_IEGetObjByName ( ByRef $oObject, $sName [, $iIndex = 0] )
$oObject Object variable of an InternetExplorer.Application, Window or Frame object
$sName Specifies name of the object you wish to match
$iIndex If name occurs more than once, specifies instance by 0-based index
0 (Default) or positive integer returns an indexed instance
-1 returns a collection of the specified objects
In your case the code will be something like:
Local $SelectRoom =
_IEGetObjByName($window,"ctl00$Main$ChangeReqsBtn")
AutoIt offers many different approaches to HTML document retrieval. Without providing concerning source code it can only be guessed.
HTML source of document is returned by _IEDocReadHTML() (assuming you're using IE.au3 UDF). Example:
#include <IE.au3>
Global Const $oIE = _IECreate('http://www.google.com/')
Global Const $sDocHTML = _IEDocReadHTML($oIE)
_IEQuit($oIE)
ConsoleWrite($sDocHTML & #LF)
Exit 0
Mentioned UDF contains functions to set values to form elements (lookup _IEForm...() in AutoIt's user defined function reference).

ArcPad - VBscript - Autopopulate attributes

I am using the following script to grab parcel and address information from one layer to fill the attribute table of a newly created feature.
There is no returned error, but the problem I am having is that there seems to be the wrong information stuck in the memory of recordselect function. No matter where I place a point it gives the same parcel # and address. Or maybe it isn’t actually be performing the IF function properly.
Sub Address
Dim rsCurrentXY
Set rsCurrentXY = Map.Layers("Violations").records
rsCurrentXY.movelast
Dim objXYShape
Set objXYShape = rsCurrentXY.Fields.Shape
Dim pControls
Set pControls= Application.Map.selectionlayer.Forms("EDITFORM").Pages(“PAGE1”).Controls
Dim rsGrid
' Find corresponding map page to the valve point
Set rsGrid = Map.Layers("ACPA_parcels").records
rsGrid.movefirst
Do While Not rsGrid.eof
If rsGrid.fields.shape.Ispointin(objXYShape) Then
pControls("txtAddress").value = rsGrid.Fields("ADD1").Value
Exit Do
End If
rsGrid.Movenext
Loop
' Clean Up
Set rsCurrentXY = Nothing
Set objXYShape = Nothing
Set rsGrid = Nothing
End Sub
(I have another subroutine called "PIN" that would do the exact same thing.)
I have them called when their respective edit boxes in the custom form are activated by the inspector.
Thanks for the help,
Robert
Accessing the EDITFORM via Application.Map.selectionlayer.Forms("EDITFORM") will be problematic. Whenever working with controls on an EDITFORM you should using ThisEvent.Object to discover all your objects. For example, if your event handler is Page_OnLoad then ThisEvent.Object will refer to your current page. You should have code like this:
Dim pPage1
Set pPage1 = ThisEvent.Object
Dim pControls
Set pControls = pPage1.Controls

Export data from listview to OpenOffice VB6

I have a program that displays data from a CSV file into a ListView.
I then have a button called "Reports" - when I click this I want the data to be displayed from the ListView/CSV file in OpenOffice Calc.
This is my code:
Private Sub cmdReports_Click()
Dim oSM As Object
Dim oDesk As Object
Dim oDoc As Object
Dim oSheet As Object
Dim i As Integer
'Instanciate OOo : this line is mandatory with VB for OOo API
Set oSM = CreateObject("com.sun.star.ServiceManage…
'Create the first and most important service
Set oDesk = oSM.CreateInstance("com.sun.star.frame.D…
'Create a new doc
Set oDoc = oDesk.loadComponentFromURL("private:fact… "_blank", _
0, arg())
'Get the first sheet in the doc
Set oSheet = oDoc.getSheets().getByIndex(0)
With oSheet
For i = 1 To ListView1.ListItems.Count
.cells(i, 1) = ListView1.ListItems(i).Text
.cells(i, 2) = ListView1.ListItems(i).SubItems(1)
.cells(i, 3) = ListView1.ListItems(i).SubItems(2)
.cells(i, 4) = ListView1.ListItems(i).SubItems(3)
Next
End With
End Sub
At the moment all my button is doing giving me Run-time error '438' Object does not support this property or method
When I debug this line is highlighted:
.cells(i, 1) = ListView1.ListItems(i).Text
This code was written for Excel but I edited it so it can be displayed in OpenOffice Calc.
Can anyone help please?
Thanks
It means exactly what it says - the statement is using a property of method that isn't supported by the Ole Automation interface. First question: can you use a type library (see the References dialogue - is there something like OpenOffice Calc in the list)? Knowing what methods and properties are available at compile time is much better - you can do the same with Microsoft Excel. Then you could declare your variables as a specific type, rather than "As Object".
Not knowing OpenOffice, I looked for documentation on OpenOffice, and found the next best thing, Star Office. Try: http://www.openoffice.org/api/basic/man/tutorial/tutorial.pdf . Look at page 64, section 4.4 for documentation on the spreadsheets. The object model looks different to Office, which would explain your problem.
It looks as if you need to use the Sheet.getCellByPosition() method, rather than the Cells() method, e.g.
GetCell = oSheet.getCellByPosition (nColumn , nRow)

In QTP, is it possible to have an anti-description?

What I have is a table of dollar amounts, some of which are links. Example:
$0.00
$1,000.00
$1.00
How do I say this most succinctly in QTP-land?
Set desCurrencyString = Description.Create
desCurrencyString("micclass").value = NOT "Link"
I suppose I could just use a boolean value to see where the link is and somehow capture the other parts of the list, possibly like this:
Set desCurrencyString = Description.Create
desCurrencyString("text").RegularExpression = True
desCurrencyString("text").value = "\$[0-9]*"
Set arrCurrencyStrings = Page.ChildObjects(desCurrencyString)
desCurrencyString("micclass").value = "Link"
arrCurrencyStrings.Remove(desCurrencyString) 'Or something, will be editing this line later
Simply loop through a WebTable.
To get cell text, use GetCellData(Row, Col) method of WebTable object.
To get a child object contained in a cell, use ChildItem(Row, Col, MicClass, intIndex) method of WebTable object.
Neither table rows, nor cells, spans, divs, etc. can be returned by ChildObjects function as they are not truly GUI object classes. (Though, if you would need it very much you could define such custom objects, but you'd have to manually set them up in Object Repository Manager).

Resources