Listbox in tk/tcl 2 - listbox

#Variables:
set var1 123
set var2 456
set var3 789
#Widgets:
label .label1 -text ""
listbox .lstb1 -height 3 -width 20 -selectmode browse
.lstb1 insert 0 Var1 Var2 Var3
#Procedure
proc SelectionHappened {listbox label} {
set activeItem [$listbox get active]
$label configure -text $$activeItem
}
#Interface
bind .lstb1 <<ListboxSelect>> {SelectionHappened .lstb1 .label1}
grid .label1 .lstb1 -sticky news
How to get in .label1 value of the selected variable, not the variable name ?
ie: instead of "$ Var1" get "123"; instead of "$ Var2" get "456"; instead of "$ Var3" get "789"

You need to change this:
.lstb1 insert 0 Var1 Var2 Var3
to this:
.lstb1 insert 0 $var1 $var2 $var3
and this:
set activeItem [$listbox get active]
to this:
set activeItem [$listbox get [$listbox curselection]]
and finally this:
$label configure -text $$activeItem
to this:
$label configure -text $activeItem
(Why doesn't $listbox get active work? When you select an item in the listbox, $listbox get active gives you the item that was active before you clicked. If you select the same item twice, $listbox get active will point out that item the second time.)
Update in response to comment:
Leave this line
.lstb1 insert 0 Var1 Var2 Var3
as is, and change this line:
set activeItem [$listbox get active]
to
set activeItem [lindex {123 456 789} [$listbox curselection]]
or
set values {123 456 789}
set activeItem [lindex $values [$listbox curselection]]
Documentation: label, lindex, listbox, set

How about using the label widget's -textvariable option?
proc SelectionHappened {listbox label} {
set varName [$listbox get [$listbox curselection]]
$label configure -textvariable $varName
}

Related

Add value to array if its not already in there

I want to add a value to an array if its not already there.
So far my code looks something like this (note that both r.names and {name} are arrays, and [1] + [2] = [1,2]):
MERGE (r:resource {hash:{hash}})
ON CREATE SET r.names = {name}
ON MATCH SET r.names = r.names + {name}
but obviously if {name} is already in r.names, it just gets added again. How can I add {name} only if r.names doesn't already contain it?
I guess you need to use the FOREACH + CASE WHEN trick: using a case when you use either a 1 element array (if your condition is true) or a 0 element array otherwise as iterator used in FOREACH. FOREACH cannot be used in a ON MATCH or ON CREATE handler, so we put it after the MERGE and use a coalesce to cover the case when r.names does not yet exist:
MERGE (r:Resource {hash:{hash}})
FOREACH(x in CASE WHEN {name} in r.names THEN [] ELSE [1] END |
SET r.names = coalesce(r.names,[]) + {name}
)
RETURN r.names
Use FILTER to get an array of the elements that aren't already in r.names and add them:
MERGE (r:resource {hash:{hash}})
ON CREATE SET r.names = {new_names}
ON MATCH SET r.names = r.names + FILTER(
el FOR el in {new_names} IF NOT el IN r.names
)

Watir Rspec Ruby : Comparing new/edited value with old/previous value

Auto generated name twice, first
$name = generate_name
self.name = $name
produces: $name is "Abc"
And then edited the $name to be "Xyz". Which causes the previous/old name to be no longer available/saved in the app, its overwritten by new/edited name.
I now have to compare the two values of same variable $name to ensure that name is edited.
using expect($name).to_not eq($old_name)
I don't understand how to save the previous/old name into another variable $old_name before overwriting it?
Before you change $name to be "Xyz", or test for equality, you need to set $old_name to be equal to $name.
Something like this:
$name = generate_name
self.name = $name
$old_name = self.name
$name = Xyz
self.name = $name
using expect($name).to_not eq($old_name)

Passing Multi Value Paramter in stored proc

Firstname emp_Fullname
--------------------------------------
chetan Patel, Chetan
mike Shah, Mike
ronie Desai, Ronie
create proc stored_procedure
#firstnamer varchar(max)
#fullname varchar(max)
as
begin
select ......
from....
where Firstname in (SELECT Value FROM dbo.FnSplit(#firstname,','))
--and emp_Fullname in (SELECT Value FROM dbo.FnSplit(#fullname,','))
I want result for below statement
exec stored_procedure 'chetan,ronie', 'Patel, Chetan,Shah, Mike'
How can I pass more than 2 emp_fullname in parameter in given stored procedure? Below is my function dbo.FnSplit that worked for multi value Firstname parameter but not working multi value fullname parameter.
ALTER FUNCTION [dbo].[FnSplit]
(
#List nvarchar(2000),
#SplitOn nvarchar(5)
)
RETURNS #RtnValue table (Id int identity(1,1), Value nvarchar(100))
AS
BEGIN
WHILE(Charindex(#SplitOn, #List) > 0)
BEGIN
INSERT INTO #RtnValue (value)
SELECT
VALUE = ltrim(rtrim(Substring(#List, 1, Charindex(#SplitOn, #List) - 1)))
SET #List = SUBSTRING(#List, Charindex(#SplitOn, #List) + len(#SplitOn), len(#List))
END
INSERT INTO #RtnValue (Value)
SELECT
VALUE = ltrim(rtrim(#List))
RETURN
END
Firstname in (SELECT Value FROM dbo.FnSplit(#firstname,'|'))
and emp_Fullname in (SELECT Value FROM dbo.FnSplit(#fullname,'|'))
and I figured that still in SSRS double click on dataset click parmater instead of default value choose expression and set it to "join(#firstname.value,"|")" and samething for other "join(#fullname.value,"|")" and now run it. Multi valye parameter should work find by doing above procedure.
Thanks to my self lol:) it took me 3 days to figured, thought you guys can use it!

Array to key value pair (Hash)

>> description
=> [" name=\"margin-top\" content=\"1\" />\r\n", " name=\"oreintation\" content=\"horizontal\" />\r\n", " name=\"paper-height\" content=\"6\" />\r\n", " name=\"paper-width\" content=\"5\" />\r\n", " name=\"margin-left\" content=\"3\" />\r\n"]
description is of type array
I need key as margin-top value 1.
I need key as oreintation value oreintation and so on, how to get this done?
Use
result = {}
description.each{|val|
result[val.split("\"")[1]] = val.split("\"")[3]
}
result # contains expected hash

String comparison passing through if statement when it shouldn't

I'm comparing values of an excel sheet to record values returned from a database and one record is passing through the if statement when it should fail the if statement.
The if statement looks like this:
if (record.value.equals(cellVal) == false)
{
record.value = cellVal
record.modifyUser = userId
//dataService.updateManualEntry(record)
println "UPDATING ${record.value.equals(cellVal)}"
println "record value: ${record.value}"
updatedCount++
}else{
println "NOT UPDATING [ [ ${record.value.length()} ] + [${cellVal.length()}]"
}
}
The println shows that the value of println "UPDATING ${record.value.equals(cellVal)}" evaluates to be true, in which case I don't understand why it is passing through the if statement. In addition the length of the string is 0.
Can I get a second pair of eyes and figure out why a true value would get through this if statement?
Your printlns happen after you have changed the value to match.
Here:
record.value = cellVal
You have set record.value to cellVal inside the if block. That's why the println returns true.
(true == false) ⇒ false
the println is showing true becoz of the 1st line in your if statement
record.value = cellVal
try printing the same value before if statement.
if ->record.value.equals(cellVal) give u false
u compare (false)==false, naturally false is always = false, hence it will pass through
2nd, look at ur code,
record.value = cellVal
record.modifyUser = userId
//dataService.updateManualEntry(record)
println "UPDATING ${record.value.equals(cellVal)}"
U assign record.value = cellVal before u do a print.
Of cuz it will print true.

Resources