How do you increment a variable by +1 on a button click? - qlikview

Hello kind helpful people,
I am having a major problem in Qlikview. I am just trying to create a button that can increment a variable by +1 each time it is clicked. I thought i could simply write an expression on a button click event but Qlikview is so different. I think it overcomplicates this matter by trying to be too simple.
The only thing i can do is 'Set a variable' to a specific value in the button properties.
Does anyone know how to do this?
Many thanks
Eddy

You can do this like you originally tried with an expression in the button action... the key is to make sure you put the = in there so vCount (or whatever your variable is called) gets evaluated first.

I am unable to add a comment, but I wanted to make sure you knew that macros won't work on server, so if you are doing it just for you it should be fine, but if you have it run on a server it could cause problems.

No that's the thing, as i mentioned in my original post all SET VARIABLE does is set a variable to a specific value that you have to specify but you cannot (as far as I know) set an expression that will increment the variable continiously by +1.
Anyway, I figured it out - and for anyone else whose stuck on the same issue:
I found a long winded way of doing it, although it works well.
1) Create your variable in Qlikview, mine is called 'vIncrement'
2) Set up a macro by going into button 'properties' > 'Add' > action type = 'External' > 'Run Macro'
3) Then name your macro and click on 'Edit Module'
4) Paste the following bit of vbScript:
Sub Increment
TheVal = ActiveDocument.Variables("vIncrement").getcontent.string
TheVal = TheVal + 1
ActiveDocument.Variables("vIncrement").SetContent TheVal, True
End sub
5) Click OK and close
This should do the trick.
I actually figured this out in about 20 minutes and I'm a total Qlikview amatuer whose never had any formal training in it lol, but StackOverflow.com won't let me paste my own answer for atleast 10 hours because I'm new here - I cannot understand why?
Never knew about vbscripting Qlikview Macro's until 10 minutes before - not bad eh for an amatuer?
I have to admit there must be a simpler method than this...but atleast this method works.
Cheers
Eddy Jawed

Related

Problem with active status when an continue form have zero record for a filter

this is my first question here and english isnt my language but I'll try to explain at my best.
Im using MS Access 2007.
The form is a "continue form" with a header section where you find an "apply filter" button and a field named "cmpCercaCognome" (italian language for "find surname" plus "cmp" in italian language as field).
This is a cut out of the feature where I am having problems.
The function is fine if the search filter that is set in the field produces at least one result.
The function fails if there are no results.
Private Sub cmpCercaCognome_Change()
If (ActiveControl.Name = "cmpCercaCognome") Then
LunghStr = Len(Me.cmpCercaCognome.Text)
else
LunghStr = Len(Me.cmpCercaCognome)
End if
'Something else but I dont reach it
end sub
The error appear when I'm clicking in the field "cmpCercaCognome" and then Im typing a key there to change the value to use for a filter that I'll apply with a button.
The check "activecontrol" is true still the Len function give error "2185 - Cant read control... without an active status..). How? I just check that have active status! And Im typing just there...
I tryed to modify the IF check so:
"If (ActiveControl.Name = "cmpCercaCognome") And (Me.RecordsetClone.RecordCount > 0) Then"
So I can check just when the count of the record is more than 0.
The problem that so I check the .value of the field that dont contain the last pressed key.
So isnt usefull for me
Is there any way to avoid the problem by keeping control of the temporary value of the field? Or is there a way to make the "temporary value" effective right away so as to avoid checking the .text property?
Thanks for any help you can get on this.

Is there a way to display text based on value?

I use software that has VBA in it, it has the full vba library of references plus its own custom stuff.
So my question is related to the vba part that should be the same everywhere I assume.
I have 5 variables that someone can select as a set point (one at a time), I also have a feedback signal for each of the variables that shows if its on or off.
on the display in the form, I have a text line that I want to display whichever one of the variables is selected.
so is there a way to write a code that says "If this variable is true display it"?
thank you guys,
Having finished my previous answer I went back to read over your question one more time and realized what I'd written was probably not what you were trying to do.
Like Tim said, if the feedback signal isn't used for anything else, rather than setting a variable for each option, have the selection set the text.
Private Sub Selection1CommandButton_OnClick()
Userform1.textdisplaybox.caption = "option1"
End Sub
Or maybe check out combination boxes, the drop down selection menus. That might have everything you're looking for all in one.
Original answer follows.
I'm a little unsure on what you're asking, but I think you want the previously selected option to show up in the text only when it has a signal. I don't know where you're keeping the selection, for now I'm just going to assume it's a global variable named selectedOption with option1, option2 etc being selected.
Something like this might be what you're trying for:
Private sub
'If both the selected option is the first and the feedback signal
'is true, then set the display to that option
If selectedOption = option1 and variableSignal1 = True Then
Userform1.textdisplaybox.caption = option1
'Option is the second and signal is true
ElseIf selectedOption = option2 and variableSignal2 = True Then
Userform1.textdisplaybox.caption = option2
'However many else ifs you need, then if the signal is not true,
'blank the textbox
Else
Userform1.textdisplaybox.caption = ""
Endif
End sub
If the signal is going to turn on and off on its own, then you could add a timer and put this in its timeout.

Excel-VBA UserForm ListBox - How can I Highlight option without Selecting

Nutshell:
What is the equivalent to Me.ListBox1.Selected(2) = True but for highlighting instead of Selecting?? (Highlight might be the wrong word but I'm sure I've seen that before in this context - the outline box around an option instead of actually selecting it)
** Tried **
Me.ListBox1.ListIndex = 2
doesn't do anything either.
With Me.ListBox1
saveVal = .List(0)
.Value = ""
.Value = saveVal
End With
Gives me an error saying "Invalid Property Value"
Background:
Why do I need to click twice on some items/boxes?
I have a userform with several ListBox which are populated by adding items one by one, which works fine.
The ListBox settings have been changed to MultiSelect = 1 - fmMultiSelectMulti and ListStyle = 1 - fmListStyleOption
The issue is when trying to select an option on some boxes for the first time, it just highlights it without selecting it, while on other boxes and other tries it may or may not select an option straight away. It doesn't seem to be the same culprits and is a bit random - does it have something to do with where I'm clicking on the option? On the item text instead of the item box? Why does it work on some and not others?
After I've selected one option in a box, it then allows me to select any other with a single click which is the desired behaviour.
I found a link where someone had suggested this behaviour was because of a corrupted workbook, but I don't think it's that. I just created a new book with 1 listbox in a userform, changed to desired settings, copied the listbox 6 times, put the listsource as rand() in columns A:G and I'm still getting the same issue.
Edit: My plan is to "highlight" the top option on each box so that the first click on a box has no option other than to select (because something is already highlighted)...
The trick to tackling my INITIAL problem seems to have been after populating each list to set .ListIndex = 0 but this only worked after using .SetFocus
Solved! (For now, I think)
Even though this doesn't highlight anything it allows me to select something first time without fail.

Unbound DataGridView add row with checkbox error

This is a Windows forms program. I have an unbound DataGridView control with four columns; Feature ID as string, Parts as string, Flats as string and ShowOnEst as boolean. The columns were defined in the form designer and the boolean column is, indeed, set to be a checkbox with tristate set to false.
The user selects a product from a list box and this code is executed to populate the grid
grdFeat.Rows.Clear()
For i = 0 To curProduct.lstFeatures.Count - 1
With (curProduct.lstFeatures(i))
grdFeat.Rows.Add(.FeatureId, .Parts, .Flats, .ShowOnEst)
End With
Next
If AllowUserToAddRows is false, everthing is good. Setting AllowUserToAddRows to true, however, results in the following error:
FormatException
Value '' cannot be converted to type 'Boolean'.
The error is NOT triggered in my code. It's displayed in a new tab titled "No Source Available".
It seems pretty clear that the process that adds the new editing row is trying to set the checkbox to a string value, or perhaps NULL. I'm very new (a few months) to vb.net, so I suspect I'm overlooking some simple setting somewhere, but after several hours of trying to find it, I'm starting to feel a little foolish here.
I'd give you a list of things I've tried already, but it's a long one. :) I even tried to go around the issue by adding a new row manually, .add("","","",False), but that too gives the same error, even though I'm telling it what to put in the checkbox.
What am I missing? Also, can someone point me to an explanation of how that new editing row thingy works?
From what you explained, I have no real explanation for the problem.
A workaround may be to set AllowUserToAddRows to false before populating the DataGridView and set it to true after.
Found it. Hope it helps someone else...
The rows being added are uncommitted rows. To solve it, capture the row added index, set the current cell and notify that the added row is dirty:
grdFeat.Rows.Clear()
For i = 0 To curProduct.lstFeatures.Count - 1
With (curProduct.lstFeatures(i))
Dim p = grdFeat.Rows.Add(.FeatureId, .Parts, .Flats, .ShowOnEst)
End With
grdFeat.CurrentCell = grdFeat.Rows(p).Cells(0)
grdFeat.NotifyCurrentCellDirty(True)
Next
Well, with further experimentation, this isn't a total fix. The problem is still there, but at least now handling the DataError event allows me to do something with it in code. Without these lines, the error occurs before the DataError event is triggered.
Still puzzled.

My DoCmd.SearchForRecord command stopped working

I have a dropdownlist that has 4 columns but only 3 are 'visible' the first one is an ID, and after update I have the following code run.
DoCmd.SearchForRecord acDataForm, "new_order_thingy", acFirst, "[OrderID] = " & Me.Combo112.Column(0)
This used to get the record pertaining to the OrderID, I am not sure what I did but I somehow broke it. I don't get an error but it doesn't retrieve any data.
It does pass the correct value in Me.Combo112.Column(0) when I MsgBox it out.
Any help/suggestions would be appreciated.
Thanks
I suggest you place a breakpoint in your code. Then, change the value in the combo, and in break mode, hover the mouse over the variables.
This will also show you if the event is really fired.
Sometimes the link between the event and the procedure is lost (e.g. when you rename the object).
The Form.DataEntry was set to YES, it should have been set to NO ... don't get why but thats what was causing my error.