Is there a way to wrap text in Excel VBA form listbox? - forms

Is there a way to wrap text in Excel VBA form listbox?
item = item & WorksheetFunction.Rept(" ",30 - Len(item))
subtotal = WorksheetFunction.Rept(" ", 10 - subtotal_pad) & _
"$ " & WorksheetFunction.Rept(" ", subtotal_pad - Len(Format(subtotal, "0.00"))) & Format(subtotal, "0.00")
taxed = " "
If tax_rate <> 0 Then
taxed = " T"
End If
description = ""
If description <> "" Then
description = vbNewLine & " - " & description
End If
quantity = ""
If unit <> "ea" Then
quantity = vbNewLine & " - " & quantity & " # $" & Format(cost, "0.00#") & "/" & unit
End If
lbxCharges.AddItem (item & subtotal & taxed & description & quantity)
This is how it looks:
but this is how it should look:

Related

Error at the end of the statement SSRS expression , couldn"t find it?

=
"<b>"+ "Created on: " + "</b>" & CDate(Fields!ticket_ticketSolutions_date_create.Value).ToString("dd/MM/yy HH:mm"))
& Environment.NewLine
& "<b>" + "Approval date: " + "</b>" & iif (IsNothing(Fields!date_approval.value),"Not Approved",CDate( Fields!date_approval.Value).ToString("dd/MM/yy HH:mm"))
& Environment.NewLine
& "<b>" + "Solutions: " +"</b>" & Fields!ticket_ticketSolutions_content_plainText.Value
The Value expression for the textrun 'solution_all.Paragraphs[0].TextRuns[0]' contains an error: [BC30205] End of statement expected.
The definition of the report '' is invalid.
I don't understand where are my errors ?? as I created a calculated fields that contains this formula
You have mis-matching )s on line 2 . Remove the end ).

Tracking Chnages in Enterprise Architect

I encounter a real difficulty in tracking changes and updates in the company models.
I research the tool abilities a lot, but still didn't find the golden way that match my requirements of:
Provide indication where was a change
What was the change
Keep the original model state, aside to the up-to-date state
EA offers the following ways:
Baselines
Version Control
Clone
Change Elements
None of them provides indication on what exactly was the change and where.
What is the easiest way to manage the changes effectively?
You forgot the last resort: audit. Turn on auditing and you can get a lot more information. Of course this also has its drawbacks
it uses a lot of space
there are still changes that are not tracked in the detail you might need it.
Turn it on at Project/Auditing. More information here.
Additionally you could think of writing triggers, but I would not recommend that since it makes your repository almost unmaintainable.
Auditing is of course also no silver bullet. Tracking changes is tedious. And personally I would not spend too much effort in this "accusation mode". Better spend your energy in driving the model towards the company goals. Nobody needs yesterday's model.
I wrote some scripts to handle change management in EA.
The idea is that the user links the changed items to a change request element that represents a workitem, project, change request, bug,...
Each link contains the date, user and a comment for the change to that item.
The scripts are part of the open source EA VBScript library:
The main script is the following
'[path=\Projects\Project A\A Scripts]
'[group=Atrias Scripts]
!INC Local Scripts.EAConstants-VBScript
!INC Atrias Scripts.Util
' Script Name: LinkToCRMain
' Author: Geert Bellekens
' Purpose: Link Elemnents to a change
' Date: 2015-10-30
'
'
function linkItemToCR(selectedItem, selectedItems)
dim groupProcessing
groupProcessing = false
'if the collection is given then we initialize the first item.
if selectedItem is nothing then
if not selectedItems is nothing then
if selectedItems.Count > 0 then
set selectedItem = selectedItems(0)
if selectedItems.Count > 1 then
groupProcessing = true
end if
end if
end if
end if
if selectedItem is nothing then
set selectedItem = Repository.GetContextObject()
end if
'get the select context item type
dim selectedItemType
selectedItemType = selectedItem.ObjectType
select case selectedItemType
case otElement, otPackage, otAttribute, otMethod, otConnector :
'if the selectedItem is a package then we use the Element part of the package
if selectedItemType = otPackage then
set selectedItem = selectedItem.Element
end if
'get the logged in user
Dim userLogin
userLogin = getUserLogin
dim lastCR as EA.Element
set lastCR = nothing
dim CRtoUse as EA.Element
set CRtoUse = nothing
set lastCR = getLastUsedCR(userLogin)
'get most recent used CR by this user
if not selectedItem is nothing then
dim lastComments
lastComments = vbNullString
'if there is a last CR then we ask the user if we need to use that one
if not lastCR is nothing then
dim response
if groupProcessing then
response = Msgbox("Link all " & selectedItems.Count & " elements to change: """ & lastCR.Name & """?", vbYesNoCancel+vbQuestion, "Link to CR")
elseif not isCRLinked(selectedItem,lastCR) then
response = Msgbox("Link element """ & selectedItem.Name & """ to change: """ & lastCR.Name & """?", vbYesNoCancel+vbQuestion, "Link to CR")
end if
'check the response
select case response
case vbYes
set CRToUse = lastCR
case vbCancel
'user cancelled, stop altogether
Exit function
end select
end if
'If there was no last CR, or the user didn't want to link that one we let the user choose one
if CRToUse is nothing then
dim CR_id
CR_ID = Repository.InvokeConstructPicker("IncludedTypes=Change")
if CR_ID > 0 then
set CRToUse = Repository.GetElementByID(CR_ID)
end if
else
'user selected same change as last time. So he might want to reuse his comments as well
lastComments = getLastUsedComment(userLogin)
end if
'if the CRtoUse is now selected then we link it to the selected element
if not CRToUse is nothing then
dim linkCounter
linkCounter = 0
'first check if this CR is not already linked
if isCRLinked(selectedItem,CRToUse) and not groupProcessing then
MsgBox "The CR was already linked to this item", vbOKOnly + vbExclamation ,"Already Linked"
else
'get the comments to use
dim comments
comments = InputBox("Please enter comments for this change", "Change Comments",lastComments)
if len(comments) > 2 then
if groupProcessing then
for each selectedItem in selectedItems
'check the object type
selectedItemType = selectedItem.ObjectType
select case selectedItemType
case otElement, otPackage, otAttribute, otMethod, otConnector :
if not isCRLinked(selectedItem,CRToUse) then
linkToCR selectedItem, selectedItemType, CRToUse, userLogin, comments
linkCounter = linkCounter + 1
end if
end select
next
if linkCounter > 0 then
MsgBox "Successfully linked " & selectedItems.Count & " elements to change """ & CRToUse.Name& """" , vbOKOnly + vbInformation ,"Elements linked"
else
MsgBox "No links created to change " & CRToUse.Name & "." & vbNewLine & "They are probably already linked" , vbOKOnly + vbExclamation ,"Already Linked"
end if
else
linkToCR selectedItem, selectedItemType, CRToUse, userLogin, comments
end if
else
MsgBox "The CR has not been linked because no comment was provided", vbOKOnly + vbExclamation ,"No CR link"
end if
end if
end if
end if
case else
MsgBox "Cannot link this type of element to a CR" & vbNewline & "Supported element types are: Element, Package, Attribute, Operation and Relation"
end select
end function
function isCRLinked(item, CR)
dim taggedValue as EA.TaggedValue
isCRLinked = false
for each taggedValue in item.TaggedValues
if taggedValue.Value = CR.ElementGUID then
isCRLinked = true
exit for
end if
next
end function
function linkToCR(selectedItem, selectedItemType, CRToUse, userLogin, comments)
Session.Output "CRToUse: " & CRToUse.Name & " userLogin: " & userLogin & " comments: " & comments
dim crTag
set crTag = nothing
set crTag = selectedItem.TaggedValues.AddNew("CR","")
if not crTag is nothing then
crTag.Value = CRToUse.ElementGUID
crTag.Notes = "user=" & userLogin & ";" & _
"date=" & Year(Date) & "-" & Right("0" & Month(Date),2) & "-" & Right("0" & Day(Date),2) & ";" & _
"comments=" & comments
crTag.Update
end if
end function
function getLastUsedCR(userLogin)
dim wildcard
dim sqlDateString
if Repository.RepositoryType = "JET" then
wildcard = "*"
sqlDateString = " mid(tv.Notes, instr(tv.[Notes],'date=') + len('date='),10) "
Else
wildcard = "%"
sqlDateString = " substring(tv.Notes, charindex('date=',tv.[Notes]) + len('date='),10) "
end if
dim sqlGetString
sqlGetString = "select top 1 o.Object_id " & _
" from (t_objectproperties tv " & _
" inner join t_object o on o.ea_guid = tv.VALUE) " & _
" where tv.[Notes] like 'user=" & userLogin & ";" & wildcard & "' " & _
" order by " & sqlDateString & " desc, tv.PropertyID desc "
dim CRs
dim CR as EA.Element
set CR = nothing
'get the last CR
set CRs = getElementsFromQuery(sqlGetString)
if CRs.Count > 0 then
set CR = CRs(0)
end if
set getLastUsedCR = CR
end function
function getLastUsedComment(userLogin)
dim wildcard
dim sqlDateString
dim sqlCommentsString
if Repository.RepositoryType = "JET" then
wildcard = "*"
sqlDateString = " mid(tv.Notes, instr(tv.[Notes],'date=') + len('date='),10) "
sqlCommentsString = " mid(tv.Notes, instr(tv.[Notes],'comments=') + len('comments=')) "
Else
wildcard = "%"
sqlDateString = " substring(tv.Notes, charindex('date=',tv.[Notes]) + len('date='),10) "
sqlCommentsString = " substring(tv.Notes, charindex('comments=',tv.[Notes]) + len('comments='), datalength(tv.Notes)) "
end if
dim sqlGetString
sqlGetString = "select top 1 " & sqlCommentsString & " as comments " & _
" from (t_objectproperties tv " & _
" inner join t_object o on o.ea_guid = tv.VALUE) " & _
" where tv.[Notes] like 'user=" & userLogin & ";" & wildcard & "' " & _
" order by " & sqlDateString & " desc, tv.PropertyID desc "
dim queryResult
queryResult = Repository.SQLQuery(sqlGetString)
Session.Output queryResult
dim results
results = convertQueryResultToArray(queryResult)
if Ubound(results) > 0 then
getLastUsedComment = results(0,0)
else
getLastUsedComment = vbNullString
end if
end function

VBS Script that shows the files created on a specific date

I want to create a script that shows the files created on a specific date in a specific location.
As for now I created this:
Set objWMIService = GetObject("winmgmts:" & "!\\" & "." & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile where Drive='C:' AND Path='\\' AND CreationDate Like '20071107%' ")
For Each objFile in colFiles
Buffer = Buffer & objFile.FileName & " - " & objFile.CreationDate & vbNewLine
Next
Wscript.echo Buffer
But I am getting error in this line: " AND CreationDate Like '20071107%' "
So it does not work in such a way as I thought it will be - in C:\ I have a lot eula.txt files created on 2007 11 07.
I do not ask about finished code, but only for a clue. Thanks!
WHERE clause of a WQL query defends or inhibits from using wildcards in CIM_DATETIME values. Use SWbemDateTime object as follows:
option explicit
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName
Dim objWMIService, colFiles, objFile, dTargetDate, dMinDate, dMaxDate, dateTime
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dTargetDate = #2007-11-07# ' date literal in yyyy-mm-dd format
dateTime.SetVarDate( dTargetDate) ' convert to CIM_DATETIME
dMinDate = datetime
dateTime.SetVarDate( DateAdd( "d", 1, dTargetDate))
dMaxDate = datetime
strResult = strResult & vbNewLine & dMaxDate
Set objWMIService = GetObject("winmgmts:" & "!\\" & "." & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ( _
"Select * from CIM_DataFile where Drive='c:' AND Path='\\'" _
& " AND CreationDate >= '" & dMinDate & "'" _
& " AND CreationDate < '" & dMaxDate & "'" _
)
If colFiles.Count = 0 Then
strResult = strResult & vbNewLine & "no files found"
Else
For Each objFile in colFiles
strResult = strResult & vbNewLine & objFile.FileName & " " & objFile.Extension _
& " - " & objFile.CreationDate
Next
End If
Wscript.Echo strResult
Wscript.Quit

Crystal Script condition statement 'This field name is not known' error

this is my current condition statement
IF {AR_DEBIT.InvoiceNo} = "" THEN {AR_DEBIT.Description}
ELSE {AR_DEBIT.Description} & "(" & {AR_DEBIT.InvoiceNo} & " - " & ToText({AR_DEBIT.InvoiceDate}, "dd-MMM-yyyy") & ")"
not working...prompt error IF {AR_DEBIT.InvoiceNo} = "" THEN this field is not known bla bla something like that...
when i remove the condition,
{AR_DEBIT.Description} & "(" & {AR_DEBIT.InvoiceNo} & " - " & ToText({AR_DEBIT.InvoiceDate}, "dd-MMM-yyyy") & ")"
the report show no error...anybody?

Form Search to find all records with value in subform (regardless of field value in)

After searching the forum, I haven't found any questions/answers quite like mine.
I have a main form with four different search fields - last name, city, phone number, and ID. I want to have a search of any of these fields (or combination of these fields) to find all records in the subform with a matching value - regardless of which field that value is in (i.e. there are multiple address fields in the subform, so the city could appear in any of these).
Additionally, if a Last Name AND City are entered I only want to return records in the subform that include both values.
Thank you in advance!
I don't think this can be done without employing VBA. You would need to add code to the AfterUpdate event for each search field's control on the main form that would subsequently update the subform's filter. I'm not sure how complex filters are allowed to be, though, which could be a problem because it's going to be a monster of a filter.
Here's an untested example that uses placeholders for the potential number of different fields in the subform (as you indicated there could be multiples of any of them) and assuming your phone number and ID are numbers and that your search controls have data validation in place to ensure that:
Private Sub last_name_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub city_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub phone_number_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub ID_AfterUpdate()
Call FilterSubForm()
End Sub
Private Sub FilterSubForm()
Dim sLastName As String
Dim sCity As String
Dim sPhone As String
Dim sID As String
Dim sFilter As String
sLastName = Trim(Me.[last name])
sCity = Trim(Me.city)
sPhone = Trim(Me.[phone number])
sID = Trim(Me.ID)
If sLastName != "" And sCity != "" Then
sFilter = "(([last_name_1] = '" & sLastName & "' " _
& "OR [last_name_2] = '" & sLastName & "' " _
& "OR [last_name_etc] = '" & sLastName & "') " _
& "AND " _
& "([city_1] = '" & sCity & "' " _
& "OR [city_2] = '" & sCity & "' " _
& "OR [city_etc] = '" & sCity & "'))"
If sPhone != "" Then
sFilter = sFilter _
& " AND " _
& "[phone_number_1] = " & sPhone & " " _
& "OR [phone_number_2] = " & sPhone & " " _
& "OR [phone_number_etc] = " & sPhone
End If
If sID != "" Then
sFilter = sFilter _
& IIf(sPhone != "", " OR ", " AND ") _
& "[ID_1] = " & sID & " " _
& "OR [ID_2] = " & sID & " " _
& "OR [ID_etc] = " & sID
End If
Else
If sLastName != "" Then
sFilter = "[last_name_1] = '" & sLastName & "' " _
& "OR [last_name_2] = '" & sLastName & "' " _
& "OR [last_name_etc] = '" & sLastName & "'"
End If
If sCity != "" Then
sFilter = sFilter _
& IIf(sLastName != "", " OR ", "") _
& "[city_1] = '" & sCity & "' " _
& "OR [city_2] = '" & sCity & "' " _
& "OR [city_etc] = '" & sCity & "'"
End If
If sPhone != "" Then
sFilter = sFilter _
& IIf(sCity != "", " OR ", "") _
& "[phone_number_1] = " & sPhone & " " _
& "OR [phone_number_2] = " & sPhone & " " _
& "OR [phone_number_etc] = " & sPhone
End If
If sID != "" Then
sFilter = sFilter _
& IIf(sPhone != "", " OR ", "") _
& "[ID_1] = " & sID & " " _
& "OR [ID_2] = " & sID & " " _
& "OR [ID_etc] = " & sID
End If
End If
Me.[your_subform].Filter = sFilter
Me.[your_subform].FilterOn = True
Me.[your_subform].Requery
End Sub