|
|
|||||||
if $PLIST is an array that has all processes running on a machine: Code: $PList = QS(Split(ListProcess('.'),@CRLF)) and I try to call each array value by it's index, why do I have to do this: Code: For Each $proc In $PList Instead of just being able to use this?: Code: For Each $proc In $PList I just don't see what the split() is doing that it's presence not being in my second code is causing it not to work. Also, this does not write to my database, when it tries to write the processes, the first error says, "Error 87: The parameter was incorrect" and then it says, "The Operation Completed Successfully" on the rest only no information is written to the DB. Can anyone help me on either issue? |
||||||||
|
|
|||||||
my comments are inline.... Code:
|
||||||||
|
|
|||||||
Vars in strings are EVIL and array element vars even more so! |
||||||||
|
|
|||||||
Ok, here's how I got it to work with the array and it'd indicies: Code: For Each $proc In $PList Bryce: Thank you for the suggestions but they were a little off. Values is not a UDF, it's a MySQL/SQL command. It's apart of the $processSQL line. I was just asked on my last post to break up my SQL statements with a return character so that the code didn't break this forums tables out to more than 2500 pixels again. And my quotes aren't all over the road, if KiX supported array elements in strings, this is probably exactly how it would look. There are just a lot of quotes because I'm stepping out of the text portion of the variable and using a fuction and concatenating them together inside the string. Bryce/Les: What is so evil about using variables in strings? It's great and it makes coding so much easier. Is there a security aspect I'm missing or is it just your coding preference? |
||||||||
|
|
|||||||
ARGH! They are just EVIL! Don't confuse lazy with easy. |
||||||||
|
|
|||||||
I don't even understand how you would insert the data into the string without using variables. Please keep in mind that my only coding experience is in PHP and it's a much more open and easy format to write to. Can you explain to me how using vars in strings is lazy as opposed to easy so I can know what you're talking about? |
||||||||
|
|
|||||||
Easy! 'string'+$Var+'another string'+$AnotherVar+'a string with "double quotes" in it'+$YetAnotherVar and so on... |
||||||||
|
|
|||||||
Lazy! 'string $Var another string $AnotherVar a string with "double quotes" in it $YetAnotherVar' I almosed puked just typing this out. |
||||||||
|
|
|||||||
But what is the purpose of that? Does it offer faster processing or does having vars in strings pose a vulnerability that I don't know about? To me, this: Code: $string = "The color of the ball is $color." is easier and much more efficient than: Code: $string = "The color of the ball is " + $color + "." Again, is it simply preference or is there some benefit to not using them inside of the string? |
||||||||
|
|
|||||||
Not a security vulnerability but a vulnerability to get bit on the ass. You were alreay bit once with your array elements but you still did not learn your lesson. |
||||||||
|
|
|||||||
How was I bit on the ass? All I did was call the array element incorrectly according to KiX. That wasn't a bite on the ass, that was a coding mistake and if I'm correct, this is the "Starters" category. If there's "Noob" category that I missed, please direct me to the correct area to post. I just wanted a simple answer, preference or problem. And it appears the only reason not to use vars in strings (based off of what you've said), it's only preference... |
||||||||
|
|
|||||||
Using a variable inside a string is valid kix code, but it can lead to undesired effects, especially when you are trying to use $, @ and % in your strings. And when you are using the execute() command, things can get weird... basically the solution you found is defining $proc1, $proc2, and $proc3 as string variables, not array elements. Since they are string variables you can put them inline of a string as long as setoptions('novarsinstring') is set to off, this is kix's default setting. And last... it comes down to personal preference |
||||||||
|
|
|||||||
Thank you Bryce, side-effects/security problems/etc was what I was looking for in regards to problems with using them. Thanx to both of you for the help on my problem. |
||||||||
|
|
|||||||
Here is a vary simple example of why vars in strings should be avoided: Code: "VAR is now '$VAR'"+@CRLF Results are: Code: VAR is now '$VAR' Pretty nasty, I'm sure you'll agree. If you use variables in strings you cannot be sure of the action - it is dependant on the context of the string, and no-one is a fan of ambiguous process when you are trying to write a program. If a variable is in a string any typo in the variable name cannot be caught as an undeclared variable. You are using SetOption("Explicit","ON"), aren't you? |
||||||||
|
|
|||||||
here is another example: $varone='One' $vartwo='Two' $varthree='Three' $String='CanYouPut$varoneInTheStringAnd$vartwoAsWellWithoutSomeSpaceDelimiter?' $String ? |
||||||||
|
|
|||||||
Richard -- I guess I've never had a problem using vars in strings before which is why I don't see why everyone is so against it. Les -- You're right, I didn't think of that example. I suppose the vars in $String would be terribly misinterpreted with VarsInStrings On right? Well, is there a way even with VarsInStrings to step out of the text? i.e. Code: $varone='One' would that work? |
||||||||
|
|
|||||||
You tell'em pip3r, I've never had any problems with vars in strings either. :0) |
||||||||
|
|
|||||||
I don't understand the Q. You are mixing singles and doubles, effectively embedding quotes. $String="CanYouPut"+$varone+"InTheStringAnd"+$vartwo+"AsWellWithoutSomeSpaceDelimiter?" |
||||||||
|
|
|||||||
Shawn, GTH |
||||||||
|
|
|||||||
ok i meant to comment on this yesterday... but work pulled me away. I was noticing that basically you have a string that is build like this. "item1*item2*item3" and you want to turn it into a comma delimited string with quotes like this "item1","item2","item3" Code:
|
||||||||
|
|
|||||||
Quote: Aye, and there's the rub. It's fine while it works - when it doesn't work its a real problem and it may take you a while to discover why your previously well behaved program has stopped working. You don't need to set NoVarsInStrings. Just don't use vars in strings. It's just bad coding practice. It doesn't mean your code won't work just as well as code which doesn't have vars in strings. However you are more likely to encounter a situation where it will fail, and even worse is that you are less likely to know about it. You're probably fed up with examples by now, but here is a good example of code not working as you'd expect: Code: If "$VAR" = "" "Variable $$VAR is not set " ? Else "Variable $$VAR is set" ? EndIf The two conditionals are identical, except one has the variable in a string. The output from this is: Code: Variable $VAR is set Now, that first result can't possibly be what the coder intended, can it? |
||||||||
|
|
|||||||
No I don't think it would be their intention but my latest question still hasn't been answered: You don't have to use vars between quotes even when NoVarsInStrings is off do you? i.e. even when I use vars in strings, if I'm testing to see if a var is set or not, I'd use your second example over the first. The only time I actually use vars in strings is when I'm 'echoing' a string and have a var in it. I mean, in your first example (if you can even do it), why would you use quotes when you don't need it? |
||||||||
|
|
|||||||
Quote: No you don't have to. Whether NoVarsInStrings is on or off, don't put vars in strings. You do need to be aware of the setting of NoVarsInStrings if you are using the "$" character in a string as a real character rather than as a variable metacharacter. Quote: I did do it. That's real code and real results cut'n'pasted from my own console. The example illustrates the mechanism by which even simple code can get screwed up, I'm sure you can extrapolate the example to some more realistic scenarios. |
||||||||
|
|
|||||||
I do understand what you're saying but in all examples, I'd be able to escape out of the quotes to get the result I'm looking for. I guess it's just going to take what you said Richard. Thanx for trying to steer me clear of going headlong off a cliff but I usually end up doing things the hard way first. =P |
||||||||
|
|
|||||||
Then maybe this will help. the option to have vars inside strings beign procesed can be deprecated int he future. I remember Ruud making such a statement some time ago. Also, by using the NoVarsInStrings=ON option one does nto have to worry about the regular '$' sign charatcer in strings. With NoVarsInStrings=ON a single $-sign is sufficient, which comes in very handy if you start using the EXECUTE() function or KiXforms. So, take some advise for the old guys, and try to code cleaner, life will be easier in the long run. |