×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

*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.

Students Click Here

Jobs

Populate EDITBOX with contents of a Text File
3

Populate EDITBOX with contents of a Text File

Populate EDITBOX with contents of a Text File

(OP)
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.

RE: Populate EDITBOX with contents of a Text File

Youreditbox.controlsource = yourtable.yourfield

RE: Populate EDITBOX with contents of a Text File

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

RE: Populate EDITBOX with contents of a Text File

(OP)
Thank you Gentlemen for your help, much appreciated.

Regards,

David.

Recreational user of VFP.

RE: Populate EDITBOX with contents of a Text File

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 --> Form.Init

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
https://www.doschke.name

RE: Populate EDITBOX with contents of a Text File

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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