Guidance
指路人
g.yi.org
Guidance Forums / Rapid-Q Basic / Trying to dynamically populate QCOMBOBOX from text file

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Trying to dynamically populate QCOMBOBOX from text file
#4413
Posted by: 2004-06-11 00:29:40
Hello All,



I am trying to populate a QCOMBOBOX from a text file. I have created a sub with the following code

*********************************************************************

SUB populateDropDown
    DIM employeeData AS QFileStream
    IF employeeData.Open ("clients.txt", fmOpenRead) = False THEN
       MESSAGEDLG("Error opening file", mtError, mbOK, 0)
       END
    ELSE
    WHILE employeeData.position < employeeData.size
       chooseEmployeeDropdown.AddItems employeeData.readline
   WEND
       employeeData.Close
    END IF

END SUB

*********************************************************************



And am trying to call that SUB here


*********************************************************************

CREATE chooseEmployeeDropdown AS QCOMBOBOX
            Left = 7
            Top = 246
            Width = 153
            TabOrder = 1
            populateDropDown  'SUB CALL
           
END CREATE

*********************************************************************



When I try to do the above I keep gettting compiler error saying that populateDropDown is not part of member chooseEmployeeDropdown.


Am I totally off the right path with what I am trying to do?



Thanks
John
Message2. Re: Trying to dynamically populate QCOMBOBOX from text file
#4418
Posted by: erdemaal 2004-06-11 07:49:02
CREATE chooseEmployeeDropdown AS QCOMBOBOX
            Left = 7
            Top = 246
            Width = 153
            TabOrder = 1
            populateDropDown  'SUB CALL
           
END CREATE

Everything in a Create/End create code must been seen
as :  chooseEmployeeDropdown.populateDropDown

So you must do this :

CREATE chooseEmployeeDropdown AS QCOMBOBOX
            Left = 7
            Top = 246
            Width = 153
            TabOrder = 1
END CREATE
populateDropDown  'SUB CALL
            
Hope it's clear :) (It's not :)

Jacques
Message3. Re: Trying to dynamically populate QCOMBOBOX from text file
#4419
Posted by: 2004-06-11 08:05:39
DIM an array, making sure it is big enough to hold the items. Use a counter set to zero. Then read in the file, increase the counter by one and put the read in line in the array.

Then in the CREATE (of course I'd use DIM instead) use a loop (for x = 1 to the counter) to add the items from the array.

I regard ANY action needed to set up a form as not deserving a SUB, so after the required definitions (for the SetFocus API call and such) I always start with a bit that reads in needed data. I tend to DIM the form, then a QRichedit to buffer file data, then one by one read files into the rich edit and analyze them.

Only then do I DIM the other form elements (I hate the CREATE method as it doesn't cater for arrays of elements)

Of course I also always add an item index to the start of any file so that I do not need While .... Wend loops.

An example;

 DIM RiEd AS QRICHEDIT
 RiEd.plaintext = 1
 RiEd.visible = 0
 RiEd.PARENT = Form

 f$ = "filename.extension"
 RiEd.Clear
 RiEd.LoadFromFile(f$)
 a$ = RiEd.Text
 NumberOfItems = VAL(MID$(a$,9,8))
 DIM ItemName$(NumberOfItems)
 ItemName$(0)="--------"
 FOR x=1 TO NumberOfItems
  beg = x * 33 - 15
  ItemName$(x) = MID$(a$,beg,7)
 NEXT x
Message4. Re: Trying to dynamically populate QCOMBOBOX from text file
#4420
Posted by: 2004-06-11 08:09:59
Guess that Erdemaal - quite rightly - means to say that you do not have to fill the combo box at setup  :)  you can put the

chooseEmployeeDropdown.AddItems

outside the CREATE block.

Message5. Re: Trying to dynamically populate QCOMBOBOX from text file
#4427
Posted by: 2004-06-11 21:54:35
Thanks All


I will give that a try


Best
John
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sat 2024-4-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0