|
Post by turtleman on Oct 15, 2022 10:50:00 GMT -5
As is often the case, I use a lot more code to do simple things than is probably necessary. Sometimes I figure it out and reduce the number of lines considerably – sometimes not. Here's a much-simplified example used to populate legends on graph. A combobox selects the "scale" for different legends.
if yscale = 1 then #plot.100, "down" #plot.100, "place 1 12; font arial 9" #plot.100, "\ $100 " #plot.100, "delsegment plot.100" #plot.100, "flush plot.100"
#plot.50, "down" #plot.50, "place 1 12; font arial 9" #plot.50, "\ $50 " #plot.50, "delsegment plot.50" #plot.50, "flush plot.50"
#plot.0, "down" #plot.0, "place 1 12; font arial 9" #plot.0, "\ $0 " #plot.0, "delsegment plot.0" #plot.0, "flush plot.0" end if if yscale = 2 then #plot.100, "down" #plot.100, "place 1 12; font arial 9" #plot.100, "\ $200 " #plot.100, "delsegment plot.100" #plot.100, "flush plot.100"
#plot.50, "down" #plot.50, "place 1 12; font arial 9" #plot.50, "\ $100 " #plot.50, "delsegment plot.50" #plot.50, "flush plot.50"
#plot.0, "down" #plot.0, "place 1 12; font arial 9" #plot.0, "\ $0 " #plot.0, "delsegment plot.0" #plot.0, "flush plot.0" end if
And so on …
The code works fine, but with over 9 legends per 5 scale selections, it seems kind of repetitious. So, I'm once again risking embarrassment to see how you experts would go about it. Thanks!
|
|
|
Post by Walt Decker on Oct 15, 2022 12:22:09 GMT -5
NOT TESTED: ' if yscale = 2 then RetVal = FN.DoNum("#plot.100", "\ $200") RetVal = FN.DoNum("#plot.50", "\ $100") RetVal = FN.DoNum("#plot.0", "\ $0 ") END IF
'---------------------------------- '----------------------------------
FUNCTION FN.DoNum(Tag$, Txt$) PRINT #Tag$, "down" PRINT #Tag$, "place 1 12; font arial 9" PRINT #Tag$, Txt$ PRINT #Tag$, "delsegment ";Tag$ PRINT #Tag$, "flush ";Tag$
END FUNCTION '
|
|
|
Post by turtleman on Oct 16, 2022 6:47:15 GMT -5
Thanks Walt, but I don't understand (Tag$, Txt$).
|
|
|
Post by turtleman on Oct 16, 2022 9:13:30 GMT -5
Now that I've read, reread, and reread about "FUNCTION," I have a better understanding and the code you supplied is working!!!
So now I have another simplification question.
For yscale = 1, yscale = 2, through yscale = 5, the digits after the "\ $xxx " are multiplied by 2 for each scale: $100 for scale1, $200 for scale 2, $400 for scale 3, $800 for scale 4, and $1000 for scale5.
Rather than repeating
RetVal = FN.DoNum("#plot.100", "\ $200")
RetVal = FN.DoNum("#plot.50", "\ $100")
RetVal = FN.DoNum("#plot.0", "\ $0 ")
for each scale, is there some way to multiply the numbers contained in "\ $xxx"
(There are actually 9 "\ $xxx" for each scale), so the code is still rather lengthy.
(Plot.100, plot.75, plot.50, etc. relate to graphicbox locations and aren't issues.)
I hope this makes some sense, but thanks for your help anyway!
|
|
|
Post by Walt Decker on Oct 16, 2022 10:05:59 GMT -5
Is this what you mean?
"\$0" X 2 = 0 "\$50" X 2 = 100 "\$100" X 2 = 200
|
|
|
Post by turtleman on Oct 16, 2022 11:26:28 GMT -5
Kind of. As in your example: "\$0" X 2 = 0 "\$50" X 2 = 100 "\$100" X 2 = 200
I'd like to substitute the yscale number for the X 2, but that only prints what's between the quotes.
|
|
|
Post by Walt Decker on Oct 16, 2022 12:01:27 GMT -5
I think this is what you want, but not sure. I have changed the function and commented it so you might understand better what is happening in the function. Now it only has to be called once for each value of yscale. NOT TESTED ' RetVal = 0 Value = 0 SELECT CASE yscale CASE 1 Value = yscale * 100 RetVal = FN.DoNum("#plot.", 100, Value) CASE 2 Value = yscale * 100 RetVal = FN.DoNum("#plot.", 100, Value) END SELECT
'--------------------------------------------- '---------------------------------------------
FUNCTION FN.DoNum(Tag$, PlotNum, Value) '#################################################### ' THE FUNCTION ASSUMES THERE ARE 3 GRAPHIC CONTROLS ' NUMBERED PLOT.100, PLOT.50, AND PLOT.0 ' ' FUNCTION INPUT: ' Tag$ = front part of graphic control tag, e. g. "#PLOT." ' PlotNum = trailing part of graphic control tag, e. g. 25 ' Tag$ and PlotNum are concatenated to produce ' e. g. "PLOT.25 ' Value = amount to display in graphic control ' '####################################################
PlotTxt$ = "" '<--- text to display Plot$ = "" '<--- graphic control PlotNo$ = "" '<--- segment number
'<========== DO THIS UNTIL VALUE IS LESS THAN ZERO ============> WHILE PlotNum > -1 PlotTxt$ = "\ $" + STR$(Value) '<--- text to display Plot$ = Tag$ + STR$(PlotNum) '<--- graphic control tag PlotNo$ = "plot." + STR$(Value) '<--- graphic control segment
PRINT #Plot$, "segment ";PlotNo$ '<--- get segment number PRINT #Plot$, "down" PRINT #Plot$, "place 1 12; font arial 9" PRINT #Plot$, PlotTxt$ PRINT #Plot$, "flush ";PlotNo$ PRINT #Plot$, "delsegment ";PlotNo$ Value = Value - (Value * .5) PlotNum = PlotNum - 50 WEND
END FUNCTION '
|
|
|
Post by Walt Decker on Oct 16, 2022 13:00:14 GMT -5
Actually, the above will not produce what you want since in your example for yscale = 2 you do 200, 100, 0. If for yscale = 3 you do 300, 100, 0 the function would have to revert to the original and call it for each value.
|
|
|
Post by Walt Decker on Oct 16, 2022 13:30:47 GMT -5
Here is a slightly different approach based on what I think you want. It uses the same one-shot function but with slightly different input.
NOT TESTED ' RetVal = 0 Value$ = "" SELECT CASE yscale CASE 1 Value$ = "100, 50, 0" RetVal = FN.DoNum("#plot.", 100, Value$) CASE 2 Value$ = "200, 100, 0" RetVal = FN.DoNum("#plot.", 100, Value$) CASE 3 Value$ = "300, 100, 0" RetVal = FN.DoNum("#plot.", 100, Value$)
END SELECT
'--------------------------------------------- '---------------------------------------------
FUNCTION FN.DoNum(Tag$, PlotNum, Value$) '#################################################### ' THE FUNCTION ASSUMES THERE ARE 3 GRAPHIC CONTROLS ' NUMBERED PLOT.100, PLOT.50, AND PLOT.0 ' ' FUNCTION INPUT: ' Tag$ = front part of graphic control tag, e. g. "#PLOT." ' PlotNum = trailing part of graphic control tag, e. g. 25 ' Tag$ and PlotNum are concatenated to produce ' e. g. "PLOT.25 ' Value$ = string containing amounts to display in graphic control ' '####################################################
PlotTxt$ = "" '<--- text to display Plot$ = "" '<--- graphic control PlotNo$ = "" '<--- segment number
Term = 0 '<--- position in Value$ where value is located
'<========== DO THIS UNTIL VALUE IS LESS THAN ZERO ============> WHILE PlotNum > -1 Term = Term + 1 PlotTxt$ = "\ $" + WORD$(Value$, Term) '<--- text to display Plot$ = Tag$ + STR$(PlotNum) '<--- graphic control tag PlotNo$ = "plot." + STR$(Value) '<--- graphic control segment
PRINT #Plot$, "segment ";PlotNo$ '<--- get segment number PRINT #Plot$, "down" PRINT #Plot$, "place 1 12; font arial 9" PRINT #Plot$, PlotTxt$ PRINT #Plot$, "flush ";PlotNo$ PRINT #Plot$, "delsegment ";PlotNo$ PlotNum = PlotNum - 50 WEND
END FUNCTION '
|
|