|
|
|||||||
Seem to keep having trouble converting this to working KiXtart code. Can someone convert it to working KiXtart code please. I keep getting an error passing the flag in the last array when I set it in parameter. Code: Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 |
||||||||
|
|
|||||||
Code:
I think... |
||||||||
|
|
|||||||
Nope, thanks for trying but same error I get. ERROR : expected ')'! Script: C:\A\AD\test.kix Line : 7 This is line 7 $objUser.SetInfo But I think Line 6 is the one really causing the error. |
||||||||
|
|
|||||||
Well late here and I have work in the morning. I'll check back in the morning. Thanks again. |
||||||||
|
|
|||||||
check out the reference for the put() function. I doubt it supports what we are throwing at it. |
||||||||
|
|
|||||||
doc give this a try: Code:
|
||||||||
|
|
|||||||
Quote: No Doc, don't try that. Stick with the bitwise "|", it's fine. |
||||||||
|
|
|||||||
Doc, you got an extra space in your WinNT string and its screwing up the WinNT path: $objUser = GetObject("WinNT:// " + $strComputer + "/kenmyer") |
||||||||
|
|
|||||||
Thanks Jooel for the bitwise code and thanks Shawn for the space in the name, that was the final key. Code now works as suggested by Jooel and removing the space as suggested by Shawn. Thanks again guys. |
||||||||
|
|
|||||||
Quote:Quote: Richard, what's up with that? Benny's code worked fine too. |
||||||||
|
|
|||||||
If the bit was already set then adding would change other bits as the two values would be summed. You only want to adjust the single bit. |
||||||||
|
|
|||||||
Thanks for the reply Howard. I understand what you mean. Wasn't sure why exactly as I didn't spend the time to work it out that far, but I was thinking concatenation and not bitwise as to why it was or would be wrong. yeah it toggles it when you use the + and either enables or leaves it alone with the | Thanks Howard. |
||||||||
|
|
|||||||
It may "toggle" it, but the carry bit would also affect the adjacent bit. I thought you were 01 of the 10 types of people that understood binary? |
||||||||
|
|
|||||||
LOL, well you see I removed that signature already |
||||||||
|
|
|||||||
No, I don't see. I don't show sigs and avatars. My pages load quicker and there is less scrolling to do. Not to mention how annoying some of them are. |
||||||||
|
|
|||||||
Benny asked the same question, so a quick explanation for anyone else who comes across this thread and who is not binary-flag-aware. It is common practice to store similar flags as bits (on or off) in a single datum. Using an eight bit field as an example, you have eight possible flags. Their positions and values are: Code: 76543210 You can explicitly set the flags in the field just by adding the values together, so to set the flags at positions 1 and 6 you would use 2+64 = 66. However this also sets all the other flags to zero which may not be what you want. If you use the bitwise OR which is "|" in KiXtart, then only the flags that you specify will be set - the other flags will be left unchanged. You cannot simply add the flag values to the existing value. If you do this then (as Les says) the flag will "carry" to the next higher position. This is easy to see with an example. Say you try to set flag 1 four times using addition. This is what would happen: Code:
As you can see, it's all turned into a horrible mess. Even when you are setting bit-fields explicitly it is good programming practice to only use bitwise operators to manipulate them. Not only does this serve as a reminder of what you are changing, but it helps to avoid costly hard to find errors if the field use should later change. To complete the story, you can safely use simple addition and subtraction to change bit settings, but only if you check the setting first: Code:
|
||||||||
|
|
|||||||
Thanks a lot for the explanation there Richard. |
||||||||
|
|
|||||||
I liked the explanation so much that I had to cast my rating in http://www.kixtart.org/ubbthreads/showprofile.php?Cat=0&User=362 |
||||||||
|
|
|||||||
Richard, I think it would be better to be consistent and use the bit-wise NOT (~) operator when turning off a flag instead of subtracting. Code: ; To clear a flag: Code: ; To set the flag: |
||||||||
|
|
|||||||
Quote: Yes, the last examples were demonstrations of how to manipulate the bits using simple math instead of bitwise operations, they are not how I would recommend that the operations are performed. Using the bitwise operations means that you do not need the conditionals at all. I hope that clarifies things. |
||||||||
|
|
|||||||
Oh, how does one adequately check to see if a bit is toggled on in oredr to use simple math to turn a flag on or off? You use bitwise oparations. So why use bitwise operators just to then use addition and subtraction? So to simplify: Code: ; To check a flag a flag: When using bitwise operations it really is necessary to check if a bit is toggled or not. You can just set it or turn it off without regard for its previous state unless your program flow is dependent on the bit value. Code: ;To clear a flag Code: ;to set a flag |
||||||||
|
|
|||||||
Quote: Errr yes If you read back you'll see that I don't at any point advocate using simple maths instead of bitwise operations, in fact I stress that it's a bad idea. The simple maths examples are there to:
|
||||||||
|
|
|||||||
d. To demonstrate how NOT to do it. |
||||||||
|
|
|||||||
This was not a dig. It was only to make a point for the novice readers. |
||||||||
|
|
|||||||
Well though not new, I have not studied or used that type of math in decades on my own, so I appreciate the input and feedback from both Howard and Richard. Thanks for the lesson and information guys. |
||||||||
|
|
|||||||
I had a bit of a eureka moment about 03:00 this morning, which leads me to be less adamant about using only bitwise operators to reset bits. The problem is that scripting languages like KiXtart are "loosely typed". In particular, KiXtart uses sub-types of variant for all it's basic data types. This is especially an issue when using constructs like the bitwise NOT "~". A bitwise NOT reverses the truth of each bit in the parameter. However, the size of the result is determined by the parameter. The results of ~0 could be 255, 65535, 4294967295 or 18446744073709551615 depending on whether the "0" is interpreted as (using Windows terminology) an 8 bit byte, a 16 bit word a 32 bit dword or a 64 bit qword. In KiXtart it is currently simple and everything will be treated as a dword. If you need a byte or word result you have to explicitly cap it, for example "&FF & ~0" for a byte and "&FFFF & ~0" for a word. In other loosely typed languages small values might be interpreted as a byte or a word which could lead to truncation. For example, if you wanted to reset flag #5 (value 32) you might do: Code: $iFlags=3112 In KiXtart this will work, and $iFlags will be set to 3080. But what if you are using a loosely typed language which interprets the 32 as being a byte? You can simulate this in KiXtart: Code: $iFlags=3112 The result is 8, which is clearly wrong. The same problem will occur when small numbers are interpreted as being 16 bit integers. If you know the size of the data that you are attempting to reset the bit in you can explicitly convert the value to the correct type using casts or functions, for example "$iFlags & ~CDbl(32)" Using a conditional test and subtraction (or XOR) to reset the bit is data size independant and might be preferable where the size of the data cannot be pre-determined or guaranteed. |
||||||||
|
|
|||||||
Very good post Richard. This is something I had not considered to date. |
||||||||
|
|
|||||||
just for the records... http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=157126&an=0&page=0#157126 Same question asked, solved, but not with that complete explanation |
||||||||
|
|
|||||||
Richard, Please consider reassembling your words of wisdom into a FAQ and post it in the FAQ forum so more can benefit. |
||||||||
|
|
|||||||
I'd like to second that... Anyone to third it ? |
||||||||
|
|
|||||||
I can third it. although, it's not must as I already learned it. just that it would be beneficial for others too. |
||||||||
|
|
|||||||
Motion carried |
||||||||
|
|
|||||||
it will face the US senate and will be turned down as it introduces threats to national security |
||||||||
|
|
|||||||
ROFL - You have too much insight to the US Law making strategy there Jooel. |
||||||||
|
|
|||||||
well, I watched the reality show called "banning the selling of or harbours to terrorists" and I liked it. like les' sig says, stupidity is human right of every soul... |