Solved

Array VB scripting

Posted on 2008-10-27
11
143 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug this code 7 56
how to blend these txt lines in a random way? 8 43
using web browser with BING 40 110
vbModal 12 31
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

943 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now