Announcement

Collapse
No announcement yet.

Displaying Loop Index in a Control

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Displaying Loop Index in a Control

    I've written complex program for number crunching.
    However, I would like to display running index from a loop:
    say FOR I=1 to 500 ===> Display I.

    So I created Main window with CreateWindow and then
    Dialog New and I added a Textbox into the Dialog.

    The program does not display running index from within the loop
    but only when the loop has finished it displays I=500 in the Textbox.
    Any ideas, what am i doing wrong?
    Branko S. Bedenik
    http://www.fg.uni-mb.si/lak/ocean


    Structural Engineering Software OCEAN2006
    Slovenia

    #2
    Branko --
    Don't know how you set text, but of course you need Sleep to give a possibillity to OS to process messages.
    Another variant - use UpdateWindow (for DDT - something like UpdateWindow GetDlgItem(hDlg, id)

    ------------------

    Comment


      #3
      The following code shows the basic technique with a Modeless dialog. If you use a Modal dialog, and trigger the counter from, say, a "start" button, then instead of DIALOG DOEVENTS, you would use UpdateWindow() after CONTROL SET TEXT.

      Code:
      #COMPILE EXE
      #INCLUDE "DDT.INC"
      
      $AppInfo = "The counter reads:"
      
      FUNCTION PBMAIN
          DIM hDlg AS LONG
          DIALOG NEW 0, "Counter Example",,, 100, 34, %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU TO hDlg
          CONTROL ADD LABEL, hDlg, 100, "", 10, 10, 80, 14, %SS_CENTER
          DIALOG SHOW MODELESS hDlg
          FOR x& = 1 TO 100
              CONTROL SET TEXT hDlg, 100, $AppInfo & STR$(x&)
              DIALOG DOEVENTS
              Sleep 100
          NEXT x&
          DIALOG END hDlg
      END FUNCTION

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


        #4
        Word of advice though... if your counter will be counting a alot of things really fast you may want to only update the display in intervals.

        This way the real code processes faster when when windows doesn't have to stop to update the index EVERY time.

        ------------------
        <b>George W. Bleck</b>
        <img src='http://www.blecktech.com/myemail.gif'>

        Comment


          #5
          Thanks guys for help.
          i'm using

          Control set text hDlg, id, format$(I,"####")
          UpdateWindow GetDlgItem(hDlg, id)

          method and it works fine

          regards
          Branko S Bedenik

          ------------------
          http://www.fg.uni-mb.si/lak/ocean


          Structural Engineering Software OCEAN2006
          Slovenia

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎