Author Topic: [Inform]WordSearcher... but Listbox doesn't work well  (Read 602 times)

Offline TempodiBasic

  • Forum Resident
  • Posts: 1415
[Inform]WordSearcher... but Listbox doesn't work well
« on: May 18, 2019, 01:36:02 PM »
Hi guys
here a Windowed (window based) version of the code of Steve https://www.qb64.org/forum/index.php?topic=1359.msg105517#msg105517 but on running I have had a problem...
program crashes when I click on ListBox after computation!?

Here code:

Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 8
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED WordSearcher AS LONG
  9. DIM SHARED WhatSearchTB AS LONG
  10. DIM SHARED AsStartPartBT AS LONG
  11. DIM SHARED AsEndPartBT AS LONG
  12. DIM SHARED AsAnyPartBT AS LONG
  13. DIM SHARED WorsListFounded AS LONG
  14. REDIM SHARED wordlist(1000000) AS STRING
  15. ': External modules: ---------------------------------------------------------------
  16. '$INCLUDE:'InForm\InForm.ui'
  17. '$INCLUDE:'InForm\xp.uitheme'
  18. '$INCLUDE:'wordsearcher.frm'
  19.  
  20. ': Event procedures: ---------------------------------------------------------------
  21. SUB __UI_BeforeInit
  22.  
  23.  
  24. SUB __UI_OnLoad
  25.     OPEN "Scrabble WordList 2006.txt" FOR BINARY AS #1
  26.     DO UNTIL EOF(1)
  27.         wordcount = wordcount + 1
  28.         LINE INPUT #1, wordlist(wordcount)
  29.     LOOP
  30.     REDIM _PRESERVE wordlist(wordcount)
  31.     CLOSE
  32.  
  33. SUB __UI_BeforeUpdateDisplay
  34.     'This event occurs at approximately 30 frames per second.
  35.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  36.  
  37.  
  38. SUB __UI_BeforeUnload
  39.     'If you set __UI_UnloadSignal = False here you can
  40.     'cancel the user's request to close.
  41.  
  42.  
  43. SUB SearcheR (Mode AS INTEGER)
  44.     m$ = _TRIM$(UCASE$(Text(WhatSearchTB)))
  45.     l = LEN(m$)
  46.     SELECT CASE Mode
  47.         CASE 1 ' STA
  48.             FOR i = 1 TO wordcount
  49.                 IF LEFT$(wordlist(i), l) = m$ THEN AddItem WorsListFounded, wordlist(i)
  50.                 '    _DELAY .3
  51.             NEXT
  52.         CASE 2 '"END"
  53.             FOR i = 1 TO wordcount
  54.                 IF RIGHT$(wordlist(i), l) = m$ THEN AddItem WorsListFounded, wordlist(i)
  55.                 '  _DELAY .3
  56.             NEXT
  57.         CASE 3 '"CON"
  58.             FOR i = 1 TO wordcount
  59.                 IF INSTR(wordlist(i), m$) THEN AddItem WorsListFounded, wordlist(i)
  60.                 '  _DELAY .3
  61.             NEXT
  62.         CASE ELSE
  63.             END
  64.     END SELECT
  65.  
  66.  
  67. SUB __UI_Click (id AS LONG)
  68.     SELECT CASE id
  69.         CASE WordSearcher
  70.  
  71.         CASE WhatSearchTB
  72.  
  73.         CASE AsStartPartBT
  74.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  75.                 ResetList WorsListFounded
  76.                 SearcheR 1
  77.             END IF
  78.         CASE AsEndPartBT
  79.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  80.                 ResetList WorsListFounded
  81.                 SearcheR 2
  82.             END IF
  83.         CASE AsAnyPartBT
  84.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  85.                 ResetList WorsListFounded
  86.                 SearcheR 3
  87.             END IF
  88.         CASE WorsListFounded
  89.  
  90.     END SELECT
  91.  
  92. SUB __UI_MouseEnter (id AS LONG)
  93.     SELECT CASE id
  94.         CASE WordSearcher
  95.  
  96.         CASE WhatSearchTB
  97.  
  98.         CASE AsStartPartBT
  99.  
  100.         CASE AsEndPartBT
  101.  
  102.         CASE AsAnyPartBT
  103.  
  104.         CASE WorsListFounded
  105.  
  106.     END SELECT
  107.  
  108. SUB __UI_MouseLeave (id AS LONG)
  109.     SELECT CASE id
  110.         CASE WordSearcher
  111.  
  112.         CASE WhatSearchTB
  113.  
  114.         CASE AsStartPartBT
  115.  
  116.         CASE AsEndPartBT
  117.  
  118.         CASE AsAnyPartBT
  119.  
  120.         CASE WorsListFounded
  121.  
  122.     END SELECT
  123.  
  124. SUB __UI_FocusIn (id AS LONG)
  125.     SELECT CASE id
  126.         CASE WhatSearchTB
  127.  
  128.         CASE AsStartPartBT
  129.  
  130.         CASE AsEndPartBT
  131.  
  132.         CASE AsAnyPartBT
  133.  
  134.         CASE WorsListFounded
  135.  
  136.     END SELECT
  137.  
  138. SUB __UI_FocusOut (id AS LONG)
  139.     'This event occurs right before a control loses focus.
  140.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  141.     SELECT CASE id
  142.         CASE WhatSearchTB
  143.  
  144.         CASE AsStartPartBT
  145.  
  146.         CASE AsEndPartBT
  147.  
  148.         CASE AsAnyPartBT
  149.  
  150.         CASE WorsListFounded
  151.  
  152.     END SELECT
  153.  
  154. SUB __UI_MouseDown (id AS LONG)
  155.     SELECT CASE id
  156.         CASE WordSearcher
  157.  
  158.         CASE WhatSearchTB
  159.  
  160.         CASE AsStartPartBT
  161.  
  162.         CASE AsEndPartBT
  163.  
  164.         CASE AsAnyPartBT
  165.  
  166.         CASE WorsListFounded
  167.  
  168.     END SELECT
  169.  
  170. SUB __UI_MouseUp (id AS LONG)
  171.     SELECT CASE id
  172.         CASE WordSearcher
  173.  
  174.         CASE WhatSearchTB
  175.  
  176.         CASE AsStartPartBT
  177.  
  178.         CASE AsEndPartBT
  179.  
  180.         CASE AsAnyPartBT
  181.  
  182.         CASE WorsListFounded
  183.  
  184.     END SELECT
  185.  
  186. SUB __UI_KeyPress (id AS LONG)
  187.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  188.     'You can change it and even cancel it by making it = 0
  189.     SELECT CASE id
  190.         CASE WhatSearchTB
  191.  
  192.         CASE AsStartPartBT
  193.  
  194.         CASE AsEndPartBT
  195.  
  196.         CASE AsAnyPartBT
  197.  
  198.         CASE WorsListFounded
  199.  
  200.     END SELECT
  201.  
  202. SUB __UI_TextChanged (id AS LONG)
  203.     SELECT CASE id
  204.         CASE WhatSearchTB
  205.  
  206.     END SELECT
  207.  
  208. SUB __UI_ValueChanged (id AS LONG)
  209.     SELECT CASE id
  210.         CASE WorsListFounded
  211.  
  212.     END SELECT
  213.  
  214. SUB __UI_FormResized
  215.  
  216.  

and attached are the screenshot of crashing and the .frm file. While the .txt is avaiable on the link above showed.
Remember to have installed Inform into QB64 folder.
 


about the issue IMHO the cause may be a too fast FOR NEXT loop, but also a _DELAY .3 has no good results.

Thanks to read and for feedback
Programming isn't difficult, only it's  consuming time and coffee

Offline FellippeHeitor

  • QB64 Developer
  • Forum Resident
  • Posts: 2226
  • LET IT = BE
    • QB64.org
Re: [Inform]WordSearcher... but Listbox doesn't work well
« Reply #1 on: May 19, 2019, 11:14:20 AM »
A few things fixed in your code (no changes to the form, just the .bas):

  • wordcount was not a shared variable
  • wordlist was being REDIMmed but you were not specifying the correct data type (STRING) in SUB __UI_OnLoad
  • there was an END statement in SUB SearcheR, which I changed into an EXIT SUB. Using SYSTEM is OK, but you shouldn't use END in an InForm-based program (using _DELAY is a bad idea too).
Code: QB64: [Select]
  1. ': This program uses
  2. ': InForm - GUI library for QB64 - Beta version 8
  3. ': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
  4. ': https://github.com/FellippeHeitor/InForm
  5. '-----------------------------------------------------------
  6.  
  7. ': Controls' IDs: ------------------------------------------------------------------
  8. DIM SHARED WordSearcher AS LONG
  9. DIM SHARED WhatSearchTB AS LONG
  10. DIM SHARED AsStartPartBT AS LONG
  11. DIM SHARED AsEndPartBT AS LONG
  12. DIM SHARED AsAnyPartBT AS LONG
  13. DIM SHARED WorsListFounded AS LONG
  14. REDIM SHARED wordlist(1000000) AS STRING, wordcount AS LONG
  15. ': External modules: ---------------------------------------------------------------
  16. '$INCLUDE:'InForm\InForm.ui'
  17. '$INCLUDE:'InForm\xp.uitheme'
  18. '$INCLUDE:'wordsearcher.frm'
  19.  
  20. ': Event procedures: ---------------------------------------------------------------
  21. SUB __UI_BeforeInit
  22.  
  23.  
  24. SUB __UI_OnLoad
  25.     OPEN "Scrabble WordList 2006.txt" FOR BINARY AS #1
  26.     DO UNTIL EOF(1)
  27.         wordcount = wordcount + 1
  28.         LINE INPUT #1, wordlist(wordcount)
  29.     LOOP
  30.     REDIM _PRESERVE wordlist(wordcount) AS STRING
  31.     CLOSE
  32.  
  33. SUB __UI_BeforeUpdateDisplay
  34.     'This event occurs at approximately 30 frames per second.
  35.     'You can change the update frequency by calling SetFrameRate DesiredRate%
  36.  
  37.  
  38. SUB __UI_BeforeUnload
  39.     'If you set __UI_UnloadSignal = False here you can
  40.     'cancel the user's request to close.
  41.  
  42.  
  43. SUB SearcheR (Mode AS INTEGER)
  44.     m$ = _TRIM$(UCASE$(Text(WhatSearchTB)))
  45.     l = LEN(m$)
  46.     SELECT CASE Mode
  47.         CASE 1 ' STA
  48.             FOR i = 1 TO wordcount
  49.                 IF LEFT$(wordlist(i), l) = m$ THEN AddItem WorsListFounded, wordlist(i)
  50.             NEXT
  51.         CASE 2 '"END"
  52.             FOR i = 1 TO wordcount
  53.                 IF RIGHT$(wordlist(i), l) = m$ THEN AddItem WorsListFounded, wordlist(i)
  54.             NEXT
  55.         CASE 3 '"CON"
  56.             FOR i = 1 TO wordcount
  57.                 IF INSTR(wordlist(i), m$) THEN AddItem WorsListFounded, wordlist(i)
  58.             NEXT
  59.         CASE ELSE
  60.             EXIT SUB
  61.     END SELECT
  62.  
  63.  
  64. SUB __UI_Click (id AS LONG)
  65.     SELECT CASE id
  66.         CASE WordSearcher
  67.  
  68.         CASE WhatSearchTB
  69.  
  70.         CASE AsStartPartBT
  71.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  72.                 ResetList WorsListFounded
  73.                 SearcheR 1
  74.             END IF
  75.         CASE AsEndPartBT
  76.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  77.                 ResetList WorsListFounded
  78.                 SearcheR 2
  79.             END IF
  80.         CASE AsAnyPartBT
  81.             IF LEN(Text(WhatSearchTB)) > 0 THEN
  82.                 ResetList WorsListFounded
  83.                 SearcheR 3
  84.             END IF
  85.         CASE WorsListFounded
  86.  
  87.     END SELECT
  88.  
  89. SUB __UI_MouseEnter (id AS LONG)
  90.     SELECT CASE id
  91.         CASE WordSearcher
  92.  
  93.         CASE WhatSearchTB
  94.  
  95.         CASE AsStartPartBT
  96.  
  97.         CASE AsEndPartBT
  98.  
  99.         CASE AsAnyPartBT
  100.  
  101.         CASE WorsListFounded
  102.  
  103.     END SELECT
  104.  
  105. SUB __UI_MouseLeave (id AS LONG)
  106.     SELECT CASE id
  107.         CASE WordSearcher
  108.  
  109.         CASE WhatSearchTB
  110.  
  111.         CASE AsStartPartBT
  112.  
  113.         CASE AsEndPartBT
  114.  
  115.         CASE AsAnyPartBT
  116.  
  117.         CASE WorsListFounded
  118.  
  119.     END SELECT
  120.  
  121. SUB __UI_FocusIn (id AS LONG)
  122.     SELECT CASE id
  123.         CASE WhatSearchTB
  124.  
  125.         CASE AsStartPartBT
  126.  
  127.         CASE AsEndPartBT
  128.  
  129.         CASE AsAnyPartBT
  130.  
  131.         CASE WorsListFounded
  132.  
  133.     END SELECT
  134.  
  135. SUB __UI_FocusOut (id AS LONG)
  136.     'This event occurs right before a control loses focus.
  137.     'To prevent a control from losing focus, set __UI_KeepFocus = True below.
  138.     SELECT CASE id
  139.         CASE WhatSearchTB
  140.  
  141.         CASE AsStartPartBT
  142.  
  143.         CASE AsEndPartBT
  144.  
  145.         CASE AsAnyPartBT
  146.  
  147.         CASE WorsListFounded
  148.  
  149.     END SELECT
  150.  
  151. SUB __UI_MouseDown (id AS LONG)
  152.     SELECT CASE id
  153.         CASE WordSearcher
  154.  
  155.         CASE WhatSearchTB
  156.  
  157.         CASE AsStartPartBT
  158.  
  159.         CASE AsEndPartBT
  160.  
  161.         CASE AsAnyPartBT
  162.  
  163.         CASE WorsListFounded
  164.  
  165.     END SELECT
  166.  
  167. SUB __UI_MouseUp (id AS LONG)
  168.     SELECT CASE id
  169.         CASE WordSearcher
  170.  
  171.         CASE WhatSearchTB
  172.  
  173.         CASE AsStartPartBT
  174.  
  175.         CASE AsEndPartBT
  176.  
  177.         CASE AsAnyPartBT
  178.  
  179.         CASE WorsListFounded
  180.  
  181.     END SELECT
  182.  
  183. SUB __UI_KeyPress (id AS LONG)
  184.     'When this event is fired, __UI_KeyHit will contain the code of the key hit.
  185.     'You can change it and even cancel it by making it = 0
  186.     SELECT CASE id
  187.         CASE WhatSearchTB
  188.  
  189.         CASE AsStartPartBT
  190.  
  191.         CASE AsEndPartBT
  192.  
  193.         CASE AsAnyPartBT
  194.  
  195.         CASE WorsListFounded
  196.  
  197.     END SELECT
  198.  
  199. SUB __UI_TextChanged (id AS LONG)
  200.     SELECT CASE id
  201.         CASE WhatSearchTB
  202.  
  203.     END SELECT
  204.  
  205. SUB __UI_ValueChanged (id AS LONG)
  206.     SELECT CASE id
  207.         CASE WorsListFounded
  208.  
  209.     END SELECT
  210.  
  211. SUB __UI_FormResized
  212.  
  213.  
  214.  
« Last Edit: May 19, 2019, 11:16:05 AM by FellippeHeitor »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1415
Re: [Inform]WordSearcher... but Listbox doesn't work well
« Reply #2 on: May 19, 2019, 04:12:32 PM »
Thanks Fellippe for your fixed version and for your time!

I must admit my disappoint when I got this failure!
I have not been able to copy correctly the code of Steve and put it into Inform structure to have a windowed interface!

LOL Better to write than to copy.

Programming isn't difficult, only it's  consuming time and coffee