Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Listbox and Textbox - Adding information from file.

  1. #1

    Listbox and Textbox - Adding information from file.

    Hi

    I am using ThinBasic version 1.13.0, and testing the listbox example (...\SampleScript\UI\Listbox\Listbox.tBbasic). Trying to populate the listbox from a text file but I cannot get the items to appear as a single line. That is the text file is:
    one
    two
    three

    Then the list box is: onetwothree; for many lines.

    I tried using the C++ escape code '\n' with similar results. How do I get the program to read a single word to populate the listbox.

    Also, if I am using a textbox how do I get the program to read several paragraphs into the Textbox. Thank You...

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,813
    Rep Power
    10
    Ciao,

    I think there is a problem in passing array of elements from file.
    I'm checking why and will post here a new thinBasic_UI.dll to test

    Regarding paragraph in standard textbox you need to add some textbox styles like %ES_MULTILINE and %ES_WANTRETURN

    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Eros - Thank You...


    Quote Originally Posted by ErosOlmi View Post
    Ciao,

    I think there is a problem in passing array of elements from file.
    I'm checking why and will post here a new thinBasic_UI.dll to test

    Regarding paragraph in standard textbox you need to add some textbox styles like %ES_MULTILINE and %ES_WANTRETURN

    Eros

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,813
    Rep Power
    10
    Attached a new thinBasic UI module.
    Please copy thinBasic_UI.dll into \thinbasic\lib\ path and replace your current one.

    What I've done was to recode the way thinBasic load string array data into a ListBox when using "Control Add Listbox ..." or "Listbox Add ..." or "Control Add Combobox ..." or "Combobox Add ..."

    Not sure I've solved 100% what you was trying to do.
    If not, please post a little example showing how to replicate the problem.

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Thank You, I will try it out this weekend and let you know if it worked. Take care...

    Quote Originally Posted by ErosOlmi View Post
    Attached a new thinBasic UI module.
    Please copy thinBasic_UI.dll into \thinbasic\lib\ path and replace your current one.

    What I've done was to recode the way thinBasic load string array data into a ListBox when using "Control Add Listbox ..." or "Listbox Add ..." or "Control Add Combobox ..." or "Combobox Add ..."

    Not sure I've solved 100% what you was trying to do.
    If not, please post a little example showing how to replicate the problem.

    Ciao
    Eros

  6. #6
    Quote Originally Posted by KF4GHG View Post
    Thank You, I will try it out this weekend and let you know if it worked. Take care...
    Hi - Very Very strange. I replaced the ThinBasic_UI.dll file and the TRACE does no work. I reinstalled Thinbasic without the updated DLL and Trace still does not work. Still having issues with the list box. The program with the new DLL continues to read the input as a single line (Please see attached). Below is the code I left the three vlist lines to show what I have tried. Any help would be appreciated. Thank You...

    uses "UI"
    uses "file"
    USES "CONSOLE"
    Uses "Trace"

    DIM tmpStr AS STRING
    dim tmpLong as long

    dim ID_List01 as long
    dim MaxItems as long
    dim CurItem as long
    dim count as long

    dim MaxElements as long = 100
    dim vList(MaxElements) AS STRING

    ' *******
    dim InFileToLoad as string
    dim InFileChannel as long
    Dim i As Integer
    Dim iTm (15) As Integer
    dim sBuffer as string

    InFileToLoad = app_sourcepath & "Out5.txt"
    ' ******

    Begin ControlID
    %Text01
    %List01
    %Butt01
    End ControlID

    function TBMain()
    DIM hDlg AS LONG

    '---Create a new dialog
    DIALOG NEW 0, "ListBox example", -1, -1, 275, 120, _
    %WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU, _
    0 TO hDlg


    randomize

    '*******
    InFileChannel = file_open(InFileToLoad , "INPUT" )

    i = 1
    while not file_eof(InFileChannel)
    sBuffer = file_lineinput(InFileChannel)
    print sBuffer
    iTm(15) = sBuffer
    i=i+1
    wend

    i = 1
    FOR count = 1 TO MaxElements
    ' Works Fine - give Item and number
    ' vList(Count) = "Item " & FORMAT$(RND(1, 100000), "000000")

    ' Does not work - gives only "ten"
    ' vList(Count) = sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")

    ' Does not work - gives "Subscript out of range in array or matrix
    'Dimension 1 should be between 1 and 15. Current value: 16"
    vList(Count) = iTm (i) 'sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")

    i = i+1
    NEXT
    ' ******

    '---Show dialog in MODAL state
    DIALOG SHOW MODAL hDlg, call dlgCallback
    end function

    callback function dlgCallback() as long

    '---Now test the message
    SELECT CASE cbMsg

    case %WM_INITDIALOG '---Message fired at the very beginning when dialog is initialized
    '---This can be the right place to initialize dialog or create controls
    CONTROL ADD listbox , cbHndl, %List01 , vList() , 5, 20, 200, 100, 0, 0
    CONTROL ADD textbox , cbHndl, %Text01 , "" , 5, 5, 200, 12
    control add button , cbHndl, %Butt01 , "Set" , 210, 5, 60, 12

    CASE %WM_COMMAND

    '---Test which control has been clicked
    SELECT CASE cbCtl

    '---Something has happened with %List01
    case %List01

    select case cbCtlMsg
    case %LBN_SELCHANGE
    LISTBOX GET TEXT cbHndl, %List01 TO tmpStr
    control set text cbHndl, %Text01, tmpStr

    case %LBN_DBLCLK
    LISTBOX GET TEXT cbHndl, %List01 TO tmpStr
    control append text cbHndl, %Text01, "(DblClick " & tmpStr & ")"

    end select

    case %Butt01
    if cbCtlMsg = %BN_CLICKED then
    '---Get the text from a textbox and place into a string
    control get text cbHndl, %Text01 to tmpStr

    '---Get the window unique ID of the control
    CONTROL HANDLE cbHndl, %List01 TO ID_List01

    '---Get the number of items present into listbox
    MaxItems = sendmessage(ID_List01, %LB_GETCOUNT, 0, 0)

    '---Get current selected item (remember it start at zero position)
    listbox get selected cbHndl, %List01 to CurItem

    '---Now delete selected item ...
    listbox delete cbHndl, %List01, CurItem

    '---...and insert new text in same position
    sendmessage(ID_List01, %LB_INSERTSTRING, CurItem - 1, strptr(tmpStr))

    listbox select cbHndl, %List01, CurItem
    end if
    end select
    END SELECT
    end function


    ThinBasic.jpg

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,146
    Rep Power
    735
    Dear KF4GHG,

    I would like to attempt to offer an insight into the problems you experience in your code.

    Observation #1
    dim MaxElements as long = 100     ' MaxElements is set to 100
    dim vList(MaxElements) AS STRING  ' vList has 100 elements
    
    ...
    
    Dim iTm (15) As Integer           ' iTm has however just 15 elements
    
    Observation #2
    InFileChannel = file_open(InFileToLoad , "INPUT" )
    
    i = 1
    while not file_eof(InFileChannel)
      sBuffer = file_lineinput(InFileChannel)
      print sBuffer
      iTm(15) = sBuffer
      i=i+1
    wend
    

    We can see in this part that sBuffer variable will contain only the last read value from the file after leaving while cycle


    Problematic part:
    i = 1
    FOR count = 1 TO MaxElements
      ' Works Fine - give Item and number
      ' vList(Count) = "Item " & FORMAT$(RND(1, 100000), "000000")
    
      ' Does not work - gives only "ten"
      ' vList(Count) = sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
    
      ' Does not work - gives "Subscript out of range in array or matrix
      'Dimension 1 should be between 1 and 15. Current value: 16"
      vList(Count) = iTm (i) 'sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
    
       i = i+1
    NEXT
    
    The issue on line 7 is not really an issue - it gives only single value because of the fact highlighted in the Observation #2

    The issue on line 11 occurs for the following reason:
    - the FOR cycle goes from 1 to MaxElements, that is 1 to 100
    - the i variable will also grow from 1 to 100, thanks to the way you initialize it to 1 before the cycle and increase by one at the end of the cycle
    - the iTm array is dimensioned just for 15 elements, as seen in Observation #1


    I hope this helps getting you closer to your goal.



    Petr
    Last edited by Petr Schreiber; 30-06-2024 at 11:37.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    Hi Petr

    Thank you for your suggestions. I made the suggested changes and modified the sBuffer to be a dimensional variable (sBuffer (i) = file_lineinput(InFileChannel)) but still am having issues. The vlist (vList(Count) = sBuffer(i))does not seem to work because it does not populate the listbox. sBuffer(i) does display on the consul but the multiline document comes out as a single line (i.e., onetwothreefourfivesixseveneightnineten...). Again thank You...


    Quote Originally Posted by Petr Schreiber View Post
    Dear KF4GHG,

    I would like to attempt to offer an insight into the problems you experience in your code.

    Observation #1
    dim MaxElements as long = 100     ' MaxElements is set to 100
    dim vList(MaxElements) AS STRING  ' vList has 100 elements
    
    ...
    
    Dim iTm (15) As Integer           ' iTm has however just 15 elements
    
    Observation #2
    InFileChannel = file_open(InFileToLoad , "INPUT" )
    
    i = 1
    while not file_eof(InFileChannel)
      sBuffer = file_lineinput(InFileChannel)
      print sBuffer
      iTm(15) = sBuffer
      i=i+1
    wend
    

    We can see in this part that sBuffer variable will contain only the last read value from the file after leaving while cycle


    Problematic part:
    i = 1
    FOR count = 1 TO MaxElements
      ' Works Fine - give Item and number
      ' vList(Count) = "Item " & FORMAT$(RND(1, 100000), "000000")
    
      ' Does not work - gives only "ten"
      ' vList(Count) = sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
    
      ' Does not work - gives "Subscript out of range in array or matrix
      'Dimension 1 should be between 1 and 15. Current value: 16"
      vList(Count) = iTm (i) 'sBuffer ' "Ronnie Item " & FORMAT$(RND(1, 100000), "000000")
    
       i = i+1
    NEXT
    
    The issue on line 7 is not really an issue - it gives only single value because of the fact highlighted in the Observation #2

    The issue on line 11 occurs for the following reason:
    - the FOR cycle goes from 1 to MaxElements, that is 1 to 100
    - the i variable will also grow from 1 to 100, thanks to the way you initialize it to 1 before the cycle and increase by one at the end of the cycle
    - the iTm array is dimensioned just for 15 elements, as seen in Observation #1


    I hope this helps getting you closer to your goal.



    Petr

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,146
    Rep Power
    735
    Thanks a lot for the comment.

    If I understand correctly, the input file contains words on each line - right?

    Then iTm array cannot be of type Integer to consume the data from the file, but of type String.

    Once you do this change, the data will be added to the listbox. But there is a catch - a lot of empty items in listbox, and one, two, three... at the very end.

    This is because you make the arrays huge by default, instead of modelling their size based on file content size.

    ThinBasic can make this whole part:
    InFileChannel = file_open(InFileToLoad , "INPUT" )
    
    
    i = 1
    while not file_eof(InFileChannel)
      sBuffer = file_lineinput(InFileChannel)
      printl sBuffer
      iTm(i) = sBuffer
      i=i+1
    wend
    
    ...much simpler for you. Consider this two liner instead:
    String iTm()  ' Notice you don't have to specify size ahead!
    PARSE(FILE InFileToLoad, iTm, $CRLF)  ' Loads each line in file to appropriate iTm array item
    
    ...you can then anytime get the number of items in array by:
    CountOf(iTm)
    
    So if you want vList to have the same number of items, you can do:
    DIM vList(CountOf(iTm)) AS STRING
    
    Or if you want to iterate over all items in the array:
    FOR i = 1 to CountOf(iTm)
    NEXT
    

    Hope it helps,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10
    Petr - Thank You!!!

Page 1 of 2 12 LastLast

Similar Threads

  1. HELP FILE : Unicode information swapped
    By Michael Clease in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 09-03-2011, 12:19
  2. Listbox and Textbox
    By sandyrepope in forum UI (User Interface)
    Replies: 2
    Last Post: 30-05-2007, 00:50
  3. Outdated thinBASIC help file information
    By Petr Schreiber in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 05-09-2005, 17:40

Members who have read this thread: 9

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •