Author |
Topic: Variable Number Of Rows Of Texboxes (Read 2368 times) |
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #20 on: Apr 14th, 2015, 5:35pm » |
|
Following on from the code that Richard Russell provided to set up a table using MAPHANDLE, I've progressed quite well, but now I'm trying to get data that has been entered into the table by the user and then print it into a texteditor control. I've tried all sorts of things, but I just can't get my head around it. I've set up the code below, which doesn't work.
Code:
NumOfRows = 4
for row = 1 to NumOfRows
for col = 0 to 4
textbox #w.tb, 10+col*55, row*20, 55, 20
maphandle #w.tb, "#w.tb";row;col
next col
next row
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid" for window as #w
'#w.tb42 "Some text"
'wait
[Calc]
for row = 1 to NumOfRows
for col = 1 to 4
h$ = "w.tb";row;col
b$ = "!contents? h$"
#w.ted, b$
maphandle #w.tb, "#w.tb";row;col
next
next
wait
What am I doing wrong. How do I get the text entered into the table into the texteditor?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #21 on: Apr 14th, 2015, 6:16pm » |
|
on Apr 14th, 2015, 5:35pm, RNBW wrote:| How do I get the text entered into the table into the texteditor? |
|
Code:NumOfRows = 4
for row = 1 to NumOfRows
for col = 0 to 4
textbox #w.tb, 10+col*55, row*20, 55, 20
maphandle #w.tb, "#w.tb";row;col
next col
next row
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid" for window as #w
#w.tb42 "Some text"
wait
[Calc]
#w.ted "!cls"
for row = 1 to NumOfRows
for col = 1 to 4
h$ = "#w.tb";row;col
#h$ "!contents? b$"
#w.ted, b$
next
next
wait
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #22 on: Apr 14th, 2015, 6:48pm » |
|
on Apr 14th, 2015, 6:16pm, Richard Russell wrote: Code:NumOfRows = 4
for row = 1 to NumOfRows
for col = 0 to 4
textbox #w.tb, 10+col*55, row*20, 55, 20
maphandle #w.tb, "#w.tb";row;col
next col
next row
texteditor #w.ted, 10, 150, 200,100
button #w.btn, "CALC", [Calc], UL, 210,150,60,30
open "Textbox grid" for window as #w
#w.tb42 "Some text"
wait
[Calc]
#w.ted "!cls"
for row = 1 to NumOfRows
for col = 1 to 4
h$ = "#w.tb";row;col
#h$ "!contents? b$"
#w.ted, b$
next
next
wait |
|
It's so obvious isn't it. I thought I'd used all the combinations, but obviously not. Just a small correction, in the last loop it should be FOR col = 0 TO 4 otherwise for some reason, it doesn't print the entry from the Row1/Col1 box.
Thanks very much Ray :)
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #23 on: Apr 15th, 2015, 3:55pm » |
|
I've moved on a bit with my coding and I'm trying out routines to: a). Only accept numeric input (0-9, -, and .) b). Format the output to 2 decimal places.
Thanks to a FUNCTION NumberOnly$() written by Bob Bromley on LB Conforums May 5, 2004, I've found code that does that and I've got it to work in my example code. The problem is, it's brought up two problems.
1. When I try to set up loops to clear textboxes, I can't get it to work. As can be seen in the code, I've tried different methods. 2. In the function, if a non-numeric character is entered, a NOTICE pops up. If I put a GOTO a label in the function it just sets up a continuous loop that I can't get out of and if I don't then clearing the NOTICE and removing the offending character then leaves me in limbo. I've tried this with some other code and it works without a GOTO a label, but not in this code.
The code is below: Code:
' THIS CODE UTILISES A FUNCTION NumberOnly$() written by Bob Bromley - May 5, 2004
' WHICH I HAVE MODIFIED, BECAUSE I ONLY WANT TO ENSURE NUMERIC ENTRY.
' BOB BROMLEY ALSO PRODUCED CODE THAT UTILISES TRIM$ AND USING TO PRODUCE FORMATTED
' NUMERICAL OUTPUT.
' Thank you Bob for the code you produced.
' The code checks numeric entry for each textbox and then produces it, formatted to
' 2 decimal places in the textbox immediately below. A NOTICE will pop up if a non-
' numeric character is entered and the COMPUTE button pressed.
' The numbers are then listed in a texteditor.
' The COMPUTE button can be pressed after each entry or after all boxes have been
' completed. The downside of the latter, is that the ERROR NOTICE will pop up but
' won't say which box is incorrect.
NOMAINWIN
' SET UP WINDOW SIZE AND POSITION
WindowWidth = 600 : WindowHeight = 630
UpperLeftX = int((DisplayWidth - WindowWidth) / 2)
UpperLeftY = int((DisplayHeight - WindowHeight) / 2)
' SET UP THE CONTROLS
STATICTEXT #m.stat4, "Enter numbers into first four boxes of top row", 35, 0, 400, 20
STATICTEXT #m.stat1, "Unformatted Numbers: Enter number", 35, 15, 290, 20
STATICTEXT #m.stat3, "TOTAL", 355, 15, 75,20
TEXTBOX #m.txt11, 35, 40, 75, 20
TEXTBOX #m.txt12, 110, 40, 75, 20
TEXTBOX #m.txt13, 185, 40, 75, 20
TEXTBOX #m.txt14, 260, 40, 75, 20
TEXTBOX #m.txt15, 335, 40, 75, 20
STATICTEXT #m.stat2, "Formatted Numbers: The numeric results are", 35, 70, 290, 20
TEXTBOX #m.txt21, 35, 90, 75, 20
TEXTBOX #m.txt22, 110, 90, 75, 20
TEXTBOX #m.txt23, 185, 90, 75, 20
TEXTBOX #m.txt24, 260, 90, 75, 20
TEXTBOX #m.txt25, 335, 90, 75, 20
STATICTEXT #m.stat5, "Summary Results", 35, 220, 150, 20
TEXTEDITOR #m.Ted1, 35, 250, 300, 150
BUTTON #m.btn1, "Reset", [ResetAll], UL, 60, 160, 60, 25
BUTTON #m.btn2, "Compute", [Compute], UL, 172, 160, 60, 25
'Open a window for showing the controls and entering data
OPEN "Filtered Numeric Input" FOR WINDOW_NF AS #m
#m "trapclose [Quit]"
' I'm not sure of the benefit of the next two lines, because if numbers
' are entered in these boxes they will be overridden by the figures entered
' in the top row, formatted and displayed in the second row and the totals
' calculated and similarly displayed.
'#m.txt15, "!disable"
'#m.txt21, "!disable": #m.txt22, "!disable": #m.txt23, "!disable": #m.txt24, "!disable": #m.txt25, "!disable":
GOTO [ResetStart]
[Compute] ' Format the entered numbers and calculate total
'This routine doesn't quite work. It prints out the results
'correctly in the texteditor, but then prints out a series
'of 0.00 before entering the total.
FOR row = 1 TO 2
FOR col = 1 TO 4
h1$ = "#m.txt";1;col
#h1$ "!contents? amt$"
h2$ = "#m.txt";2;col
amt = CheckDecPoints(amt$) ' Check for one decimal point
amt = NumberOnly(amt$) ' Make the conversion
'#h1$,
num(row,col) = amt
#h2$, (USING("############.##", num(1,col))) ' Put the result in the lower textbox
#m.Ted1, (USING("############.##", num(row,col)))
maphandle #m.txt, "#m.txt";row;col
next
next
total = num(1,1) + num(1,2) + num(1,3) + num(1,4)
amt = total
#m.txt15, amt
#m.txt25, (USING("############.##",amt))
#m.Ted1, (USING("############.##", amt))
WAIT
[ResetAll] ' Blank the textboxes
FOR row = 1 TO 2
FOR col = 1 TO 4
h1$ = "#m.txt";row;col
h2$ = "#m.txt";row;col
#h1$, ""
#h2$, ""
NEXT col
NEXT row
#m.Ted1, "!CLS"
[ResetStart] ' Blank both the textboxes
FOR row = 1 TO 2
FOR col = 1 TO 4
h1$ = "#m.txt";row;col
h2$ = "#m.txt";row;col
a$ = STR$(0)
#h1$, "!CLS"
#h2$, "!CLS"
NEXT col
NEXT row
#m.Ted1, "!CLS"
WAIT
[Quit]
CLOSE #m
END
'---------------------------------------------------------------------
'
' FUNCTIONS
'
'---------------------------------------------------------------------
FUNCTION NumberOnly(in$) ' Here is the meat of it!
[Start]
FOR i = 1 TO LEN(in$)
t$ = MID$(in$, i, 1)
[DoItAgain]
SELECT CASE
' Do nothing if t$ is a numeral or a decimal point
CASE ASC(t$) = 46 OR (ASC(t$) > 46) AND (ASC(t$) < 58)
' A minus sign is ok, as long as it preceeds the numbers
CASE ASC(t$) = 45 AND i = 1
CASE ELSE
' Error!! Only valid numbers 0-9, - , and . can be entered
NOTICE "ERROR!!! Please enter a valid number (0-9 - . )"
'GOTO [Start]
'GOTO [DoItAgain]
END SELECT
NEXT
NumberOnly = VAL(in$)
END FUNCTION
' We must allow decimal points, but more than 1 will give us an incorrect return.
' So the first thing to do is count them, and stop here if there is more than 1.
' Use this for severe error-checking.
FUNCTION CheckDecPoints(amt$)
t = 0
FOR i = 1 TO LEN(amt$)
t$ = MID$(amt$, i, 1) : IF t$ = "." THEN t = t + 1
IF t > 1 THEN NOTICE "Only 1 decimal point is allowed in the number! " : WAIT
NEXT
END FUNCTION
'---------------------------------------------------------------------
Has anyone got any ideas/solutions?
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 1348
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #24 on: Apr 15th, 2015, 4:30pm » |
|
on Apr 15th, 2015, 3:55pm, RNBW wrote:| Has anyone got any ideas/solutions? |
|
Delete this line, it's meaningless (there is no handle #m.txt) and breaks the rest of the program by zeroing the textbox handles:
Code: maphandle #m.txt, "#m.txt";row;col I should perhaps add a test in LBB for an undefined handle being supplied, rather than simply failing 'silently'.
Richard.
|
|
Logged
|
|
|
|
RNBW
Full Member
member is offline


Gender: 
Posts: 106
|
 |
Re: Variable Number Of Rows Of Texboxes
« Reply #25 on: Apr 15th, 2015, 5:11pm » |
|
on Apr 15th, 2015, 4:30pm, Richard Russell wrote:Delete this line, it's meaningless (there is no handle #m.txt) and breaks the rest of the program by zeroing the textbox handles:
Code: maphandle #m.txt, "#m.txt";row;col I should perhaps add a test in LBB for an undefined handle being supplied, rather than simply failing 'silently'.
Richard. |
|
Richard Thank you for your very prompt resolution of the problem. The code now works nicely, even the NOTICE bit. I've checked back on my other code and found that the maphandle wasn't there, so that is why it worked in that case.
It could be useful to include a check in LBB. It would help to cover up my programming incompetence.
Ray
|
|
Logged
|
|
|
|
|