Microsoft Reporting Service Textbox Alignment in Expression. - ssrs-2008

I'm trying to set the textbox alignment depending on its content.
I have
= Replace(Fields!1_Text.Value, " " , chr(13) & CHR(10))
in value expression.
Where should I put
iif(fields!Allignment.Value = "C", "Center", "Right")
to align as coded?

Try using an aggregate function, such as first(), around your fields:
Iif(First(Fields!Allignment.Value,"DataSet1") = "C","Center","Right")
(alignment is misspelled...)

I found the solution.
Well, I didn't know that I could add an expression for the text alignment property.
Steps are:
Textbox - go to Properties - "TextAlign" property - Expression
I could add an expression for "TextAlign" property like:
Iif(First(Fields!Allignment.Value,"DataSet1") = "C","Center","Right")
Cheers,

Related

Conditional formatting on Access form looking up a value

I've created a form within Access which uses a cross-tab query as its data source.
The column headings for the query are 1, 2, 3, 4 and 5 representing week numbers.
The values display items such as 3/3 = 100.00% or 0/13 = 0.00% or 3/14 = 21.00%.
I've added conditional formatting to the text boxes on the form.
Expression Is Right([2],7)="100.00%" works and displays the figure in bold red when the percentage is 100.
Expression is Val(Right([2],7))=100 also works - converting the text value to a numeric value.
The problem I'm having is that I'm not always looking for 100% - it depends on the value within a table. What I'm trying to do is
Val(Right([2],7))=(SELECT ParamValue*100 FROM tbl_System WHERE Param='SampleSize') - this doesn't work.
Neither does:
Eval(Val(Right([2],7))=(SELECT ParamValue*100 FROM tbl_System WHERE Param='SampleSize'))
or
Val(Right([2],7))=EVAL(SELECT ParamValue*100 FROM tbl_System WHERE Param='SampleSize')
or
Val(Right([2],7))=DLookUp("ParamValue","tbl_System","Param= 'SampleSize'")*100
or
Val(Right([2],7))=Eval(DLookUp("ParamValue","tbl_System","Param= 'SampleSize'")*100)
The SQL for the cross-tab query is:
TRANSFORM NZ(Sum(Abs([Include])),0) & "/" & NZ(Count(*),0) & " = " &
FormatPercent(NZ(Round(Sum(Abs(Include))/Count(*),2),0),2)
SELECT tbl_TMP_PrimaryDataSelection.TeamMember
FROM tbl_TMP_PrimaryDataSelection
GROUP BY tbl_TMP_PrimaryDataSelection.TeamMember
PIVOT tbl_TMP_PrimaryDataSelection.WeekNum In (1,2,3,4,5)
I don't think you can use a function in there, be it system or user-defined.
But you can define the FormatCondition dynamically at runtime, like this:
Dim txtFld As TextBox
Dim objFrc As FormatCondition
Dim strExpr As String
Set txtFld = Me!myTextBox
' Remove existing FormatConditions
txtFld.FormatConditions.Delete
' The dynamic expression
strExpr = "Val(Right([2],7))=" & DLookUp("ParamValue","tbl_System","Param='SampleSize'")*100
' Assign a new FormatCondition to text box
Set objFrc = txtFld.FormatConditions.Add(acExpression, , strExpr)
' Set the format
objFrc.ForeColor = &HFF0000
This example simply removes and recreates all FormatConditions. If you have a fixed number of conditions, you can also use the FormatCondition.Modify method (see online help).
Edit:
The final code I have used executes on the Form_Load event and adds a format to each of the five weekly text boxes:
Private Sub Form_Load()
Dim aTxtBox(1 To 5) As TextBox
Dim x As Long
Dim oFrc As FormatCondition
Dim sExpr As String
With Me
Set aTxtBox(1) = .Wk1
Set aTxtBox(2) = .Wk2
Set aTxtBox(3) = .Wk3
Set aTxtBox(4) = .Wk4
Set aTxtBox(5) = .Wk5
For x = 1 To 5
aTxtBox(x).FormatConditions.Delete
sExpr = "Val(Right([" & x & "],7))>=" & DLookup("ParamValue", "tbl_System", "Param='SampleSize'") * 100
Set oFrc = aTxtBox(x).FormatConditions.Add(acExpression, , sExpr)
oFrc.ForeColor = RGB(255, 0, 0)
Next x
End With
End Sub
Edit 2
Yes, defining FormatConditions via VBA is especially useful when dealing with multiple controls in a loop. You can do this in Design View too and save the FormatConditions permanently, simply to avoid going through the FormatConditions dialogs one by one. Or if the customer later decides that he'd rather have a different color. :)
Note: You could use Set aTxtBox(x) = Me("Wk" & x) in the loop. But actually you don't need multiple TextBox variables, you can simply re-use it.

maskedEditColumn datagridview how to use class? is it what i need?

I am trying to mask user's input in a datagridview column and i found this ready class Masked edit column Class that adds a 'mask edit column' option in the column types list. When i select this column type a mask field is being added in the list of column properties. I tried to do my job by adding some mask elements in this 'Mask' field, but when I run the code it didnt restrict me from adding other characters. I re-opened the 'edit columns menu' and I saw that the 'Mask' field was empty.
I want the text cell to accept 20 chars maximum and only: 1.Capital Letters(English & Greek), 2.these three chars(.,-), 3.Numbers 0-9
So as a first test i used only this mask(>????????????????????) but it didnt work as it didnt convert my characters to Uppercase and accepted more than 20 chars when i end the cell edit.
i am not sure the way to go is the Masked Text Box way. i have made many projects on vb and i used to use a loop in the textChanged event of a text box to restrict characters entry. the loop is this : (but i cant use it now in the valueChanged event cause it seems that 'value' doesn't have a selectionStart property.)
Dim charactersDisallowed As String = "!##$%^&*()+=|}{][:;?/><.,~""
Dim theText As String = txtCopies.Text
Dim Letter As String
Dim SelectionIndex As Integer = txtCopies.SelectionStart
Dim Change As Integer
For x As Integer = 0 To txtCopies.Text.Length - 1
Letter = txtCopies.Text.Substring(x, 1)
If charactersDisallowed.Contains(Letter) Then
theText = theText.Replace(Letter, String.Empty)
Change = 1
End If
Next
txtCopies.Text = theText
txtCopies.Select(SelectionIndex - Change, 0)
So,
Is a masked text cell what i need? and if yes( Why is this mask box not keeping the mask i enter? And how can i use this class to do my job?)
What can i alternately do to restrict some characters in a column's cells? (I will then convert to Uppercase on cellEndEdit)
I finally did it by removing the unwanted characters on cellvaluechanged event, which seems that is being raised when I end the cell's edit by for example hitting "Enter".

How do I use the "like" operator in Crystal Reports 2008 using a parameter

I am trying to create a formula based on a parameter that will allow the user to select a description of a supply item, or if none is selected to pull all values. Also want to be able to give them a parameter that allows them to type any part of the description using the "like" option. I can get the first part of the formula to work but not the second part. It is correctly pulling a typed in item or if none is typed it returns all values. Anything past the first "or" does not work. Should I create a separate parameter for the second part or can I use the same one?
IF HASVALUE ({?DESCR}) THEN{Command.DESCRIPTION} = {?DESCR} else true
or
( UPPER({Command.DESCRIPTION}) LIKE "*" + UPPERCASE({?DESCR}) + "*")
OR
( UPPER({Command.DESCRIPTION}) LIKE "*" + UPPERCASE({?DESCR}) + "*")
To the extent I understand your requirement you don't need anything after the if because though you give single character or a string your HASVALUE ({?DESCR}) returns true... hence you can modify your formula as
IF HASVALUE ({?DESCR})
THEN{Command.DESCRIPTION} LIKE "*" + {?DESCR} + "*"
else true
you can use UPPERCASE if you need.
Edit:
IF HASVALUE ({?DESCR})
THEN {Command.DESCRIPTION} LIKE "*" + {?DESCR} + "*"
ELSE IF HASVALUE({?NIIN})
THEN {Command.NIIN} = {?NIIN}
ELSE IF HASVALUE({?CLASS})
THEN {Command.CLASS} = {?CLASS}
else TRUE

Create a Unique ID for a Visio Shape use the Shape Sheet

I'm not new to Visio nor to programming but I am new to developing in Visio.
I'm using 2007 and am creating my own custom shapes with Shape Data.
I want to create a UniqueID for all my shapes in the context of the drawing.
I have created a Shape data element called 'Shape UniqueID'. (ShapeSheet Prop.Shape_Unique_ID)
I tried to generate a unique ID (Shape.UniqueID property), using the formula syntax below, in the ShapeSheet 'Value' cell for the property :
=UniqueID(visGetOrMakeGUID) and =UniqueID(1)
But Visio does not recognize this as a valid Formula..
I also tried to use DATA1():
=Guard(Data1())
That gives me a unique value BUT it does not update if you copy the shape.
I've dowloaded the 2007 SDK and can't find a Shapesheet function to read the properties.
I have also seen that you can set the page so UniqueIDs are always on shapes used but I can't figure out how to turn it on.
My "preference" is to use a Shape Data element and set it BUT......
Any Ideas would be appreciated?
Thanks ... Scott
[Note this answer is rough duplicate of the one here ]
UniqueIDs are only accessible in code, ie, there's no ShapeSheet function that'll return a unique ID (GUID).
By default a shape starts off without a UniqueID so you have to assign it in code. Some shapes such as the off page connector shape store the unique IDs in the ShapeSheet so that they can track which shape is connected to which, but this is managed by an addon.
You can store a GUID in a ShapeSheet cell (usually a User cell), but generally if you have a reference to a shape to read a cell then you also have the means to read the .UniqueID property as well. If you're looking for other ways to identify a shape then shp.ID (or the ID() ShapeSheet function) will return an ID that's unique to the page, so that may be something to consider as well
Here's some sample code that demonstrates how to use UniqueIDs:
Sub UniqueIDsDemo()
Dim vPag As Page
Set vPag = ActivePage
Dim vShp As Shape
Set vShp = vPag.DrawRectangle(1, 1, 1, 1)
Debug.Print vShp.NameID & " UniqueID = '" & vShp.UniqueID(visGetGUID) & "'"
Dim sGUID As String
sGUID = vShp.UniqueID(visGetOrMakeGUID)
Debug.Print vShp.NameID & " UniqueID = '" & vShp.UniqueID(visGetGUID) & "'"
vShp.AddSection visSectionUser
Dim rowIdx As Integer
Dim cellName As String
cellName = "UniqueID"
rowIdx = vShp.AddNamedRow(visSectionUser, cellName, visTagDefault)
vShp.CellsSRC(visSectionUser, rowIdx, visUserValue).FormulaU = sGUID
Debug.Print vShp.NameID & "!User." & cellName & " = '" & vShp.CellsU("User." & cellName).ResultStrU("") & "'"
End Sub

RowFilter including [ character in search string

I fill a DataSet and allow the user to enter a search string. Instead of hitting the database again, I set the RowFilter to display the selected data. When the user enters a square bracket ( "[" ) I get an error "Error in Like Operator". I know there is a list of characters that need prefixed with "\" when they are used in a field name, but how do I prevent RowFilter from interpreting "[" as the beginning of a column name?
Note: I am using a dataset from SQL Server.
So, you are trying to filter using the LIKE clause, where you want the "[" or "]" characters to be interpreted as text to be searched ?
From Visual Studio help on the DataColumn.Expression Property :
"If a bracket is in the clause, the bracket characters should be escaped in brackets (for example [[] or []])."
So, you could use code like this :
DataTable dt = new DataTable("t1");
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Description", typeof(string));
dt.Rows.Add(new object[] { 1, "pie"});
dt.Rows.Add(new object[] { 2, "cake [mud]" });
string part = "[mud]";
part = part.Replace("[", "\x01");
part = part.Replace("]", "[]]");
part = part.Replace("\x01", "[[]");
string filter = "Description LIKE '*" + part + "*'";
DataView dv = new DataView(dt, filter, null, DataViewRowState.CurrentRows);
MessageBox.Show("Num Rows selected : " + dv.Count.ToString());
Note that a HACK is used. The character \x01 (which I'm assuming won't be in the "part" variable initially), is used to temporarily replace left brackets. After the right brackets are escaped, the temporary "\x01" characters are replaced with the required escape sequence for the left bracket.