Monday, October 1, 2007

Simplifying Evaluate

If you're only interested in getting a single value from Evaluate, you don't need to Dim a Variant to containt the Array Evaluate (almost) always returns.

Simply implode the evaluate, and you can assign the Evaluate directly.

Dim commonUsername As String
commonUsername = Implode( Evaluate( |@Name( [CN] ; @UserName )| ) )

6 comments:

Jake Howlett said...

Brilliant! I love tips like this and I hate dimming variants just to get one value.

J E Carter II said...

Very nice little trick, Tommy! Thanks for sharing!

Chris said...

I can't believe I never thought of that before. This has bugged me for years. I always wanted to do this instead:
Evaluate(|@Name([CN]; @UserName)|)(0)

Now I don't have to declare that useless temporary Variant variable anymore.

Thanks!

Nate said...

Nice one, Tommy!

I'm curious... why Implode instead of it's shorter alias Join?

Tommy Valand said...

I guess because of reading co-workers code, and being influenced by the formula-language, which @Implodes.

I think I'll try to change my habit, since, as one commenter on Codestore said, Join is three letters shorter than Implode, and split/join is also what those "operations" are called in JavaScript.

I also think split/join are better descriptions of what is goin on.

William Beh said...

Very very cool. Tried it out and started using it for application which is roll out to production.