I have the following in a batch file:

Set %1=<value>
ex. Set %1=TECRA S1

This value is written using a vb script that detects the system type
in the BIOS. Now, I'm then using this value to set an environment
variable, however, environment variables must not contain spaces so
that I can use IF GOTO statements in my batch file. I need an
addition to my vb script that will remove any spaces OR replace them
with underlines (which ever is easier) before writing the result to
the batch file. Here's an example of my vb script:

--->8----->8---
Dim I, fso, MyFile, s(200), item

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\temp\detect.bat", True)

Set SystemSet = GetObject
("winmgmts:").InstancesOf("Win32_ComputerSystem")
for each item in SystemSet
MyFile.WriteLine "Set %1=" & trim(item.Model)
next

MyFile.close
--->8----->8---

You'll notice that the "Set %1=" value will always be constant and
that it MUST contain a space therefore requiring the script to only
modify the value after the = sign.

I appreciate any help you can offer.

Re: Removing spaces for environment variable by Spyke

Spyke
Mon Apr 26 14:52:44 CDT 2004

decumanusmaximus@hotmail.com (Decumanusmaximus) wrote in
news:5cb12438.0404261015.2bdae43e@posting.google.com:

> I have the following in a batch file:
>
> Set %1=<value>
> ex. Set %1=TECRA S1
>
> This value is written using a vb script that detects the system type
> in the BIOS. Now, I'm then using this value to set an environment
> variable, however, environment variables must not contain spaces so
> that I can use IF GOTO statements in my batch file. I need an
> addition to my vb script that will remove any spaces OR replace them
> with underlines (which ever is easier) before writing the result to
> the batch file. Here's an example of my vb script:
>
> --->8----->8---
> Dim I, fso, MyFile, s(200), item
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set MyFile = fso.CreateTextFile("c:\temp\detect.bat", True)
>
> Set SystemSet = GetObject
> ("winmgmts:").InstancesOf("Win32_ComputerSystem")
> for each item in SystemSet
> MyFile.WriteLine "Set %1=" & trim(item.Model)
> next
>
> MyFile.close
> --->8----->8---
>
> You'll notice that the "Set %1=" value will always be constant and
> that it MUST contain a space therefore requiring the script to only
> modify the value after the = sign.
>
> I appreciate any help you can offer.
>

Try this instead

--->8----->8---
Dim I, fso, MyFile, s(200), item

Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\temp\detect.bat", True)

Set SystemSet = GetObject
("winmgmts:").InstancesOf("Win32_ComputerSystem")
for each item in SystemSet
MyFile.WriteLine "Set %1=" & replace(trim(item.Model)," ","")
next

MyFile.close
--->8----->8---


--

Cheers,
Spyke