LB Booster
« Numeric entry into a textbox »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:23am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: Numeric entry into a textbox  (Read 2323 times)
RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Numeric entry into a textbox
« Reply #23 on: May 25th, 2016, 4:59pm »

on May 23rd, 2016, 10:00am, RNBW wrote:
Whilst the code does enable a grid to be set up in LB, using it with LBB is a bit slow setting up. Also, the fact that a list of 90 textbox controls is set up (1-90) it is not going to be as easy to access the controls as using the grid I have previously set up with RR help where the controls are accessed via row,col.



I have tried to set up Cundo's code using controls in a row/col basis instead of just a long list of controls. I have first set it up to display headers in Row 1 for the columns and Column 1 for the rows. Then tried to set up reading from the other textboxes and printing to the main window. This works but both the grid and the printed data flashes. It seems to be related to the Timer. If you increase the timer value the rate of flash slows. I've played around with various alternatives to contentName$ and h$, to try to get outside the chkInput loop, but it doesn't work. What am I doing wrong?

Code:
'=========================================
' NumInputGrid_LB_LBB_1F.bas
'=========================================
' Sets up Grid of textboxes
' Works by setting up each textbox as a
' pop-up window and then showing them on
' a child window
' Initial Code by Cundo on Liberty Basic
' Forum 20 May 2016 #reply 17
'=========================================

    'NoMainWin

    '--------------------------
    ' Set up #main window size
    '--------------------------
    maxRows = 10: maxCols =9
    dim disp$(maxRows,maxCols)
    WindowWidth = 1000
    WindowHeight = 480
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    '------------------
    ' OPEN THE #main WINDOW
    '------------------
    stylebits   #main, 0, _WS_VISIBLE, 0, 0
    Open "Window" for Window_nf as #main
        #main "trapclose [quit]"

    '-------------------------
    ' CREATE THE CONTROLS
    '-------------------------
    for row = 1 to maxRows
      for col = 1 to maxCols
        textbox #temp.t1,(100*col)-100+50, (25*row)-25+50,100+1,25+1
            stylebits #temp.t1, _ES_RIGHT, _WS_VISIBLE OR _WS_BORDER, 0, 0
            Open "" for Window_popup as #temp
            maphandle #temp.t1, "#";row;col;".t1" ' required for LBB
            maphandle #temp, "#";row;col
      next col
    next row

    '------------------------------------------------------
    'attach the controls to the main handler and show them
    '------------------------------------------------------
    for row = 1 to maxRows
       for col = 1 to maxCols
          h$= "#";row;col;".t1"
          call setParent hWnd(#main) , hWnd(#h$)
          call ShowWindow hWnd(#h$), 1
       next col
    next row

    call ShowWindow hWnd(#main), 1


 [chkInput]
  Timer 0
  for row = 1 to maxRows
     for col = 1 to maxCols
        controlName$="#";row;col;".t1"
        #controlName$ "!contents? txt$"
        new$= remchar$(txt$,"abcdefghijklmn?opqrstuvwxyz")
        if new$<>txt$ Then
           #controlName$ new$
           handle = Hwnd(#controlName$)
           pos = Len(txt$)
           CallDLL #user32, "SendMessageA",_
                             handle As long, _
                             _EM_SETSEL As long,_
                             pos As long,_
                             pos As long,_
                             result As void
         End if
     next col
  next row

 Timer 300, [chkInput]


 '----------------------------------
 ' PRINT ROW NUMBER IN FIRST COLUMN
 '----------------------------------
 for row = 2 to maxRows
    h$ = "#";row;1;".t1"
    #h$ "Row ";row-1
 next row

 '-----------------------------------
 ' PRINT COLUMN NUMBERS IN FIRST ROW
 '-----------------------------------
 for col = 2 to maxCols
    h$ = "#";1;col;".t1"
    #h$ "Col ";col-1
 next col

 '--------------------
 ' GET DATA FROM GRID
 '--------------------
 for row = 2 to maxRows
    for col = 2 to maxCols
    controlName$="#";row;col;".t1"
    #controlName$ "!contents? txt$"
    disp$(row,col) = txt$
    print txt$
    next col
 next row

wait

    [quit]
    close #main    
    for row = 1 to maxRows
        for col = 1 to maxCols
           h$= "#";row;col
           closeMePlease$ = h$
           close #closeMePlease$
        next col
    next row
    end

sub setParent parent,child
    calldll #user32, "SetParent",_
                     child as ulong,_
                     parent as ulong,_
                     r as void
End sub

Sub ShowWindow hWnd, flag
    'SW_HIDE = 0
    'SW_NORMAL = 1
    CallDLL #user32, "ShowWindow",hWnd as uLong, flag As Long, r As void
End Sub

'include lb45func.bas  
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Numeric entry into a textbox
« Reply #24 on: May 25th, 2016, 5:54pm »

on May 25th, 2016, 4:59pm, RNBW wrote:
What am I doing wrong?

The code is working as designed, as far as I can see. You are rejecting any non-numeric characters in the boxes, so when you print (say) "Col 4" to a box the "Col" part fails the validity-check and it gets replaced with just "4"; similarly with the "Row n" boxes.

If your intention was that the row and column 'label' boxes should not be subject to the numeric-character-only check then you should exclude them from it, for example by changing the looping code as follows:

Code:
  for row = 2 to maxRows
     for col = 2 to maxCols 

But I would say the real problem is a poor choice of array indices. In my opinion it would make much more sense to number the 'label' boxes as column 0 and row 0, and then the 'active' part of the grid would start at column 1 and row 1.

I've made that change in the listing below, and - since this is a support forum for LBB - I've modified the code to use the nicer (and faster) LBB method rather than the LB method. I think we've pretty much established that maintaining compatibility with LB has no value.

Code:
'=========================================
' NumInputGrid_LBB_1F.bas
'=========================================
' Sets up Grid of textboxes
' This version is LBB only
' Forum 20 May 2016 #reply 17
'=========================================

    NoMainWin

    '--------------------------
    ' Set up #main window size
    '--------------------------
    maxRows = 10: maxCols = 8
    dim disp$(maxRows,maxCols)
    WindowWidth = 1000
    WindowHeight = 480
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    '-------------------------
    ' CREATE THE CONTROLS
    '-------------------------
    for row = 0 to maxRows
      for col = 0 to maxCols
        textbox #main.tb,100*col+50, 25*row+50,100+1,25+1
        stylebits #main.tb, _ES_RIGHT, _WS_BORDER, 0, 0
        maphandle #main.tb, "#main.tb";row;"x";col
      next col
    next row

    '------------------
    ' OPEN THE #main WINDOW
    '------------------
    stylebits   #main, 0, _WS_VISIBLE, 0, 0
    Open "Window" for Window_nf as #main
        #main "trapclose [quit]"

    call ShowWindow hWnd(#main), 1

    '----------------------------------
    ' PRINT ROW NUMBER IN FIRST COLUMN
    '----------------------------------
    for row = 1 to maxRows
       h$ = "#main.tb";row;"x0"
       #h$ "Row ";row
    next row

    '-----------------------------------
    ' PRINT COLUMN NUMBERS IN FIRST ROW
    '-----------------------------------
    for col = 1 to maxCols
       h$ = "#main.tb0x";col
       #h$ "Col ";col
    next col


 [chkInput]
  Timer 0
  for row = 1 to maxRows
     for col = 1 to maxCols
        controlName$="#main.tb";row;"x";col
        #controlName$ "!contents? txt$"
        new$= remchar$(txt$,"abcdefghijklmn?opqrstuvwxyz")
        if new$<>txt$ Then
           #controlName$ new$
           handle = Hwnd(#controlName$)
           pos = Len(txt$)
           CallDLL #user32, "SendMessageA",_
                             handle As long, _
                             _EM_SETSEL As long,_
                             pos As long,_
                             pos As long,_
                             result As void
         End if
     next col
  next row

 Timer 300, [chkInput]


 '--------------------
 ' GET DATA FROM GRID
 '--------------------
 for row = 1 to maxRows
    for col = 1 to maxCols
    controlName$="#main.tb";row;"x";col
    #controlName$ "!contents? txt$"
    disp$(row,col) = txt$
    print txt$
    next col
 next row

    wait

[quit]
    close #main    
    end

Sub ShowWindow hWnd, flag
    'SW_HIDE = 0
    'SW_NORMAL = 1
    CallDLL #user32, "ShowWindow",hWnd as uLong, flag As Long, r As void
End Sub

'include lb45func.bas 

Richard.
« Last Edit: May 25th, 2016, 5:59pm by Richard Russell » User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Numeric entry into a textbox
« Reply #25 on: May 25th, 2016, 6:42pm »

Richard

Thank you for your response.

There remains a problem. If you REM NoMainwin. The print txt$ in the GET DATA routine should print out the results to the mainwin. These continue to flash as the data is input into the grid (I reduced the number of rows/cols to 3/4 so not too much data) and to scroll. When all data is entered, the flashing and scrolling does not end until the top window is closed just leaving the mainwin. The data displayed is in excess of what should be seen and always seems to start with 24.

I'm scratching my head.

User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Numeric entry into a textbox
« Reply #26 on: May 25th, 2016, 7:39pm »

on May 25th, 2016, 6:42pm, RNBW wrote:
If you REM NoMainwin. The print txt$ in the GET DATA routine should print out the results to the mainwin. These continue to flash as the data is input into the grid

I'm afraid I don't know what you mean; I don't see anything unexpected. As you're outputting a large number of lines (one for every cell in the grid) every 300 milliseconds or so, the mainwin is pretty much constantly scrolling. There's no 'flashing' as such (here) but the scrolling means nothing stays still long enough to read!

Did you perhaps mean to output the data in a grid on the mainwin, so that it never needs to scroll? You could do that as follows:

Code:
 '--------------------
 ' GET DATA FROM GRID
 '--------------------
 for row = 1 to maxRows
    for col = 1 to maxCols
    controlName$="#main.tb";row;"x";col
    #controlName$ "!contents? txt$"
    disp$(row,col) = txt$
    locate 10*col,row
    print txt$;
    next col
 next row 

Richard.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Numeric entry into a textbox
« Reply #27 on: May 25th, 2016, 8:44pm »

on May 25th, 2016, 7:39pm, Richard Russell wrote:
I'm afraid I don't know what you mean; I don't see anything unexpected. As you're outputting a large number of lines (one for every cell in the grid) every 300 milliseconds or so, the mainwin is pretty much constantly scrolling. There's no 'flashing' as such (here) but the scrolling means nothing stays still long enough to read!


Perhaps flash was not the correct description. As I said, I reduced the number of textboxes to a 3 row x 4 col grid. This was printed several times in mainwin.

I thought with the for..next loop in the GET DATA section, it would print out the data from 12 textboxes, starting with cell 1/1 through to cell 3/4. It prints it out several times, which accounts for the scrolling.

Thanks for the code for printing out in grid form.

At the end of the day, on LBB given the choice of this method or creating a grid as previous postings some time ago, I will stick with the latter. It is easier to create and edit and does all that I could ask for. Once again, I thank you for your help with that.

With regards to LB, I shall post the code I produced on the LB site, and hopefully someone there will come up with a solution for LB.

Richard, as usual, you come up with the goods!
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Numeric entry into a textbox
« Reply #28 on: May 25th, 2016, 9:11pm »

on May 25th, 2016, 8:44pm, RNBW wrote:
As I said, I reduced the number of textboxes to a 3 row x 4 col grid. This was printed several times in mainwin.

I am still not really understanding. What difference did you expect reducing to "a 3 row x 4 col grid" to make? It's still outputting 12 lines every 300ms, that's more than 36 lines every second, which is far too fast for anybody to read and of course will mean it starts to scroll almost immediately!

Quote:
I thought with the for..next loop in the GET DATA section, it would print out the data from 12 textboxes, starting with cell 1/1 through to cell 3/4. It prints it out several times, which accounts for the scrolling.

Again you say "it prints out several times" as if this was a surprise. Did you not mean to put the printing routine in your TIMER handler? Having done so of course it prints out "several times": it prints out every 300ms!

Quote:
hopefully someone there will come up with a solution for LB.

But surely (until I modified it) your solution was for LB! I thought that was the whole point of you using the 'cundo' method of creating the boxes initially as separate windows.

Richard.
User IP Logged

RNBW
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 106
xx Re: Numeric entry into a textbox
« Reply #29 on: May 25th, 2016, 9:44pm »

I thought I had put the print routine outside the timer handler. So this is where I went wrong.

Your final solution is for LBB only. So there code I had produced up to then I shall post on LB, because I don't have time to take it any further.

As I said in my last post, I'll use the textbox grid system developed some weeks ago for LBB. It would be nice though if someone on LB could produce the relevant code to let Cundo's methods be used on LB. I don't know when I will be able to get back to it.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls