All Forums >> [General Forum] >> Off-Topic Lounge >> Weekly/Monthly Challenge? Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
With the mass of talent (not me) in this forum I was thinking it might be fun to have a contest of sorts. I come up with these ideas (stupid at times) and have no idea how to go about doing anything about them.
There would have to be 3 or 4 skill levels because for me to compete against ehvbs, dm_4ever, or DiGITAL.SkReAM would be funny at best ;-) Obviously I'm not skilled enough to put something like this on.
I just thougt it might be a way to promote the forum and educate people on VBS. People come here for answers, this would help people provide answers, learn to solve script problems and become better scripters.
I do like mcds99's proposal. If you like my sample for a challenge:
According to the VBScript Docs ("VarType Constants") there are these subtypes of variants in VBScript:
vbEmpty 0 Uninitialized (default) vbNull 1 Contains no valid data vbInteger 2 Integer subtype vbLong 3 Long subtype vbSingle 4 Single subtype vbDouble 5 Double subtype vbCurrency 6 Currency subtype vbDate 7 Date subtype vbString 8 String subtype vbObject 9 Object vbError 10 Error subtype vbBoolean 11 Boolean subtype vbVariant 12 Variant (used only for arrays of variants) vbDataObject 13 Data access object vbDecimal 14 Decimal subtype vbByte 17 Byte subtype vbArray 8192 Array
Given the array:
Dim aTests : aTests = Array( 1, "test" )
The line:
WScript.Echo Join( aTests, vbTab )
will output:
1 test
but if you add an object to aTests:
Dim aTests : aTests = Array( 1, "test", New RegExp )
you'll get an error like:
Das Objekt unterstützt diese Eigenschaft oder Methode nicht. (The object doesn't support this method or property)
The challenge: Create an Array aTest with at least one sample for each possible subtype and write a
Function JoinX( aArr, sSep )
that does what Join() should have done in the first place.
and we could reach an agreement regarding the way to post such challenges (and the - hopefully - many answers), I'd gladly do my best to keep you challenged.
Posts: 1944
Score: 30
Joined: 6/29/2006
From: Orange County, California
Status: offline
ginolard - , ehvbs overwhelms me sometimes with his long posts...I'd be afraid to see extremely concise explanations or code from him...so it's good where he's at...at least this way after reading and looking for a few minutes it makes sense to me.
I wanted to take a crack at this but wasn't sure how to handle those types that can't be echoed out...looking at the examples by ebgreen and ehvbs (who I think gave a lot away)...this is what I have so far.
(1) The price: If we get some more interesting/inspiring contributions I would send to the winner (determined by a poll (?) or mutual consense): A German book about VBScript for Beginners with a dedication/devotement signed by me stating that the winner doesn't need the book
(2) Looks like sample data for all types can be fabricated now: the literals Empty, Null und Nothing come handy; the global Err object can be use directly (but see (3)); "CDate(Now())" seems a bit tautologous to me
(3) Did you spot that for the Err object the TypeName is object but the VarType is 3 (Long)? That came as a nasty surprise for me!
(4) Decimal isn't supported by VBScript, so I wouldn't reject a JoinX() that skips this data type; I believe that ginolard's roundabout way via .NET changed his VBScript Currency variable into a Decimal - but I'm not sure
(5) dm_4ever started with the concatenation functionality. Good start, but it looks very complicated to me - isn't there a more simple way? - remember you'll have to cope with an Array containing an Array containing ...
(6) As to the escape (?) to .NET: We (ok - I) want a function JoinX() that can be used as easily as Join(). We (ok - I) wouldn't like the necessity to convert my VBScript arrays to .NET Arraylists. I would renege on this statement if somebody can show/prove that the Arraylist can be joined without further programming, like sJoined = DataList.Join( ", " ).
Looking forwards to more interesting ideas and code!
I have not had much time to look at this, but it did remind me of something that I wrote a very long time ago. I wrote this code when I was learning VBScript so that I could understand dictionaries. It doesn't directly have to do with joining arrays, but the recursive approach that it takes could be a useful point in a possible direction for someone with more time than I have right now.
I've gotta admit, I'm completely lost as to what you are looking for, ehvbs. First off, all variables are type variant in vbs. Never heard of 'subtypes'.
It sounds like you are looking for some kind of recursive element-testing function, that tests each element in an array to see if that element is an array itself. If it is, it tests each of those elements, etc. And then it joins each array/element together.
Is that what you are looking for? I am unsure as all this talk of subtypes has made me somewhat dizzy.
_____________________________
"There's the one man who learns by reading, the two men that learn by watching, and the rest of us have to pee on the electric fence for ourselves." - Roy Rogers
"Would you like to touch my monkey?" - Dieter (Mike Meyers)