Solved

Array VB scripting

Posted on 2008-10-27
11
145 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

733 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