Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inconsistentent Behaviour of a Code
Message
De
29/05/2013 11:26:28
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
29/05/2013 06:54:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01575038
Message ID:
01575051
Vues:
65
>I am using some code to generate Serail Number of a computer system so that I can use the same serail number for the purpose of locking my software with a particular system.
>
>The problem is the LOCK NUMBER being generated is sometimes "067A067$FB780:050:050:300:301:53VM/S1172" while sometimes it is "067A067AFB780:050:050:300:301:53VM/S1172".
>
>The 8th digit i.e "$" is replaced by "A " and sometimes $ comes. What is the bug, how to overcome it.
>
>Here is my code
>
>
>M=0
>HDDNO=GetVolumeSerial()
>
>*CPUID Type-I*
>LOCAL lcComputerName, loWMI, lowmiWin32Objects, lowmiWin32Object
>lcComputerName = GETWORDNUM(SYS(0),1)
>loWMI = GETOBJECT("WinMgmts://" + lcComputerName)
>lowmiWin32Objects = loWMI.InstancesOf("Win32_Processor")
>FOR EACH lowmiWin32Object IN lowmiWin32Objects
>    WITH lowmiWin32Object
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>    ENDWITH
>ENDFOR
Hi Harsh

I want to teach you something. WITH is not all that useful, especially in the above. It would be better to do this:
>FOR EACH lowmiWin32Object IN lowmiWin32Objects
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>ENDFOR
WITH is good when you have many properties to access like this:
>    WITH lowmiWin32Object
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>        cIDTYPEONE= TRANSFORM(.ProcessorId)
>    ENDWITH
but it is not any better than this (except for less typing) and you can use this approach across many objects:
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
>        cIDTYPEONE= TRANSFORM(lowmiWin32Object.ProcessorId)
There is a risky "feature" of with.

If you do this
>FOR EACH lowmiWin32Object IN lowmiWin32Objects
>    WITH lowmiWin32Object
>        cIDTYPEONE= SOMEUDF(.ProcessorId)
>    ENDWITH
>ENDFOR
The WITH stays in effect in someudf. That is not a best practice. It is best to explicitly pass parameters to a udf. A typing mistake could cause a messy debugging session inside someudf or other called routines. I just avoid WITH...ENDWITH unless I have no choice.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform