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

question on INLIST with MEMO field - Foxpro 9.0 1

Status
Not open for further replies.

kimsue

Programmer
Mar 5, 2002
52
US
The following method successfully eliminated MEMO fields from the SEARCH LIST in Visual Foxpro 7.0. In Visual 9.0, I get the error "Operator/Operand Type Mismatch" on the line beginning with.... IF INLIST..... (line 7)
when a memo field is in the file. Anybody have any idea WHY? Thanks.


#DEFINE NUM_AFIELDS 16
LOCAL i
PUBLIC aWizFList
DIMENSION aWizFList[1]
=AFIELDS(aWizFList)
FOR m.i = FCOUNT() TO 1 STEP -1
IF INLIST(aWizFList[m.i,2],'G','M','U') &&Memo field
=ADEL(aWizFList,m.i)
DIMENSION aWizFList[MAX(1,ALEN(aWizFList,1)-1),NUM_AFIELDS]
ENDIF
ENDFOR
THIS.RowSourceType = 5
THIS.RowSource = "aWizFList"
THIS.VALUE = THIS.LIST[1]
 
Kim,
Welll, in simple terms, the "Operator/Operand type mismatch" occurs when you have two different variable types, or an illegal variable type that you are either trying to "join" together, or test against. For example, you can't say does 1 = 'A' because 1 is a number and 'A' is a character value. So, I would expect that somewhere in there, (without being able to run your code, and test against it...) there is probably some "type" testing you are doing that is now yielding a different result...
Try putting "SET STEP ON" at the start of your code, then as thelines progress through (step through 1 line at a time) hover your cursor over the items in the line, and see what their value is, before you click step, and after you click step. You will find EXACTLY where the offending line is, and what value is not giving what is expected.

(When in the debugger, if you hover your mouse over any variable or table name, it will show you the value that item currently has present. A nice feature of the debugger if you are not familiar with it.)

Hope this helps.


Best Regards,
Scott

"Everything should be made as simple as possible, and no simpler."[hammer]
 
Thanks, Scott. I have never used the debugger; however, I know the error occurs on the 7th line of the above code and only occurs when there is a memo field. I get the same error when I try to run the FIND (this is in the FOXPRO 7.0 WIZBTNS library-not my code) on any form that is using a file with a MEMO. Nothing changed from Foxpro 7.0 to Foxpro 9.0. If I remove the memo field from the files, the error goes away. I use the txtbtns buttons on all my forms. I'll see if I can figure out how to use the debugger, but I don't think it will help in this case. Thanks.
 

Kimsue,

It looks like you've hit some sort of bug. The Help says that the array returned by AFIELDS() has 18 columns, but if you look at the array that your code is creating, it only has 16 columns. Your loop is in fact looking at the 2nd col of the first row, the 4th col of the 2nd row, the 6th col of the 3rd row, and so on. This is obviously wrong.

Let me dig a bit further, and I'll post any further findings.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Kimsue,

The spec for the array returned by AFIELDS() changed between VFP 7 and 8. As I mentioned earlier, the array should now return 18 columns, but, looking at it in the debugger, it only has 16. As you've found, this only applies when the table contains a memo field.

I really don't understand what is going on here. However, I suggest the following code as a workaround:

Code:
#DEFINE NUM_AFIELDS 16
LOCAL i, j
PUBLIC aWizFList, aTemp
DIMENSION aWizFList[1], aTemp[1]
AFIELDS(aTemp)
j = 0
FOR m.i = 2 TO ALEN(aTemp)-16 STEP 18
  IF NOT INLIST(aTemp[m.i],'G','M','U')
                  && Not Memo field
      j = j + 1 
      DIMENSION aWizFlist(j)
      aWizFlist(j) = aTemp(m.i - 1)
  ENDIF
ENDFOR
THIS.RowSourceType = 5
THIS.RowSource = "aWizFList"
THIS.VALUE = THIS.LIST[1]

This is putting the field list into a temporary array, then looking at every 18th element of that array, and if not a memo field, copying the field name to the final array. This is not very satisforactory, because it is specific to VFP 8 and above, but it should get you past the present problem.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks, Mike. You are correct. I just signed on to post the solution. I was using the old code. It has been updated in Foxpro 9.0.


LOCAL i
PUBLIC aWizFList
DIMENSION aWizFList[1]
=AFIELDS(aWizFList)
FOR m.i = FCOUNT() TO 1 STEP -1
IF INLIST(aWizFList[m.i,2],"G","M","U") &&Memo field
=ADEL(aWizFList,m.i)
DIMENSION aWizFList[MAX(1,ALEN(aWizFList,1)-1),ALEN(aWizFList,2)]
ENDIF
ENDFOR
THIS.RowSourceType = 5
THIS.RowSource = "aWizFList"
THIS.VALUE = THIS.LIST[1]
 

Kimsue,

Oh, I see now. It wasn't a bug. It was your NUM_AFIELDS constant that made the array 16 columns. I should have noticed that.

Well, that means that my solution isn't specific to VFP 8 and above, as I first thought.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top