Solved

Array VB scripting

Posted on 2008-10-27
11
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…

724 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