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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memo field 3

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

First time, I am going to use memo field.
Please let me know the following:

1. How can I define memo field in cursor define ( create cursor ..
2. How can I display on form. ( Like textbox or edit box.)
3. How can I save it in cursor/table.

Thanks

Saif
 
1 With the data type Memo or short M, so [tt]memofieldname Memo[/tt] or [tt]memofieldname M[/tt].
The help tells you that.
2. A memo can be multiline, so an Editbox is used to display it. In a textbox it appears as in a browse window as "memo" when empty and as "Memo" with a big M, if text is in it, but you don't see the value. If you double click you get a popup memo edit window (ike an editbox as its own window) just like in a browse window.
In an Editbox you see the value. Take notes about how the editbox behaves with TAB (see the help file again).
3. It saves just normal, there's nothing special about the data type, regarding saving the only special case where it's quite hard to get a value back out is the General (G) field type. Memo is not at all complicated like that, just because it also goes into the fpt file of a table. Memos are just text fields, just without a specific length like char fields, and with a much higher upper bound of however much space is left in the fpt file, that's all to it.

You really only start using Memos now? Why, what held you frrom it? It's all documented. The only, really the only problematic field type VFP has is General fields.

The only small advantage of DBFs without memos (and then also without General fields, and Blobs) is, that they don't have an fpt file and more backwards compatible dbf formats are available so you can share such data without fpt file with more legacy applications, but how many are there, still? In old dBase versions, for example?

And Memos work just like any other field type with INSERT-SQL, UPDATE-SQL or REPLACE, i.e. REPLACE memofield With "string" does not differ from a normal char field.

Chriss
 
Saif,

I think Chris has told you most of what you need to know about memo fields. But just to add a couple of points:

Here is an example of a command that creates a cursor with a memo field:

[tt]CREATE CURSOR MyCursor (Cust_ID C(10), CustNotes[highlight #FCE94F] M[/highlight])[/tt]

Here the CustNotes field is the memo field, as indicated by the letter M. (You don't specify the length of the field, which in any case variable.)

To display the memo on a form, use an EditBox. Set its ControlSource to the name of the memo field. It works just like the ControlSource of other controls. If the user edits the contents, the text will be saved back to the table, either immediately or when you do a TABLEUPDATE(), depending on whether you have buffering in force.

You can in theory also use a textbox for a memo field, but as that is always only one line high, you will only see the first small part of the text.

One other useful pair of commands: APPEND MEMO copies a text file into a memo field; and COPY MEMO does the reverse.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi,

Everything is ok, it is saving in memo field, but I want to print the contents of memo field in invoice.

It is not printing and showing blank.

Thanks

Saif
 
Saif,

Show us the report, what field have you added? What is the content of the memo field like?

A problem might be that the content of the memo field can be almost anything. So you may need a field with variable size in your report in order to show all content.

Regards, Gerrirt
 
How are you trying to print the memo field? In a report? If so, you should be able to do that by using an ordinary report field, but you will need to tick the "Stretch with overflow" box (in the report properties).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks for reply!

Please check these images.
MemoError_n1nxyj.png
memoerror1_cyjyb9.png
memoerro2_qoutln.png


Descr is a memo field.

Saif
 
What you are seeing is normal.

In the grid, you don't see the contents of the memo field - just the word "memo". You need to double-click on it to open a window where you can see (and edit) the actual text.

In the report, you have to set "Stretch with overflow" to see the full contents - otherwise it will just show you the first line, which might be empty.

Also, it looks like the entire memo fields are completely empty in this case, which would also explain the behaviour you are seeing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
A couple of other points:

I said, " .. it looks like the entire memo fields are completely empty in this case." That's because the word "memo" in the grid starts with a lower case m. If the memo actually had some text in it, it would show as "Memo"(capital M) rather than "memo", as per this example:.

grid_kz9y5f.jpg


Secondly, if you want to actually see some text in the grid, you can create a new character field to contain the first bit of the memo text, like this:

Code:
SELECT *, LEFT(descr, 64) AS ShortDescr FROM MyCursor ;
  INTO CURSOR MyCursor

then use ShortDescr as the control source of the memo field. If want the user to see more of the text (and to edit it), place an edit box on the form, and make Descr its ControlSource.

You could do the same in the report. But setting "Stretch with overflow" will also solve the problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes, all is normal, you've been warned in a textbox (also in a grid column with a textbox) you see the word "memo" for empty memo fields and "Memo" for memos with text. Only the Editbox displays the memo content directly.

And a report control, too, as Mike said, just also check "stretch with overflow" or you only see line 1 of the text. And in case the memo is empty and displays "memo" the report is blank for that memo.
So a memo showing "memo" in a textbox or grid cell is empty and shows blank in a report.

Chriss
 
Hi Saif,

Below a sketch of code how to display MEMO fields values in a grid and on a form triggered from a list box

Code:
PUBLIC go_Form

go_Form = CREATEOBJECT("frmForm")
go_Form.Visible = .T.
go_Form.Show

READ Events

CLOSE ALL 
CLEAR ALL
RETURN 

*********

DEFINE CLASS frmForm As Form
	Width = 960
	MinWidth = 960
	MaxWidth = 960
	Height = 450
	MinHeight = 450
	AutoCenter = .T.
	Caption = "Grids - Editbox versus MemoField"
	ShowTips = .T.
	Themes = .F.

*********

*!*	ADD objects with their procedures

	ADD OBJECT lblComment as Label WITH ;
		Left = 480 + 12, Top = 24, Height = 36, Width = 480 - 24 - 120, AutoSize = .F., ;
				Caption = "Change text in the editbox and click on the corresponding" + CHR(13) + ;
				"record to see the adopted changes"
		
	ADD OBJECT edtComment as EditBox WITH ;
		Left = 960 - 12 - 120, Top = 24, Width = 120, Height = 84, ControlSource = "csrBanks.mComment"
		
		PROCEDURE edtComment.LostFocus()
			Replace csrBanks.mComment WITH ALLTRIM(This.Value)

		ENDPROC 
		
	ADD OBJECT lstBanks AS ListBox WITH ;
		Left = 480 + 12, ;
		Top = 126, ;
		Width = 480 - 24, ;
		Height = 450 - 42 - 150, ;
		ItemBackColor = RGB(0, 240, 240), ;
		RowSourceType = 6, ;
		RowSource = "csrBanks.cString, mComment", ;
		ColumnCount = 2, ;
		ColumnWidths = "330, 48", ;
		Anchor = 15
		
		PROCEDURE lstBanks.Click()
			ThisForm.edtComment.Value = csrBanks.mComment
			
		ENDPROC 


	ADD OBJECT grdEBanks as grdBanks

		PROCEDURE grdEBanks.Init()
			WITH This
				.Column1.Header1.Caption = "Name of Bank"
				.Column1.Width = 294
				.Column1.ReadOnly = .T.

		    	WITH .Column2
		    		.Header1.Caption = "Comments"
		    		.NewObject("edtComments","EditBox")
					.edtComments.BackColor = RGB(0, 240, 240)
					.edtComments.Visible = .T.
					.CurrentControl = "edtComments" 
					.Width = 120
					.Sparse = .F.
				ENDWITH 
			ENDWITH
		ENDPROC 
		
	ADD OBJECT grdMBanks as grdBanks WITH ;
		Top = 204, ;
		Anchor = 30, ;
		AllowRowSizing = .F., ;
		ToolTipText = "Hoover over Memo to read its content"
		
		PROCEDURE grdMBanks.Init()
			WITH This
				.Column1.Header1.Caption = "Name of Bank"
				.Column1.Width = 294
				.Column1.ReadOnly = .T.

		    	WITH .Column2
		    		.Header1.Caption = "Comments"
		    		.DynamicFontItalic = "IIF(EMPTY(mComment), .F., .T.)"
		    		.DynamicFontBold = "IIF(EMPTY(mComment), .F., .T.)"
					.Width = 120
				ENDWITH 
			ENDWITH
		ENDPROC 
		
	ADD OBJECT cmdExit As CommandButton WITH ;
    	Width = 60, Height = 30, Left = 960 - 12 - 60, Top = 450 - 12 - 30, Caption = "Exit", Anchor = 12
    	
		PROCEDURE cmdExit.Click()
			ThisForm.Release
			CLEAR Events
		
		ENDPROC
			
*!*	ADD code to form's methods

	PROCEDURE Init()
		DODEFAULT() 
		This.DoBinds()
		
	ENDPROC
	
	PROCEDURE DoBinds()
		LOCAL loColumn, loObject

		FOR EACH loColumn IN This.grdEBanks.Columns
			FOR EACH loObject IN loColumn.Objects
				IF loObject.Baseclass == "Header"
					UNBINDEVENTS(loObject)
					BINDEVENT(loObject, "Click", This, "HeaderClick")

				ENDIF
			NEXT 
		NEXT
		
	ENDPROC

	PROCEDURE HeaderClick()
		LOCAL ARRAY laEvents[1]
		
*!*			AEVENTS(laEvents, 0)

*!*			= MESSAGEBOX("Clicked: " + SYS(1272, laEvents[1]), 64, "Clicked Object", 1500)
			
*!*			loObject = laEvents[1]

		WITH This.grdEBanks
			.RowHeight = 24
		ENDWITH 

	ENDPROC	

	PROCEDURE Destroy()
		ThisForm.cmdExit.Click()
		
	ENDPROC
    
	PROCEDURE Load()
		LOCAL lcText as Character
		
		lcText = "This is a " + CHR(13) + "three line " + CHR(13) + "long text"
		
		CREATE CURSOR csrBanks (cString C(60), mComment M)
		
		INSERT INTO csrBanks VALUES ("Crédit Suisse", lcText)
		INSERT INTO csrBanks VALUES ("Deutsche Bank", "")
		INSERT INTO csrBanks VALUES ("Crédit Lyonnais", "de gustibus et coloribus non est disputandum")
		
		LOCATE 
					
	ENDPROC
ENDDEFINE

**********

DEFINE CLASS grdBanks as Grid
		Left = 12
		Top = 12
		Width = 480 - 24
		Height = 180
		Anchor = 75
		GridLines = 2
		HeaderHeight = 21
		AllowHeaderSizing = .F.
		RowHeight = 18
		AllowRowSizing = .T.
		BackColor = RGB(0, 240, 240)
		ColumnCount = -1
		RecordSource = "csrBanks"
		ToolTipText = "Stretch RowHeight as desired - Click ColumnHeader to reset"
ENDDEFINE 

**********

hth

MarK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top