Solved

Array VB scripting

Posted on 2008-10-27
11
142 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 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

21 Experts available now in Live!

Get 1:1 Help Now