Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detect state of memofield and textbox
Message
From
13/11/2012 03:18:39
 
 
To
13/11/2012 02:17:58
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01557010
Message ID:
01557013
Views:
60
This message has been marked as a message which has helped to the initial question of the thread.
Likes (1)
>having trouble determing state of editbox when a memofield is blank
>
>
>oFrm.Edit1.Value = filetostr('m.txt')  && original memofield is copied to m.txt 
>
>pass through an editbox to add to the memofield and now i am trying to compare the original memofield with the editbox info
>
>if not empty oFrm.Edit1.Value  &&& is editbox empty 
>wait window 'empty this works'
>endif
>
>if oFrm.Edit1.Value # filetostr('m.txt')     &&&& 'original memo field empty and editbox has data 
>wait window 'this does not work SITUATION IS NOT DETECTED' 
>endif
>
>if filetostr('m.txt') = " "   original memofield empty
>wait window 'this does not work SITUATION IS NOT DETECTED'
>endif
>
>any help with correct effective code for these two situations much appreciated.

What a mess. Almost all of your comments are lies and don't match the actual code.

1. Unless you have a specific requirement to persist the value of the memo field to disk, you don't need to use FILETOSTR() / STRTOFILE(). If the source of the original value of the editbox is a memo field of a table, you can just compare the new/changed value of the editbox to the memo field.
oFrm.Edit1.Value = SomeTable.SomeMemoField
* Editbox contents may get changed here
IF oFrm.Edit1.Value == SomeTable.SomeMemoField
etc.

* Note the use of the double equal signs == which means the comparison must be exact. It's a good idea to get in the habit of using it for almost all string comparisons.

* If you've bound the editbox to the table memo field so the latter gets automatically updated,
* you can save the initial value of the memo field to a memory variable:
lcOldMemoFieldValue = SomeTable.SomeMemoField
oFrm.Edit1.Value = SomeTable.SomeMemoField

IF oFrm.Edit1.Value == lcOldMemoFieldValue
etc.
2. EMPTY( ) is a function e.g.
IF EMPTY( oFrm.Edit1.Value )
etc.
3. If you want "original memo field empty and editbox has data" then you either have to include both conditions in one line, or nest them:
* One line:
IF EMPTY( SomeTable.SomeMemoField ) AND NOT EMPTY( oFrm.Edit1.Value )
etc.

* Nested IFs:
IF EMPTY( SomeTable.SomeMemoField )  && original value empty
  IF NOT EMPTY( oFrm.Edit1.Value )  && current editbox value not empty
    * code here meets both conditions

  ENDIF

ENDIF
4. In character comparisons the empty string "" is not the same as one space " ".
* Your code uses a single = (inexact string comparison) against a single space character
if filetostr('m.txt') = " "

* You could use exact string comparison to the empty string:
IF FILETOSTR( 'm.txt' ) == ""

* but better is a nested function call:
IF EMPTY( FILETOSTR( 'm.txt' ) )
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform