Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What exactly is a
Message
De
24/11/2004 11:11:37
 
 
À
24/11/2004 11:04:31
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Database:
Visual FoxPro
Divers
Thread ID:
00964046
Message ID:
00964344
Vues:
7
I agree with Albert that commonly used functions should have easy to recognize and understand names, but I use that function as I first saw it: 'buf2dword' because that is the name I see it posted with the most in other utilities, on the interent, and in threads. It can even be found by buf2dword in google...


>What a community:) But it surely helps exchange ideas, doesn't it.
>I'd recommend StrToInt32 (2 Terry:) over DwordToNum because:
>We say it's a double word in this time slice using still 32 bits environments. Word length might change but bit length doesn't - snowball to avalange trial:)
>Cetin
>
>>Holy cow, ask *ONE* simple question and sometimes it starts a snowball :-)
>>
>>But I have my original question answered: what is a DWORD and Cetin here helped me name my function and as Peter de Valenca has said, what I really want in a function name is something that is accurate - but that accuracy has to be balanced with something I can remember - I think I like the DWordToNum() best (if someone has better name that is more accurate, I'm still open to suggestions).
>>
>>I have a large function library that started way back in FP Dos days (I think it was a guy named Alan Schwartz way back at an early conference who got me started writing functions to increase my "resusability" of code - was that the guy's name - I think he worked for the FoxFire guys). Anyhow, the name is important because if you don't use the function for a long time, it helps to have *some* idea of what you might have called it. And as someone has pointed out, sometimes the names given by MSFT to functions seem "odd" to us who have to use them!
>>
>>Thanks for all the input!
>>
>>Albert Gostick
>>
>>>>Hi Y'all,
>>>>
>>>>Trying to name a function correctly to put it into my library of functions. The following function was pulled from the UT and I want to rename it - but I don't exactly know what a DWORD is. Here is the function:
>>>>
>>>>
>>>>FUNCTION buffer2dword(lcBuffer)
>>>>
>>>>RETURN ASC(SUBSTR(lcBuffer, 1,1)) + ;
>>>>    ASC(SUBSTR(lcBuffer, 2,1)) * 256 +;
>>>>    ASC(SUBSTR(lcBuffer, 3,1)) * 65536 +;
>>>>    ASC(SUBSTR(lcBuffer, 4,1)) * 16777216
>>>>
>>>>
>>>>
>>>>Looking up some definitions via Google, it says "double word" but in this case, it contains a numeric value. Why would they call it a "word" when it contains a number?
>>>>
>>>>Also, what would you call something that is stored as base 256 (the passed in string seems to be base 256). I was thinking of calling the above function 'StringToDWord' but 'string' is a bit ambigous. Note: if worrying about a function name seems 'anal', I have a large library of functions and I think it is important to name them correctly!
>>>>
>>>>Thanks,
>>>>Albert Gostick
>>>
>>>Albert,
>>>A word is 2 bytes and dword is 4 bytes = 32 bits integer (quadword 8 bytes).
>>>Passed in string is I bet a hex string. ie:
>>>
>>>FF is 255
>>>0100 is 256
>>>FFFF is 65535
>>>0D is 13 etc
>>>
>>>In memory an 32 bits integer is stored as a sequence of 4 bytes (reverse order - low order,high order words). ie: "ABCD" is printable but if it stores an integer then its value is:
>>>
>>>asc("A") * 256^0 +
>>>asc("B") * 256^1 +
>>>asc("C") * 256^2 +
>>>asc("D") * 256^3
>>>
>>>IOW above function could be:
>>>
>>>
>>>FUNCTION buffer2dword(lcBuffer)
>>>local lnValue
>>>lnValue=0
>>>for ix=1 to 4
>>> lnValue = lnValue + asc(substr(m.lcBuffer,m.ix)) * 256^(m.ix-1)
>>>endfor
>>>return m.lcValue
>>>
You might call it Str2Int32, Str2Int, Dword2Num, C2Bin etc
>>>Cetin
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform