Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate EDITBOX with contents of a Text File 3

Status
Not open for further replies.

David Higgs

Programmer
May 6, 2012
390
0
16
GB
I have a Text File which contains a Single Alpha Numeric Word on Each Line. I'd like to place the contents of the text file into an EDITBOX so that the user can make a selection. The Text File will occasionally be edited.

I can retrieve the Data by using one of the following options (although I am open to other suggestions).

Code:
* Option 1

CREATE CURSOR Logmenu ;
	( Log_Select varchar(15) )

LogSource = "Log_Selection.txt"	
Append From (LogSource) type sdf

* Option 2

LOCAL LogSelect AS String
	m.LogSelect = FILETOSTR("Log_Selection.txt")

However I don't seem to be able get my head around how to populate the EDITBOX with the Data.

Any help would be most appreciated.

Regards,

David.

Recreational user of VFP.
 
It could be easy as this:

Code:
Thisform.MyEditbox.Value = FILETOSTR("Log_Selection.txt")

If the user edits the data and you need to write it back to your text file, just do the reverse:

Code:
STRTOFILE(Thisform.MyEditbox.Value, "Log_Selection.txt")

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thank you Gentlemen for your help, much appreciated.

Regards,

David.

Recreational user of VFP.
 
To pick one line, you should use a grid or a listbox, not an editbox. And then option 1, reading the file as sdf (or csv) into a dbf (cursor) is fine for that.

An editbox does allows selection oif any amount of text, muiltiple lines, but also partial lines, so if you want to know a specific item = line number picked the editbox is the wrong control for that.
Grids are a bit complicated, but for a single column grid this could be as simple as that:

Code:
CREATE CURSOR Logmenu ;
	( Log_Select varchar(15) )

LogSource = "Log_Selection.txt"	
Append From (LogSource) type sdf
Go Top

thisform.addobject("grid1","grid")
thisform.grid1.collumncount = 1
thisform.grid1.width = 250
thisform.grid1.recordsource = "Logmenu"
thisform.grid1.column1.controlsource = "Log_Select"
thisform.grid1.column1.width = 250
thisform.grid1.visible = .t.

Or add the grid at design time.

Bye, Olaf.

PS: I forgot to tell an important detail: The row a user picks will be the current record of the cursor, so the choice made is Logmenu.log_select. It'll perhaps start at the bottom row after the append, and the grid displays nothing or only that last row. So you better GO TOP IN Logmenu.

Olaf Doschke Software Engineering
 
Olaf, I realised as soon as I had populated the EDITBOX that I probably wouldn't be able to achieve what I had set out to do.

I ran your code and also populated a LISTBOX on the same form for comparison. The LISTBOX meets my requirements, however, I will go with the GRID option as I think it will be more flexible as I continue to develop and improve the application.

Thank you very much for your help, much appreciated.

Regards,

David.

Recreational user of VFP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top