Jump to content

Recommended Posts

Posted

been staring at scripts all day and my brains turned to mush

 

if left (existing,1) = "#" and right (existing,1) not = "," then outputstring = existing & " : " & outputstring

 

basically trying to read a value and check the first and last characters such that if it starts with # and ends with , alter a variable but all i keep getting is expected then but it looks correct to me

Posted (edited)
been staring at scripts all day and my brains turned to mush

 

if left (existing,1) = "#" and right (existing,1) not = "," then outputstring = existing & " : " & outputstring

 

basically trying to read a value and check the first and last characters such that if it starts with # and ends with , alter a variable but all i keep getting is expected then but it looks correct to me

@sted

Try something like this

 

if instr(existing, "#") = 1 and inStr(StrReverse(existing), ",") = 1 then outputstring = existing & " : " & outputstring

 

 

(Just in case those of you who know me think I have gone mad - mrwITch posted this!!)

Edited by witch
  • Thanks 2
Posted (edited)

thanks both witches lol its not erroring now just need to alter last bit to be not ","

sorted had to ad an escape clause below it as well but script now works thanks

Edited by sted
Posted
thanks both witches lol its not erroring now just need to alter last bit to be not ","

sorted had to ad an escape clause below it as well but script now works thanks

 

Sorry didn't read original posting properly

for your 'not =' use <>

  • Thanks 1
Posted
Sorry didn't read original posting properly

for your 'not =' use <>

 

Just changed

if instr(existing, "#") = 1 and inStr(StrReverse(existing), ",") = 1 then outputstring = existing & " : " & outputstring

To

if instr(existing, "#") = 1 and not inStr(StrReverse(existing), ",") = 1 then outputstring = existing & " : " & outputstring

Seemed to work but in testing while the expression is fine it didn't do quite what i wanted lol typical so next line is if first and last character is a # then quit (changed final , for a # as its easier to spot

Posted
Just changed

if instr(existing, "#") = 1 and inStr(StrReverse(existing), ",") = 1 then outputstring = existing & " : " & outputstring

To

if instr(existing, "#") = 1 and not inStr(StrReverse(existing), ",") = 1 then outputstring = existing & " : " & outputstring

Seemed to work but in testing while the expression is fine it didn't do quite what i wanted lol typical so next line is if first and last character is a # then quit (changed final , for a # as its easier to spot

 

the

not inStr(StrReverse(existing), ",") = 1

won't work

 

Use the following

if instr(existing, "#") = 1 and inStr(1, StrReverse(existing), ",") = 0 then outputstring = existing & " : " & outputstring

 

should do it

 

This now tests the 1st character (after reversing the string)

The = 0 should indicate that a "," wasn't found

 

So your complete test

if instr(existing, "#") = 1 and inStr(1, StrReverse(existing), ",") = 0 then outputstring = existing & " : " & outputstring

 

should be read as follows

If the 1st char of existing is a "#" and the last char of existing is NOT a "," then modify outputstring

Posted
Seems to work ok i just didn't 100% think it through so it works right but it had an unexpected side effect
Posted

Just re-thought this -- instr is NOT the best way of handling this

 

if mid(existing, 1, 1) = "#" and mid(strReverse(existing), 1, 1) <> "," then outputstring = existing & " : " & outputstring

 

The above is a better test for what you wanted

 

 

?? what was the unexpected side effect ??

Posted

Maybe just me ( could be totally wrong and off the mark here so apologies in advance as am not an expert by any means of the word ) but using all these different functions ie InStrRev, StrReverse etc just seems to over complicate it ??

 

[color=#333333]if left (existing,1) = "#" and right (existing,1) <> "," then outputstring = existing & " : " & outputstring[/color]

 

Something along those lines ?

Posted
Maybe just me ( could be totally wrong and off the mark here so apologies in advance as am not an expert by any means of the word ) but using all these different functions ie InStrRev, StrReverse etc just seems to over complicate it ??

 

[color=#333333]if left (existing,1) = "#" and right (existing,1) <> "," then outputstring = existing & " : " & outputstring[/color]

 

Something along those lines ?

 

Yeah - that should also do it

Posted
Just re-thought this -- instr is NOT the best way of handling this

 

if mid(existing, 1, 1) = "#" and mid(strReverse(existing), 1, 1) <> "," then outputstring = existing & " : " & outputstring

 

The above is a better test for what you wanted

 

 

?? what was the unexpected side effect ??

 

what it does is read a variable from active directory. in theory what it was supposed to do was if it started with a hash but diddnt end with one take the original data add some more and then add a hash. on next run do nowt. what it did was run that bit on the first run through then on 2nd runthrough overwrite the data i was trying to save lol. i just added another if start and end =# exit the script line not 100% what i wanted but does the job well enough

Posted

I may be totally off the mark here but like this?

 

existing = "#test"
wscript.echo existing


if left(existing,1) = "#" and right(existing,1) <> "#" then existing = existing & "newdata" & "#"

wscript.echo existing

if left(existing,1) = "#" and right(existing,1) <> "#" then existing = existing & "newdata" & "#"

wscript.echo existing

 

Take in a variable (from AD for you though),

If it doesn't end in # add "sometext"

Even if run again, do nothing to do it as it end sin # now?

 

Steve

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...