Microsoft KB Archive/157194

= PRB: TYPE Function Does Not Indicate Character(Binary) =

Article ID: 157194

Article Last Modified on 10/15/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q157194



SYMPTOMS
The TYPE function does not differentiate between Character and Character(binary) or Memo and Memo(binary) field types. The Type function simply returns a "C" or an "M," respectively.



WORKAROUND
Use the AFIELDS function to create an array that contains information on each field in the table. The procedure listed below, bin_fld, contains code that determines whether a character or memo field is binary. Before executing this code, issue the CREATE TABLE syntax provided in step 1 of the "Steps To Reproduce Behavior" section below.

  Create a program called Test that contains the following code: **** Begin Program Example **** PROC bin_fld PARAMETER a  IF TYPE(a)= "C" OR TYPE(a) ="M" =AFIELDS(test) IF ASCAN(test,UPPER(a)) > 0 fldtype=ASCAN(test,UPPER(a))+1 IF test(ASCAN(test,UPPER(a))+5)=.T.                 retvalu= "Field Type: "+ test[fldtype]+ " Binary" ELSE retvalu= "Field Type: "+ test[fldtype]+ ' Not Binary' ENDIF ENDIF ELSE retvalu= TYPE(a) ENDIF RETURN retvalu **** End program example ****  Type SET PROCEDURE TO Test in the Command window. Type ? Bin_fld("memo1") in the Command window.

The values returned from the bin_fld procedure for character and memo fields indicate not only the field's type but also whether the field is binary.

The AFIELDS function creates an array with specific information on each field in a chosen table. For example, the sixth element of the array created by the AFIELDS function shows whether code page translation is allowed. This field contain a true (.T.) or false (.F.) value. If this element contains a true value in a Character or Memo field type, the field is binary. The TYPE command handles any other field types. Entry of a nonexistent field name produces a "U," indicating undefined.



STATUS
This behavior is by design.



MORE INFORMATION
Character(Binary) or Memo (Binary) are not separate data types, as are Date, Currency, or Numeric types. The Binary versions of these fields prevent the field from conversion into another code page.

The NOCPTRANS clause on the CREATE TABLE or ALTER TABLE commands creates a binary Character or Memo field. This clause prevents a Character or Memo field from being translated into another code page. Since the NOCPTRANS clause works only on character or memo fields, these are the only field types in Visual FoxPro that can be either binary or non-binary. Some fields, however, are binary by design, such as Integer and General types. Therefore, the TYPE function provides adequate information.

Steps to Reproduce Behavior
  In the Command window, type the following command as one line: CREATE TABLE Test (char1 C(10), char2 C(10) NOCPTRANS, memo1 M(4),     memo2 M(4) NOCPTRANS)   Type the following four lines in the Command window: ? TYPE("char1") ? TYPE("char2") ? TYPE("memo1") ? TYPE("memo2") </li></ol>

The commands all return either "C" or "M" depending on the field type without indicating whether or not it is binary.

Additional query words: kbdsd VFoxWin

Keywords: KB157194

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.