From: Bob on
Hi,
Another newbie question.....I have a procedure that uses the "after"
command. I provide the "after" command an argument from multiplying two
values together. The two values come from two scale bars. One of the
scale bar values is multiplied by 0.01 to express the final result as a
percent.
Example:
Scale bar 1 set to 38
Scale bar 2 set to 80
Scale bar 2 value multiplied by 0.01 yielding 0.8
Then Scale bar 1's value of 38 is mulitplied by 0.8 to yield 30.4
I want to use the 30.4 as the argument to the "after" command.

This is not working apparently because the product is a decimal number, and
the "after" command wants an interger. (yes?).
I have tried a number of things to convert the decimal result to an integer,
but so far no luck. I would be fine with a value of 30 or 31 in the above
example. I am using the "set" command to assign all the values above to
variables.

Any help.


From: Aric Bills on
On Jul 12, 7:26 pm, "Bob" <kava...(a)noga.com> wrote:
> Hi,
>   Another newbie question.....I have a procedure that uses the "after"
> command.  I provide the "after" command an argument from multiplying two
> values together.  The two values come from two scale bars.   One of the
> scale bar values is multiplied by 0.01 to express the final result as a
> percent.
> Example:
> Scale bar 1 set to 38
> Scale bar 2 set to 80
> Scale bar 2 value multiplied by 0.01 yielding 0.8
> Then Scale bar 1's value of 38 is mulitplied by 0.8 to yield 30.4
> I want to use the 30.4 as the argument to the "after" command.
>
> This is not working apparently because the product is a decimal number, and
> the "after" command wants an interger. (yes?).
> I have tried a number of things to convert the decimal result to an integer,
> but so far no luck.  I would be fine with a value of 30 or 31 in the above
> example.  I am using the "set" command to assign all the values above to
> variables.
>
> Any help.

set fraction 30.5
set int1 [expr {int($fraction)}]
set int2 [expr {round($fraction)}]
From: Bob on
Thanks for the post. Those commands work fine. :)
Now I'm stuggling with getting some formulas to work when a scale bar is
moved.
>snip<
scale .dit -orient horizontal -label dit -variable dit
scale .dah -orient horizontal -label dah -variable dah
scale .space -orient horizontal -label space -variable space
scale .wpm -orient horizontal -label wpm -from 80 -to 100 -variable wpm
set wpmpercent [expr (0.01*$wpm)]
>snip<
Viewing the variables with puts shows that the variables dit, dah, space,
and wpm change when I drag the appropriate scale bar. However, the variable
wpmpercent sits at 0.8 regardless of what I do with the .wpm scale bar. I
attribute this to the fact that the wpm variable is read once when the
script is run, and it's starting value is 80, but it is not read after that.
I have tried calling a procedure with the -command option to the .wpm scale
bar, to set the wpmpercent variable. The proc appears to run, but it is
complaining about not finding the wpm variable. I've tried using the global
statement for all the variables, but that does not seem to help. I am
clearly chasing my tail at this point.

My goal is to have a variable wpmpercent that goes from 0.8 to 1.0 based on
the .wpm scale bar. Then I want to multiply dit, dah, and space by that
value. Then after converting to integers, feed those values to the after
command.

Any thoughts?

P.S. Yes, indeed I'm building an app that sends Morse code. I have working
code that toggles the RTS line on a com port.



"Aric Bills" <aric.bills(a)gmail.com> wrote in message
news:3b767678-9894-4b28-8ca9-776f4eb8998a(a)i31g2000yqm.googlegroups.com...
On Jul 12, 7:26 pm, "Bob" <kava...(a)noga.com> wrote:
> Hi,
> Another newbie question.....I have a procedure that uses the "after"
> command. I provide the "after" command an argument from multiplying two
> values together. The two values come from two scale bars. One of the
> scale bar values is multiplied by 0.01 to express the final result as a
> percent.
> Example:
> Scale bar 1 set to 38
> Scale bar 2 set to 80
> Scale bar 2 value multiplied by 0.01 yielding 0.8
> Then Scale bar 1's value of 38 is mulitplied by 0.8 to yield 30.4
> I want to use the 30.4 as the argument to the "after" command.
>
> This is not working apparently because the product is a decimal number,
> and
> the "after" command wants an interger. (yes?).
> I have tried a number of things to convert the decimal result to an
> integer,
> but so far no luck. I would be fine with a value of 30 or 31 in the above
> example. I am using the "set" command to assign all the values above to
> variables.
>
> Any help.

set fraction 30.5
set int1 [expr {int($fraction)}]
set int2 [expr {round($fraction)}]


From: Aric Bills on
Use the -command option for the scale widget:

scale .wpm -orient horizontal \
-label wpm -from 80 -to 100 \
-variable wpm -command setWpmPercent

and define setWpmPercent in such a way that it treats wpmpercent as a
global variable (three possibilities follow; pick your favorite):

proc setWpmPercent {num} {
variable wpmpercent [expr {$num * 0.01}]
}

proc setWpmPercent {num} {
global wpmpercent
set wpmpercent [expr {$num * 0.01}]
}

proc setWpmPercent {num} {
set ::wpmpercent [expr {$num * 0.01}]
}

Hope that helps.

Aric
From: Bob on
Ok, here is what I'm trying now....

#####################################
scale .dit -orient horizontal -label dit -variable dit
scale .dah -orient horizontal -label dah -variable dah
scale .space -orient horizontal -label space -variable space
scale .wpm -orient horizontal -label wpm -from 80 -to 100 -variable
wpm -command setwpmpercent

proc setwpmpercent {num} {
global wpmpercent
set wpmpercent [expr {$num * 0.01}]
}

set ditlen [expr {$dit*$wpmpercent}]

pack .dit
pack .dah
pack .space
pack .wpm

#######################################


I'm still getting an error that the wpmpercent variable can't be found in
the 'set ditlen' expression.


"Aric Bills" <aric.bills(a)gmail.com> wrote in message
news:ccfa5346-9dfc-4b85-847d-6683be80547b(a)y11g2000yqm.googlegroups.com...
> Use the -command option for the scale widget:
>
> scale .wpm -orient horizontal \
> -label wpm -from 80 -to 100 \
> -variable wpm -command setWpmPercent
>
> and define setWpmPercent in such a way that it treats wpmpercent as a
> global variable (three possibilities follow; pick your favorite):
>
> proc setWpmPercent {num} {
> variable wpmpercent [expr {$num * 0.01}]
> }
>
> proc setWpmPercent {num} {
> global wpmpercent
> set wpmpercent [expr {$num * 0.01}]
> }
>
> proc setWpmPercent {num} {
> set ::wpmpercent [expr {$num * 0.01}]
> }
>
> Hope that helps.
>
> Aric