Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Example of using Split without giving a variable to the array

 
Logged in as: Guest
arrSession:exec spGetSession 2,16,30369
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Post a VBScript >> Example of using Split without giving a variable to the array
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Example of using Split without giving a variable to the... - 1/27/2006 9:13:13 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
t = Split(MyTextStr,MyDelimiter)(MyArrayNumber)

This example get the first letter of the month  (1 line, 1 Split and lots of parenthesis)

       


< Message edited by Fredledingue -- 1/27/2006 9:20:29 AM >


_____________________________

Fred
 
 
Revisions: 2 | Post #: 1
 
 RE: Example of using Split without giving a variable to... - 1/30/2006 3:25:18 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
This is a valid technique to be aware of. I think a different example would show off it's uses better however. In the example you give, you take a static string ("01/08/2005") then convert it to a formatted date-time, split that, and grab the first character of the 3rd field. When all you would really need to do to get the same information is Left("01/08/2005", 1). Again, I don't say this to invalidate the method. Simply to point out that the example does not showcase the method's versatility. Instead, let's say that you have a text file that has a list of users and a share that they map to in this form:

Doe, John|\\server1\share1
Does, Jane|\\server2\share1
.
.
.

Your job is to echo the name of the server that each user logs in to. (I used an array for the list of lines rather than a text file, but it would work the same regardless)

      

EDIT: Stupid fat finger typos.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Revisions: 1 | Post #: 2
 
 RE: Example of using Split without giving a variable to... - 1/30/2006 7:24:27 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
quote:

all you would really need to do to get the same information is Left("01/08/2005", 1)


Not realy.  Left("01/08/2005", 1)  gave me "0" while my code gave me "A". Try it.

I found your sample interresting too. Especialy the use of For Next and of Function. I don't realy understand why you used a function in this case, but it was interresting to learn how these things work.

_____________________________

Fred

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Example of using Split without giving a variable to... - 1/30/2006 7:34:17 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Running this code:
MsgBox Ucase(Left((Split(FormatDateTime("01/08/2005", 1)," ")(2)),1))

I get a 0 for the result.

As for why I used a function, you are right that it does not ad any value in this instance. I do it mainly out of habit. What usually happens to me is someone says "We want you to take this file and output the name of the server on each line". I do that just fine then 2 days later they say "Oh, and we want to have every 3rd leter capitalized". So I make that change. Then later the same day they say "But only if the 4th letter of the server name is v". So I need to make that change. I just find that keeping things logically grouped lets me handle requests like this better. That is what happens when you are not allowed to gather requirements before you start a project. Keeping things as discrete procedures also helps in a work environment like mine where we encourage everyone to use a common code base. I could then take this function and put it into our script library and everyone could easily copy and paste it into their own scripts at the end and just add one line of code wherever they actually need to use it in their code.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Post #: 4
 
 RE: Example of using Split without giving a variable to... - 1/31/2006 8:29:08 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
"0" ?! What the hell "FormatDateTime("01/08/2005", 1) " returns on your PC?

_____________________________

Fred

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Example of using Split without giving a variable to... - 1/31/2006 9:14:10 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
WScript.Echo FormatDateTime("01/08/2005", 1) returns:
Saturday, January 08, 2005

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Post #: 6
 
 RE: Example of using Split without giving a variable to... - 2/1/2006 11:00:58 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
So try this...


      

Too bad it's not the same in every language. I have "french" language and the white space are not the same as yours and I have no coma.

_____________________________

Fred

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Example of using Split without giving a variable to... - 2/2/2006 12:53:29 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Yes that does give the first leter of the month. My point with the alternative example however was simply that there are built in ways to handle the problem you were presenting without using split. As a matter of fact, I suspect that the reason we ot different results was due to Locale setings. Here is a solution that does not use split and should work for every Locale:

MsgBox Left(MonthName(Month(CDate("01/08/2005"))), 1)

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Post #: 8
 
 RE: Example of using Split without giving a variable to... - 2/2/2006 11:37:04 AM   
  Fredledingue


Posts: 337
Score: 0
Joined: 5/9/2005
From:
Status: offline
ah! MonthName! I didn't know that.

Is there also something like ZodiacSign(Date) or ChineseAstroAnimal(Year(Date)) or FormatDate(Date, VbMayaCalendar)...?




_____________________________

Fred

(in reply to ebgreen)
 
 
Post #: 9
 
 RE: Example of using Split without giving a variable to... - 2/7/2006 4:41:27 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Never ask questions of smartasses. 

Here ya go. Note that your second question is not possible because the non-OO nature of VBScript prevents the overloading of built in functions. O, and I haven't tested it but I suspect that ChineseAstroAnimal is only valid for AD (or CE) if you prefer) dates.


      

EDIT: Extra points if you can tell me the significnce of the date I chose.
EDIT2: I should have pointed out up front that the ChineseAstroAnimal function is not truly accurate. The chinese zodiac uses a lunar calendaring for determining zodiac. It should however match up fairly accruately with the placemats you find in chinese resturaunts.

< Message edited by ebgreen -- 2/7/2006 5:21:31 AM >


_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to Fredledingue)
 
 
Revisions: 2 | Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Post a VBScript >> Example of using Split without giving a variable to the array Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts