Smart questions
Smart answers
Smart people
Join Tek-Tips Forums
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

thegame8311 (TechnicalUser) (OP)
15 Jan 12 16:58
greetings

I can seem to populate my listbox. When I run my code nothing is showing in the listbox

here's what I have so far:

CODE

LPARAMETERS cItem

lp1.listbox1.RowSourceType = 3
lp1.listbox1.RowSource = "SELECT * FROM LivePlayers INTO CURSOR myCursor"

lp1.listbox1.value = myCursor.pid

I have values in my table, so what could I be missing?
danfreeman (Programmer)
15 Jan 12 17:18
When you change the contents of a listbox, you have to call the Listbox.Requery()

 
MikeLewis (Programmer)
16 Jan 12 3:18
When you use Rowsourcetype = 3, the cursor (MyCursor in this case) is dummy cursor. The actual cursor that's used to populate the listbox is created behind the scenes.

So lp1.listbox1.value = myCursor.pid doesn't have any effect.

Either change the above line to lp1.listbox.ListIndex= 1. Or, better, do this:

CODE

SELECT * FROM LivePlayers INTO CURSOR myCursor
lp1.listbox1.RowSourceType = 2
lp1.listbox1.RowSource = "MyCursor"
lp1.listbox1.Listindex = 1

Also, if you want to see all the fields from LivePlayers, then you need to set the ColumnCount accordingly.

In fact, you could also do this:

CODE

lp1.listbox1.RowSourceType = 2
lp1.listbox1.RowSource = "LivePlayers"
lp1.listbox1.Listindex = 1

Mike

 

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
16 Jan 12 17:47
cool, well now that does not set any of the properties, but why, does it need to go into an event or somewhere else?
OlafDoschke (Programmer)
16 Jan 12 18:00
Mike's code can replace your code at the position it is right now.

The ideal place to put initialisation code is the Init() event of course. Data retreival can also go into the OpenTables() method of the forms dataenvironment or into the Load() of the form, previous to any init of any control. However you like it.

Bye, Olaf.
MikeLewis (Programmer)
17 Jan 12 2:58
My own choice would be to put the code in the Init of the listbox, as that would make it more self-contained. But it could also go in the Init of the form.

Mike
 

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

OlafDoschke (Programmer)
17 Jan 12 3:15
A little bit beyond the scope of this question:

Yes Mike, that's good from the OOP encapsulation perspective, of course.

But I rather see it from the perspective of application layers.  And while it's good an object to be self contained, responsible for it's own state including data binding, it makes this control object work throughout many application layers, as it's part of the GUI and will then drill down to the database, which is a no go with seperating the concerns of presentation and persisting data to seperate modules.

Actually you can combine both the OOP thought and the thought on decoupling aspects in the N tier application layer model, by letting a control not directly access data in it's init, but still let it call an object representing the next layer of the app to delegate fetching the data for it.

That way the control would take care of missing data on it's own anyway and the data access layer would only query data the control really needs to display.

I still prefer the push of data into the GUI and not an intelligent GUI requesting what it wants to display, because having the presentation centrelised gives more overview to the programmer for interdependencies and the business layer can more easy be adopted to a whole new form in one central databinding method, perhaps.

Bye, Olaf.
thegame8311 (TechnicalUser) (OP)
17 Jan 12 12:29
ok, that worked, but now I am adding values from one table to another, but when I try to use the following the listbox does not refresh or requery

CODE

thisform.list1.refresh
thisform.list1.requery

I have those in the add button so after it adds it to the table it should show me the updated list, but it is not
MikeLewis (Programmer)
17 Jan 12 12:41
Just doing a requery isn't enough. You need to regenerate your cursor.

Try running the same code (the code that does the SELECT, etc.) from the button that's used to add the data to the table.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
17 Jan 12 12:51
would it help to put that same select code into the requery function?
OlafDoschke (Programmer)
17 Jan 12 13:08
Mike initially gave you 2 alternatives. Alternative 2 was just setting lp1.listbox1.RowSource = "LivePlayers" instead of a query into a cursor named "MyCursor".

If you do that the listbox requery() will show the new records.

Bye, Olaf.
MikeLewis (Programmer)
17 Jan 12 14:37
Yes, Olaf is correct. TheGame, if you could post the actual code you are using, it might be easier to advise you.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
17 Jan 12 18:07
it's ok I figured that part out.

The part that is getting me now is 'field' phrase is not found

Here is the code:

CODE

thisform.list1.RowSourceType = 2
thisform.list1.RowSource = "TestTeam"
thisform.list1.Listindex = 2
thisform.list1.ColumnCount = 3
thisform.list1.ColumnWidths = "100,150,150"

it's pointing at my Rowsource line. the table exists, so I'm confused why I keep getting this error
OlafDoschke (Programmer)
18 Jan 12 2:35
Sepcifying a table not yet opened is not possible, unlike SQL-SELECT From opening a table a rowsource, even in rowsourcetype 2 can not only be a table name, but an expression with table and field names and thus vfp just errors this way instead of opening TestTeam.dbf

Bye, Olaf.
MikeLewis (Programmer)
18 Jan 12 3:18
Yes, I agree with Olaf. Make sure that TestTeam is open before you run that code. If that doesn't solve the problem, come back, and we can look at it in more detail.

Mike
 

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

OlafDoschke (Programmer)
18 Jan 12 3:23
Just to clarify: With "can not only" I meant it's also possible the rowsource is an expression in general, it does not need to be a table or alias name, even if you specify rowsourcetype alias. So vfp does not know it should open that table, unlike with SQL-Select, where it actually does open not yet opened tables.

Bye, Olaf.
thegame8311 (TechnicalUser) (OP)
18 Jan 12 12:47
So if I insert a

CODE

Use "table"
before the rowsource code then it should work
thegame8311 (TechnicalUser) (OP)
18 Jan 12 13:02
Also I was wondering if you can do this:

CODE

thisform.list2.RowSourceType = 2
thisform.list2.RowSource = lnTeam
thisform.list2.Listindex = 2
thisform.list2.ColumnCount = 3
thisform.list2.ColumnWidths = "100,150,150"

where lnTeam is a variable
MikeLewis (Programmer)
18 Jan 12 14:23

Quote:

Use "table"

No. Remove the double quotes. For example:

CODE

USE TestTeam

But you need to do that once only, before you call the code that sets the RowSource. For example, do it in the Load event of the form. (And you should only do it if the table is not already open.)

This is a better way:

CODE

IF NOT USED("TestTeam")
  USE TestTeam IN 0
ENDIF

Quote:


thisform.list2.RowSource = lnTeam

What's lnTeam? Is it a variable that holds the name of the table? If so, that's fine.

The stuff with column count and column widths look OK too.

Mike
 

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
18 Jan 12 18:31
Yes lnTeam holds the table name
thegame8311 (TechnicalUser) (OP)
18 Jan 12 18:42
Now this code is giving me fits

on the fwrite line

CODE

lnFileHandle3 = FCREATE('C:\Stats3.txt') && creating final file

PUBLIC newline3

*lnCount3 = OCCURS(',', z)*

LOCAL lnFileHandle7 && numeric file handle

lnFileHandle7 = FOPEN( "C:\Stats2.txt") && open previous file for reading

IF lnFileHandle7 = -1

   && error, could not open the file

   && do something to handle the error

   RETURN

ENDIF

LOCAL lcLine && define a variable to hold each line

DO WHILE NOT FEOF( lnFileHandle7) && loop through the file

   lcLine = FGETS( lnFileHandle7) && store each line in lcLine
   
   lp1.text3.value = GETWORDCOUNT(lcLine)
   
   FWRITE(lnFileHandle3, GETWORDCOUNT(lcLine))
   
ENDDO

FCLOSE(lnFileHandle3)
FCLOSE(lnFileHandle7)
OlafDoschke (Programmer)
19 Jan 12 2:19
You can only FWRITE() strings into a file, GETWORDCOUNT() returns a number.

Bye, Olaf.
MikeLewis (Programmer)
19 Jan 12 3:27
TheGame,

What on earth is this FWRITE() code all about? We were talking about listboxes. Where does this new code you posted come into it?

Have you still got problems with populating your listbox?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
19 Jan 12 9:50
Sorry I meant to start that on a new post, I will do that  
MikeLewis (Programmer)
19 Jan 12 10:47
OK, I saw you new post about FWRITE().

So, what's the story with the listbox? Do you still have the problem, or have you resolved it?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 

thegame8311 (TechnicalUser) (OP)
23 Jan 12 21:23
I resolved it, thanks for the ideas, you guys are awesome

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close