qlikview set expression with chr()-function - function

I am Setting some variables in the script of my qlikview application. Later on I try to reuse one of the previous variables but qlikview is giving me an error.
SET vCurrentMonth = "=CAL.MONTH";
SET vMonthCounter = "SUM({<MONTH = {'$(vCurrentMonth)'}>} Counter)";
I was trying to use the $-expansion as already known from the normal set expressions that are not in the Script. But then I did not receive any data.
After some Research I found that I must replace the $ with the chr()-function.
SET vMonthCounter = "SUM({<MONTH = {'" & chr(36)& "(vCurrentMonth)'}>} Counter)";
But this chr()-function is returning a string so I don't receive the sum of my Counter but the string of the set Expression ($03).
What am I doing wrong? Can anybody explain how to use this function in the script?
Thanks in advance

It works fine for me even without using the chr() function. I've added = before the sum (i've used simple string for vCurrentMonth and remove the = there):
SET vMonthCounter = "=SUM({<MONTH = {'$(vCurrentMonth)'}>} Counter)";
and then using the variable in text box (like below) is giving me the correct result:
= vMonthCounter
If you still prefer the chr() approach then some changes in the vMonthCounter are needed to get the same result:
let vMonthCounter1 = '=SUM({ <category = {' & chr(39) & chr(36) & '(vCurrentMonth)' & chr(39) & '} >} value)';
set is replaced with let. let evaluates the expression and will actually run and replace the chr() with the symbols (btw when using set you are not obligated to enclose the string in any quotes)
replaced the start and end quotes with single quote
the single quotes inside the set expressions are replaced with chr(39)

Related

IIf query decimal removal

Trying to attempt the following in MS Access.
Convert data in one field to an 18 digit number starting with 01 in another field.
There are also some conditions that have to be met:
the first dash should become double zeros
the second dash should be removed
the third and fourth dash should be a single zero
the decimal must also be replaced with a zero
My query works fine until the decimal is the 15th character in the data.
Here is the query:
SELECT MasterVacant.ParcelIdNumber,
"01" + Mid([ParcelIdNumber],1,2) + "00" + Mid([ParcelIdNumber],4,2) + Mid([ParcelIdNumber],7,1)
+ IIf(Mid([ParcelIDNumber],11,1) = "", "0"+Mid([ParcelIDNumber],9,2), Mid([ParcelIDNumber],9,3))
+ IIf(Mid([ParcelIDNumber],14,1) = ".", "0"+Mid([ParcelIDNumber],12,2), Mid([ParcelIDNumber],12,3))
+ Mid([ParcelIDNumber],15,3) AS ParcelNumber
FROM MasterVacant;
Here is a start and finish example...
'12-06-1-00-50.000-RR' should become '011200061000050000'
'12-06-3-07-09.000-RR' should become '011200063007009000'
'13-35-1-01-129.000-RR' should become '011300035100112900'
However, instead of getting `0113000351001129000' I get '013000351001129.00'.
The issue is how do I remove the decimal when the decimal is the 15th character like in the third set of example?
I receive the data as a single column. Some of it is below....
1. 13-35-1-07-29.000-RR
2. 13-35-1-01-112.000-RR (Removing the decimal when the data is like this is the issue)
3. 13-35-4-01-01.000-RR
4. 13-35-4-02-04.000-RR
5. 13-35-1-13-17.000-RR
The output for the above data should be
1. 011300351007029000
2. 011300351001112000
3. 011300354001001000
4. 011300354002004000
5. 011300351013017000
Use a custom function:
Public Function Make18(ByVal Value As String) As String
Const Head As String = "01"
Const Tail As String = "000"
Const Lead As String = "00"
Dim Parts As Variant
Dim Part As Integer
Dim Result As String
Parts = Split(Split(Value, ".")(0), "-")
For Part = LBound(Parts) To UBound(Parts)
Select Case Part
Case 0
Parts(Part) = Head & Parts(Part)
Case 1
Parts(Part) = Lead & Parts(Part)
Case 3, 4
Parts(Part) = Right(Lead & Parts(Part), 3)
End Select
Next
Result = Join(Parts, "") & Tail
Make18 = Result
End Function
and your query becomes:
SELECT
MasterVacant.ParcelIdNumber,
Make18([ParcelIdNumber]) AS ParcelNumber
FROM
MasterVacant;
I am assuming you meant the opposite where:
12-06-1-00-50.000-RR should become 011200061000050000
12-06-3-07-09.000-RR should become 011200063007009000
13-35-1-01-129.000-RR should become 0113000351001129.00
I would recommend the REPLACE() in MSACCESS to strip the dashes out. Once you have the dashes out you can MID()
Unfortunately your attempted code does something different with the 3rd row because 3 zeros are being put in when there should be only two in my opinion.
Try in a text box:
=Replace("13-35-1-01-129.000-RR","-","")
will return 1335101129.000RR
and see if that assists you in making your code.
Maybe go one step further and put it in a function.

Two different formats of field in report Access 2013

I'm trying to find a way to do the following:
I want to have two different formats for a certain text box. To do so, I've done the following: User types one or two digits in a form text box(who's input and format are both "#,0;0;_") and has "yes/no" box on the right of that number field which asks if it's "kg per bag"(so by default it's the other measurement unit which is Percentages), then an OnLoad event is fired when viewing the report for that form, which checks if the yes/no value is yes or no. If "yes" then the format is set to "#.0 & " kg/bag"", if no it's set to "#.0 & " %"".
I will have to additionally divide by 100 when percentages are the ones picked, but first I want the whole thing to work... Which I still can't do!
Sadly, I'm nowhere near getting it to work... Here is my current macro on the onload event of the report, which is marked as not valid expression:
Link to the image on Imgur
Or here is the MacroBuilder Code:
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<UserInterfaceMacros xmlns="http://schemas.microsoft.com/office/accessservices/2009/11/application"><UserInterfaceMacro For="Report" Event="OnLoad"><Statements><ConditionalBlock><If><Condition>[yn]=False</Condition><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " kg/bag"</Argument></Action></Statements></If><Else><Statements><Action Name="SetValue"><Argument Name="Item">[Text0].[Format]</Argument><Argument Name="Expression">#,0 & " %"</Argument></Action></Statements></Else></ConditionalBlock></Statements></UserInterfaceMacro></UserInterfaceMacros>
Which is displayed as:
If [yn]=False Then
SetValue
Item = [text0].[format]
Expression = #,0 & " kg/bag"
Else
SetValue
Item = [text0].[format]
Expression = #,0 & " %"
End if
Can anyone give me a hint on where to go with this? Thank you!!
P.S. Comma is my decimal separator in regional settings!
You don't really need to change format only concatenate the numeric value with unit (kg/bag or %).
Using VBA, try the following code in the OnLoad event (I am assuming the recordsource field behind the text0 control is called the same -text0):
If Forms!yourformname![yn] = False Then
Reports!yourreportname!text0 = Me.text0 & " kg/bag"
Else
Reports!yourreportname!text0 = (Me.text0)/100 & "%"
' ALTERNATIVELY: Reports!yourreportname!text0.Format = "percent"
End If
Alternatively in the OnLoad event, use an embedded macro or call an external macro with the following one action (if/then changed into the IIF function):
SetValue
Item: text0
Expression: =IIF(Forms!yourformname![yn] = False, text0 & " kg/bag", text0/100 & "%")

Global Date Variable Works Only for Entered Values

I'm currently working on what should be a relatively simple database, which is very close to being at its end, until I hit the inevitable problem.
I'm using Global Variables and a Form to collect parameters to pass into the Criteria portion of a Query, which works just fine for the first two, which are basic strings and integers.
Then comes the dates, which work, so long as you chose a date from the DatePicker that is entered into the query.
For example, if the query field holds 6/1/2014, 6/3/2014, and 6/8/2014, and the date 6/5/2014 is picked, the form will crash and go blank, though if you pick 6/8/2014, it'll go on as it should.
I had tried a variety of different forms of the code, but in the most basic form I simple have:
Between Get_Global('GBL_Start_Date_ID') AND Get_Global('GBL_End_Date_ID')
I'm not sure if I should be limiting the DatePicker based on the values entered in the query, or if there's a more robust way of going about this, or maybe I just completely missed a simple checkbox.
EDIT
My code for the Global Variables looks like this:
Option Compare Database
Global GBL_Start_Date_ID As Date
Global GBL_End_Date_ID As Date
Global GBL_Customer_ID As Long
Global GBL_Engineer_ID As Long
Public Function Init_Globals()
GBL_Start_Date_ID = #6/1/2014#
GBL_End_Date_ID = #6/30/2014#
GBL_Customer_ID = 1
GBL_Engineer_ID = 1
End Function
Public Function Get_Global(gbl_parm)
Select Case gbl_parm
Case "GBL_Customer_ID"
Get_Global = GBL_Customer_ID
Case "GBL_Engineer_ID"
Get_Global = GBL_Engineer_ID
Case "GBL_Start_Date_ID"
Get_Global = GBL_Start_Date_ID
Case "GBL_End_Date_ID"
Get_Global = GBL_End_Date_ID
End Select
End Function
And I just add a simple line to the AfterUpdate event of the ComboBoxes and TextBoxes to assign the variable:
GBL_Engineer_ID = Me.EngineerSelection
Thanks in advance,
Aaron
You can do two things. Fix the query as it is written or make it much more robust.
To fix it as written
Between "#" & Get_Global('GBL_Start_Date_ID') & "#" AND "#" & Get_Global('GBL_End_Date_ID') & "#"
OR
change your Get_Global function
Public Function Get_Global(gbl_parm)
Select Case gbl_parm
Case "GBL_Customer_ID"
Get_Global = GBL_Customer_ID
Case "GBL_Engineer_ID"
Get_Global = GBL_Engineer_ID
Case "GBL_Start_Date_ID"
Get_Global = "#" & GBL_Start_Date_ID & "#"
Case "GBL_End_Date_ID"
Get_Global = "#" & GBL_End_Date_ID & "#"
End Select
End Function
You are correctly specifying that the values of GBL_Start_Date_ID and GBL_End_Date_ID are dates by using #s when you create them however when you use them in your query they appear without them. You can prove to yourself this is what is happening by typing ?#1/1/2014# into the immediate window. The date is printed as 1/1/2014 which when used in your query, makes Between 6/1/2014 AND 6/30/2014 which is a syntax error.
To make things all that much better you need to parameterize this part of your query. Change this
Between Get_Global('GBL_Start_Date_ID') AND Get_Global('GBL_End_Date_ID')
to this
Between pStartDate AND pEndDate
Before you call your query you need to do your usual checks: are either of these null? is pStartDate < pEndDate?
By performing these checks and parameterizing this you ensure that you never end up with a query like this. Calling your query means you need to need to populate the parameters with DAO or ADO.
Between AND

access fields same but not equal?

i'm using the following code to compare two recordsets:
For i = 1 To (recordsetA.Fields.Count - 1)
If recordsetA.Fields(i).Value <> recordsetB.Fields(i).Value Then
stringFieldList = stringFieldList & ", " & recordsetA.Fields(i).Name
End If
Next i
However in the stringFieldList there are a couple of fields which have the same values (like 1339.5). Why?
Since it sounds like your dealing with double datatypes, the proper way for the test would be to set a limit, then test the absolute difference. You will also need to think about handling a null value.
Const epsilon as double = 0.00001
If Abs(recordsetA.Fields(i).Value - recordsetB.Fields(i).Value) < epsilon Then
'do stuff here
End If

Problem updating values in combobox in vb.net

I have this code, but I have a problem.
When I update but do not really made any changes to the value and press the update button, the data becomes null. And it will seem that I deleted the value.
I've taught of a solution, that is to add both combobox1.selectedtext and combobox1.selecteditem to the function. But it doesn't work.
combobox1.selecteditem is working when you try to alter the values when you update. But will save a null value when you don't alter the values using the combobox
combobox1.selectedtext will save the data into the database even without altering.
But will not save the data if you try to alter it.
-And I incorporated both of them, but still only one is performing, and I think it is the one that I added first:
Dim shikai As New Updater
Try
shikai.id = TextBox1.Text
shikai.fname = TextBox2.Text
shikai.mi = TextBox3.Text
shikai.lname = TextBox4.Text
shikai.ad = TextBox5.Text
shikai.contact = TextBox9.Text
shikai.year = ComboBox1.SelectedText
shikai.section = ComboBox2.SelectedText
shikai.gender = ComboBox3.SelectedText
shikai.religion = ComboBox4.SelectedText
shikai.year = ComboBox1.SelectedItem
shikai.section = ComboBox2.SelectedItem
shikai.gender = ComboBox3.SelectedItem
shikai.religion = ComboBox4.SelectedItem
shikai.bday = TextBox6.Text
shikai.updates()
MsgBox("Successfully updated!")
Please help, what would be a simple workaround to solve this problem?
a few things to remember ---
a 'selected____' anything is only non-null when something is, uhm, SELECTED. To ensure that SOMETHING is selected even at start add a line like: ComboBox1.SelectedIndex = 0.
If your recordset has non-string types (like a DATE field might be) then be sure to first check then coerce the string coming back as TEXT to the correct type. I.e....
if isDate(ComboBox1.SelectedText) then ... 'its ok to use this coerced text.
Since a combobox (as well as a listbox) can hold an entire CLASS (i.e. any kind of OBJECT) ... any SelectedItem assignment had better match EXACTLY to the type that was .Items.Add 'ed originally to the control.