emy
New Member
Hello
Posts: 45
|
Post by emy on Apr 25, 2022 12:07:48 GMT -5
Hello every one, I try to make working the following code, but I d'ont see where I did make mistake. Thanks for Your advise.
p(1) = 0
p(2) = 8
p(3) = 34
p(4) = 100
nomainwin
WindowWidth = 300 : WindowHeight = 160
UpperLeftX = 14 : UpperLeftY = 30
UpperLeftX = 320
UpperLeftY = 200
statictext #trt.stt11, "Value1", 30, 45, 80, 20
statictext #trt.stt12, "Value2", 90, 45, 80, 20
statictext #trt.stt13, "Value3", 140, 45, 80, 20
statictext #trt.stt14, "Value4", 190, 45, 80, 20
open "Stats" for window_nf as #trt
#trt, "trapclose [quittrt]"
'..................
for i = 1 to 4
s = p(i)
select case s
case 0
var2$ = "#trt.stt1" + str$(i)
#var2$, str$(0) + "%"
case (s > 0) or (s < 9)
var2$ = "#trt.stt1" + str$(i)
'#var2$, using("#.#",p(i)) + "%"
#var2$, using("#.#",s) + "%"
case (s > 9) or (s < 99)
var2$ = "#trt.stt1" + str$(i)
'#var2$, using("##.#",p(i)) + "%"
#var2$, using("##.#",s) + "%"
case 100
var2$ = "#trt.stt1" + str$(i)
#var2$, using("###.#",p(i)) + "%"
end select
next i
'..................
wait
'------------------
[quittrt]
close #trt
wait
'------------------
insert code here
|
|
|
Post by Rod on Apr 25, 2022 12:54:04 GMT -5
what do you expect
#var2$,
to do?
print var2$ would print the contents of var2$ var2$= would fill the contents of var2$ #var2$ is not a recognised command unless you are using a handle variable which I dont think you are.
|
|
|
Post by tenochtitlanuk on Apr 25, 2022 14:22:56 GMT -5
You are having trouble understanding statictest etc, and also a logic error of 'or' where you need and. Run this simplified version which just puts the results on the 'main window'. For correct spacing make sure the font is 'monospaced' like Courier.
for i = 1 to 4 read s select case case s =0 print str$( 0) + "%" case ( s >0) and ( s <9) print using( "#.#", s) + "%" case ( s >9) and ( s <99) print using( "##.#", s) + "%" case s =100 print using( "###.#", s) + "%" end select next i
end
data 0, 8, 34, 100
For nicer aligned formatting, try this mod.
for i = 1 to 4 read s
select case case s =0 print right$( " " +"0", 5) + "%" case ( s >0) and ( s <9) print right$( " " +using( "#.#", s), 5) + "%" case ( s >9) and ( s <99) print right$( " " +using( "##.#", s), 5) + "%" case s =100 print using( "###.#", s) + "%" end select next i
end
data 0, 8, 34, 100
Even then, you have left yourself with uncertainty with say numbers like 99.5 ......
|
|
emy
New Member
Hello
Posts: 45
|
Post by emy on Apr 26, 2022 2:03:15 GMT -5
Thank You Rod for Your answer. Thank You Tenochtitlanuk, I will try Your method.
|
|
|
Post by tsh73 on Apr 26, 2022 5:35:10 GMT -5
Two more things to be added
One, then dividing numeric interval, you usually want all points to actually mean something So
for x = .5 to 1.5 step .5 print x, select case case x >0 and x <1 print "case 1" case x >1 and x <10 print "case 2" case else print "Nothing fits" end select next
produces
0.5 case 1 1 Nothing fits 1.5 case 2
- likely not what you wanted.
Common pattern is to use <= on one side, like this
for x = .5 to 1.5 step .5 print x, select case case 0<=x and x <1 print "case 1" case 1<=x and x <10 print "case 2" case else print "Nothing fits" end select next
Then "1" goes to "case 2"
0.5 case 1 1 case 2 1.5 case 2
Two Why do you use different print using, at all? You probably seen that
print using ("#.#", 10) gives
%10.0 Here "%" is that sign that number did nit fit to format string (number too big)
You program something around that - but do you avare that print using rounds numbers, up and down, at .5 points? So
print using ("#.#", 9.94999) gives
9.9 , but
print using ("#.#", 9.95) again gives
%10.0
Why not use
print using ("###.#", 10) all the time?
If you concerned about extra leftside spaces, you can just trim them
print using ("###.#", 9.94) print trim$(using ("###.#", 9.94))
9.9 9.9
|
|
emy
New Member
Hello
Posts: 45
|
Post by emy on Apr 27, 2022 7:13:12 GMT -5
Thank You tsh73, I appreciate Your advice, useful.
Reading tenochtitlanuk's example, I see that I did not use 'select case/end select' correctly.
I code it in a different manner.
Rod, the following code works nice on my PC with Window XP
p(1) = 0 : p(2) = 8 : p(3) = 34 : p(4) = 100
nomainwin
WindowWidth = 300 : WindowHeight = 160 UpperLeftX = 14 : UpperLeftY = 30 UpperLeftX = 320 : UpperLeftY = 200
statictext #trt.stt11, "Value1", 30, 45, 80, 20 statictext #trt.stt12, "Value2", 90, 45, 80, 20 statictext #trt.stt13, "Value3", 150, 45, 80, 20 statictext #trt.stt14, "Value4", 210, 45, 80, 20
open "Statistics" for window_nf as #trt #trt, "trapclose [quittrt]"
for i = 1 to 4 if p(i) > 0 then if p(i) < 100 then var1$ = "#trt.stt1" + str$(i) #var1$, using("##.#",p(i)) + "%" else var1$ = "#trt.stt1" + str$(i) #var1$, using("###.#",p(i)) + "%" end if else var1$ = "#trt.stt1" + str$(i) #var1$, using("#",p(i)) + "%" end if next i wait
[quittrt] close #trt wait
|
|