Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Field name != variable name?
Message
De
21/05/1998 14:21:48
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00100420
Message ID:
00100900
Vues:
68
>>I put this in chatter because I've already found the solution, but I'm curious why it was a problem in the first place.
>>
>>I have the following code:
>>
>>public clname
>>clname = ""
>>public cfname
>>cfname = ""
>>
>>Clname = left(newname,at(",", newname)-1)
>>Cfname = right(newname,len(newname)-at(",", newname)-1)
>>
>>select 0
>>use (bal_file) alias bal
>>select bal
>>
>>scan for alltrim(bal.client_num) = alltrim(ClNum)
>> replace bal.lname with Clname
>> replace bal.fname with Cfname
>>endscan
>>
>>(newname comes in to the program as a parameter, and bal_file is defined earlier)
>>
>>It splits up newname into clname and cfname just fine according to a messagebox. But when I open the bal file, it _changes_ the value of those two variables to a completely different name! I went round and round with it, with no clue why it should be changing the variables when I didn't tell it to. Finally, in desperation, I changed the variable names. That did it.
>>
>>The best I can figure out is it thinks clname and cfname are equivilent to the field names bal.lname and bal.fname. So when I open the bal file, it fills in the global variables with the fields it finds there in the first record.
>>
>>But why? lname != clname. This doesn't make sense.
>>
>>My solution was to change the variables to cl and cf. That fixed it, but it's still got me baffled as to why it happened in the first place.
>>
>>Thanks,
>
>Are you sure you haven't got fields called "clname" and "cfname". When I first started at this company, I was dumped with some progs using vars that matched field names - grew me some more gray hairs with that. Fox looks for fields before vars.

A reasonably quick solution is to always make sure you refer to your variables with the "m." prefix, your object properties with "object_name.", and your data table fields with the "table_name." prefix. This is an always-works, never-fail solution, and in the wonderful world of objects, it is very mandatory.

No matter what version of Fox you're using, this should become a standard programming practice from day one. It improves code readibility and preventgs the above mentioned situation. In fact, I've forced programmers working under me to recode their work if they are not doing this.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform