i have a report with parameter is the year i can select a multiple value: for example i selected 2005,2006,2007
when i click in view report i get this result
i added some custom code to add value in arraylist
Dim values As System.Collections.ArrayList
Function AddValue(ByVal newValue As Integer)
If (values Is Nothing) Then
values = New System.Collections.ArrayList()
End If
values.Add(newValue)
End Function
Public Function GetArray(Item as Integer)
return values(Item)
End Function
i added my code in my matrice this is the result
The first row i got the right anwer but the other rows are false answers this is the resut what i need
Without RDL details regarding your expressions - it is difficult to answer your question. What are your expected results? What is the exact input and output you are expecting? Please provide samples.
In this scenario, it seems the issue is in your custom code. Once you return the result at the end of first row. The variable(called "result") keeps the "66" and it was never overwritten so that it always shows "66". In Reporting Services, it generates cells from left to right, top to bottom. So you need to pass the first column (HP, DELL, Acer) as argument in your function and use a variable (called "previous")to receive this value. Always do the judgment at the beginning of the function, if the passing argument is not equal to the "previous". You need to clear the "result" variable.
Related
There is probably a simple solution to this, but it is eluding me.
I have a textbox (name = CFMon), that references a month textbox. The user will submit values for all months, but they select a key month that is used for a calculation. I need to use their selected key month to get the value from the appropriate month textbox (each month is named mon1, mon2, etc)
When not using VBA, I would simply use the indirect function to evaluate all of the string.
test = Forms![Form]![CFMon] & ".value"
this does exactly what it is supposed to do and just regurgitate the text string
I am hoping the evaluate the reference and return the appropriate month value. For Example. The user selects CFMon = Mon3, the value will return the value the user inputs in the Mon3 (March) textbox
You could obtain the control from the Controls collection, e.g.:
test = Forms("Your Form Name").Controls(Forms![Form]![CFMon]).Value
Alternatively, you could use the eval function, but I would advise against this:
test = eval("Forms![Your Form Name]![" & Forms![Form]![CFMon] & "].Value")
i have a piece of code that is to be repeated several times throughout my form when certain buttons are pressed. on the clicking of the buttons it should be adding to the decimal value inside the textbox by the value that varies from button to button.my code so far looks like this:
Function EditPrice(ByVal a As Decimal, ByVal b As Decimal)
Dim num1 As Decimal
num1 = a + b
Return num1
End Function
Private Sub btnMinusMushroom_Click(sender As Object, e As EventArgs) Handles btnMinusMushroom.Click
EditPrice(CDec(txtEditCost.Text) + "0.5")
End Sub
if that isn't clear what the code should be doing, the variable of "a" in the function "EditPrice" is the decimal value inside the textbox "txtEditCost" and the decimal value of .5 is the value that should be added to the textbox value.
the function name is underlined red saying "argument not specified for parameter 'b' of 'public function EditPrice(ByVal a As Decimal, ByVal b As Decimal) as object' ".
i dont know what that means or how to fix the problem, any ideas?, thanks
There are a number of issues with your code. To help you avoid such issues in future, I strongly suggest that you set Option Strict On. That will disallow narrowing implicit conversions and late-binding, which will force you to give more consideration to the data types you're using. You can set it On for the current project in the project properties. You can also set it On in the IDE options so that it will be On by default for all future projects.
The first issue is one that Option Strict On would flag, i.e. you have declared a function without a return type. This:
Function EditPrice(ByVal a As Decimal, ByVal b As Decimal)
should be this:
Function EditPrice(ByVal a As Decimal, ByVal b As Decimal) As Decimal
The second issue relates to the naming of that function. You have named it EditPrice but, if you look at the actual code of the method, the name has nothing at all to do with it. There's no price there and there's no editing. All it does is add two numbers of type Decimal and return the result. There's nothing about that that requires the numbers to represent a price and nothing is edited because nothing is changed by the method.
The third issue is with how you're calling the method. The method is declared as taking two Decimal arguments yet what are you doing?
EditPrice(CDec(txtEditCost.Text) + "0.5")
How does that make sense? You get a String from a TextBox and convert that to a Decimal and then you add another String to that and then pass that single result to the method. That's all kinds of wrong. Firstly, why are you adding a String to a Decimal? If you want to add the number 0.5 to something then use a number, not a String. If you want to add to a Deciaml then use a `Decimal number. Secondly, why are you adding the two numbers there and passing the result to the method when the whole point of the method is to add the two numbers? That code should be more like this:
EditPrice(CDec(txtEditCost.Text), 0.5D)
That's still a problem though because, as I said, the EditPrice method doesn't actually edit anything. It just adds two inputs and returns the result, but you don't actually use that result. You presumably want to display that result somewhere. If it's in the same TextBox again then you need to do that:
txtEditCost.Text = EditPrice(CDec(txtEditCost.Text), 0.5D).ToString()
Note the ToString call there too. That will be required by Option Strict On because that Text property is type String and that method returns a Decimal.
The code is still a bit dodgy even with those changes. What's the point of a method that adds two numbers and returns the result when you could do that inline with a simple addition operator? If a method is to be named EditPrice then it actually ought to edit a price. In that case, it would make more sense to have it take a single number to add to the current price and then have the method make the change, e.g.
Private Sub EditPrice(valueToAdd As Decimal)
Dim currentValue As Decimal
'This will get the current value or zero if there is no valid value.
Decimal.TryParse(txtEditCost.Text, currentValue)
Dim newValue As Decimal = currentValue + valueToAdd
txtEditCost.Text = newValue.ToString()
End Sub
Note that that is a Sub rather than a Function because it actually makes a change rather than return a value that other code uses to make a change. In this case, the name actually describes what the method does. Method names should ALWAYS describe what the method actually does.
I'm having this issue where my SSRS Report header will show me the value of next group of the report. I am using the Code route to accomplish this. I have two functions, one to set the Value, and one to retrieve it. This is inside the code section of my report.
Public Shared varInvoiceNum As Integer
Public Function SetInvoiceNum(InvcNum As Integer) as Integer
varInvoiceNum = InvcNum
End Function
Public Function GetInvoiceNum() as Integer
Return varInvoiceNum
End Function
I then have a textbox with an expression that sets the value in the header of the group for Invoice Num. This group only shows Once and cant have it repeating, as it contains address information. In the Report Header is where I call the get function.
The problem occurs when the total section for the report appears on the second page. For whatever the reason, even though the header section in the tablix that contains the Set function call never reappears until the third page. On the Second page the Second Invoice Number will appear. Even though its still apart of the first group. It some how gets set to the next value. Any idea how this might be happening?
EDIT: The Second Invoice number in the batch shouldn't be showing, because the Total section is still apart of the First Invoice group. This is the Issue, there is no error message. It just improperly sets the next variable to the next group when the Set Expression hasn't occurred again.
I have the following:
=Round(ReportItems!Textbox47.Value
+ CDbl(ReportItems!Textbox218.Value)
+ CDbl(ReportItems!Textbox222.Value)
+ CDbl(ReportItems!Textbox226.Value)
+ CDbl(ReportItems!Textbox230.Value)
+ CDbl(ReportItems!Textbox234.Value),2,MidpointRounding.ToEven)
This is saved in the Textbox called ReportItems!TotalSaves.Value
This TextBox is part of DataSet1. What I want to do is call that TextBox in another DataSet.
I tried a Lookup and it does not work. I tried to save the value of that TextBox in a global variable but it does not take Items in the report collection.
EDIT1:
I tried to do the following:
Public Function GetValue(Byval value as Double)
prueba = value
End Function
Public Function Value() As Double
Return prueba
End Function
I called the function GetValue inside the Dataset1 where ReportItems!TotalSaves.Value exists in an expression:
Code.GetValue(ReportItems!TotalSaves.Value)
And then call the Value function in the Dataset2
Code.Value()
But it returns 0 so there is no value saved, maybe it is saved but for some reason Value does not get the value that it is saved in the GetValue function, even if it is the same variable.
EDIT2:
I tried to do the changes Alejandro told me:
But:
In English:
"The expression value for the TextBox50 make a reference to an element "TotalFrecPromVentas" (This is the textbox that exists in Tablix1/dataset1 that does not exists in Tablix2/Dataset2),the element expressions of the report can only reference to another elements of the same group.
You can reference a textbox in another dataset by using the ReportItems!TotalSaves.Value you identified in your question.
For example if I have a text box that sums the values in a column as follows
I can reference this value from another table using a different dataset as follows
This would result in the following output, in this case a very simple definition of the 6 times table
Is this the sort of solution you were looking for? If you need further clarification, or a different approach then let me know.
Try change:
Dim public total as Double
Public Function GetValue(ByVal numero as Double ) AS Double
total = numero
return total
End Function
In the selected textbox named Mytextbox I put manually a double value: =12.456.
The textbox in red rectangle is the textbox where I want to place the
referenced Mytextbox value
So in the textbox I put the following expression:
=Code.GetValue(ReportItems!MyTextbox.Value)
You have to put =Code.GetValue(ReportItems!TotalSaves.Value).
Note I am not using Value() function. My function just returns the value of the passed parameter.
Don't use Value() function use my code.
It worked for me. Let me know if it could help you.
I have a table in a report and a textbox that changes its background color based on the value(s) in the table. Right now I have the background color expression for the textbox set to:
=iif(Me.Value = ReportItems![NewValue].Value, "Yellow", "Transparent")
"NewValue" is the name of one of the columns in the table. The above works fine if the textbox value is in the very first row in the "NewValue" column, but not otherwise.
How do I fix this so it will work if the textbox value shows up in any row in the "NewValue" column?
Sorry, I'm a little new to Reporting Services and haven't seen any functions for table controls.
Instead of ReportItems![NewValue].Value, you can also use ReportItems("NewValue").Value, by the way
I finally got this working yesterday thanks to this blog post:
http://mpasharp.spaces.live.com/blog/cns!5BA71A558863C810!191.entry?sa=340192646
I basically did what he did in the post, modified slightly for my report. I also added a function for getting the row index of the value I was looking for (variables are a little different in mine).
Public Shared Function GetChangedValueIndex(txt As String) As Integer
Dim counter As Integer = 0
For Each s As String In ChangedValueList
If s = txt Then
Return counter
End If
counter += 1
Next
Return -1
End Function
The other caveat is that calling the function to add a value to the array has to occur earlier in the report than anywhere you want to check for it. The table I was working with is actually at the end of the report (and can't be moved for requirements reasons) so I made a copy of that table, moved it to the top of the report, and set it to be hidden.
Unbelieveable that there isn't an easier way to do this.