Assigning text to a variable. Problem, text contains tabs.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

Assigning text to a variable. Problem, text contains tabs.

Post by miles.williams » Fri Jun 03, 2005 3:48 pm

I am copying text from an alarm system, writing it to a file, then assigning it to a variable, then entering it into a fault logging / ticketing system, the problem is that sometimes there is a Tab in the alarm text, this is being read as Press Tab and is shifting the focus and causing all sorts of problems, how can I replace the Tab with several spaces ?

I have tried the following :

stringreplace>INSTRUCTIONS, {there is a tab here} ,,INSTRUCTIONS
stringreplace>INSTRUCTIONS,Tab,,INSTRUCTIONS


Any ideas lads and lasses ?

Thanks.

miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

Anyone ?

Post by miles.williams » Wed Jun 08, 2005 8:27 am

Is there anyone out there that can shed some light on the subject ? If my post was a little too complicated, then in summary, I want to character replace the invisible gap (tab) with something else, like 5 "space"s

miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

Re: Anyone ?

Post by miles.williams » Wed Jun 08, 2005 8:30 am

miles.williams wrote:Is there anyone out there that can shed some light on the subject ? If my post was a little too complicated, then in summary, I want to character replace the invisible gap (tab) with something else, like 5 "space"s
- Whoops sorry.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Jun 08, 2005 8:55 am

Something like this:

VBSTART
VBEND
VBEval>Replace("hello world",vbTab,""),new

e.g, if INSTRUCTIONS is your variable containing the string:

VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS
MJT Net Support
[email protected]

miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

Thank you very much

Post by miles.williams » Wed Jun 08, 2005 9:14 am

I know nothing about VB yet, but just to clarify :

VBEVal>Replace("%INSTRUCTIONS%",vbTab,""),INSTRUCTIONS

This will replace a tab space (vbTab) with nothing (what is between the "") Is that right ? If this is the case could I replace it with " " ? (seven spaces, not showing up properly) Or would I need to have :

VBEVal>Replace("INSTRUCTIONS%",vbTab,"vbSpace*7"),INSTRUCTIONS

Thanks for the reply.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Jun 08, 2005 9:20 am

Hi,

Yes, my example replaces tab with nothing. You could replace it with seven spaces just by doing:

VBEVal>Replace("%INSTRUCTIONS%",vbTab," "),INSTRUCTIONS

Or:

VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS
Last edited by support on Thu Jun 09, 2005 6:33 am, edited 1 time in total.
MJT Net Support
[email protected]

miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

hmm

Post by miles.williams » Wed Jun 08, 2005 11:06 am

That appears to have not worked, I'll supply the entire section of script that might make things clearer :


Previous to this I have copied and writeln'd text to a file c:\reminstruct.tmp...


Let>linenum=1

ReadLn>c:\reminstruct.tmp,%linenum%,line
Let>instructions=%line%%CR%
Let>linenum=%linenum%+1
label>start1
ReadLn>c:\reminstruct.tmp,%linenum%,line
If>%line%=##EOF##,end1
Let>INSTRUCTIONS=%INSTRUCTIONS%%line%%CR%
Let>linenum=%linenum%+1


Goto>start1
Label>end1


VBSTART
VBEND
VBEVal>Replace("%INSTRUCTIONS%",vbTab,Space(7)),INSTRUCTIONS

message>%instructions%



And the result from this is :

Microsoft VBScript compilation error :1033
Unterminatated string constant

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Jun 08, 2005 11:26 am

Something else in the string means VBScript doesn't like it. Here's another way to do it which uses the native StringReplace function:

//Put these two lines at start of script
VBSTART
VBEND

//This line gives us a native variable containing the tab character
VBEval>vbTab,msTab
//This line replaces occurences of msTab with seven spaces
StringReplace>INSTRUCTIONS,msTab, ,INSTRUCTIONS
MJT Net Support
[email protected]

multifix
Newbie
Posts: 8
Joined: Mon Mar 28, 2005 4:17 pm
Location: Florida

could it be ?

Post by multifix » Wed Jun 08, 2005 2:58 pm

I noticed in support's example that the VBreplace function had one%sign but Miles' had two. Syntax error?
Kris

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Jun 08, 2005 11:29 pm

Yes, syntax error, should be two.

Perhaps support will edit original posting with both?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu Jun 09, 2005 6:33 am

Correct - should have been two - I have edited post accordingly.
MJT Net Support
[email protected]

miles.williams
Newbie
Posts: 14
Joined: Fri May 13, 2005 8:51 am

SUCCESS !!!

Post by miles.williams » Tue Jun 14, 2005 3:08 pm

Thank you guys I was pulling my hair out over that one, it works a treat ! Another problem solved.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts