Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Array VB scripting

Posted on 2008-10-27
11
Medium Priority
?
150 Views
Last Modified: 2012-05-05
I have created a script that pull the H: drive home directory of a user down from  the Active Directory. It looks like this:  \\TTTT-S-3-01\johndoe$. I need to only get the server name from the string using array function or some other technique that can do this. Basically, I need to cut the Johndoe$ out and only get the : \\TTTT-S-3-01.

How do I do this?
0
Comment
Question by:dongocdung
  • 6
  • 5
11 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22814900
Hello dongocdung,

Try something like:

left(subject, InStr(3, subject, "\"))

where subject is the AD entry

Regards,
Chris
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22814910
dongocdung,

Or to remove the trailing backslash use:

left(subject, InStr(3, subject, "\") - 1)

chris_bottomley
0
 

Author Comment

by:dongocdung
ID: 22815917
I got this message when I run it "Invalid procedure call or argument: "left"

This is what I typed:

Dim strServerDirectory
strServerDirectory = left(HomeDirectoryLine, Instr(3, subject, "\") -1 )
wscript.echo strserverDirectory


where HomeDirectoryLine is \\tttt-s-2-01\johndoe

Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22816146
Most likely HomeDirectoryLine is not constructed as \\astring\anotherstring.

Try adding an extra print:

Dim strServerDirectory
wscript.echo HomeDirectoryLine
strServerDirectory = left(HomeDirectoryLine, Instr(3, subject, "\") -1 )
wscript.echo strserverDirectory

Chris
0
 

Author Comment

by:dongocdung
ID: 22821621
It worked great. Though I can only get the //tttt-s-2-01. How can I get rid of the // also?
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22821665
Sounds like:

mid(HomeDirectoryLine, 3, Instr(3, subject, "\") -3 )

Chris
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1500 total points
ID: 22821671
Or more correctly I think:

mid(HomeDirectoryLine, 3, Instr(3, HomeDirectoryLine, "\") -3 )

Chris
0
 

Author Comment

by:dongocdung
ID: 22821872
Wow....Chris you are a genious...

I also have to 2 other post regarding scripting. If you can help me out, I would greatly appreciated.

Title: Resolve server name to IP and finding current logon user name

Thanks
0
 

Author Closing Comment

by:dongocdung
ID: 31510421
Thanks
0
 

Author Comment

by:dongocdung
ID: 22825127
Thanks
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22825727
I'm actually disappointed at a 'B' grade, which since both this one and the other one are B's is perhaps unfair.

"Grading at Experts Exchange is not like school. It's more like the "10-point Must" system in professional boxing; in other words, an answer is worth an A, unless it doesn't resolve your issue. If it requires you to do a little more research, or figure out one more piece of code, then it's worth a B. If you think it's not worth a B, the custom is to offer the Experts an opportunity to earn a better grade."

More generally I think you will find all the experts have similar beliefs, in that if you don't need to ask for further help  or you ask but get it then an 'A' is appropriate whereas if you need to ask for further help but get none and have to make up the difference yourslf then it is a 'B' if the 'original' question is mostly answered.

Think about it anyway for the future.

Chris
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question