Solved

How To Remove Spaces From Object Property Before Writing To File

Posted on 2004-09-30
2
173 Views
Last Modified: 2010-05-02
I have the following code that writes some info about the computer to a file. The only thing I don't really like about it is when it writes one of the properties (the computer model) it has extra whitespace on the end of it (either a tab or some spaces). Is there any way that I can remove that whitespace before printing the info to the file? Here is the code:

Sub QueryInstances(objClass, Properties, Conditions)
    If Conditions = "None" Then
        strSelect = "Select " & Properties & " From " & objClass
    Else
        strSelect = "Select " & Properties & " From " & objClass & " Where " & Conditions
    End If
    Set objClassName = _
        objWMIService.ExecQuery (strSelect, , wbemFlagReturnImmediately + wbemFlagForwardOnly)
    For Each objComponent In objClassName
        intCount = 1
        objFile.Write (",")
        For Each objProperty In objComponent.Properties_
            If InStr(1, Properties, objProperty.Name, vbTextCompare) Then
                If intCount = 0 Then
                    objFile.Write (",")
                End If
                If intCount = 1 Then
                    intCount = 0
                End If
                If IsNull(objProperty.Value) Then
                    objFile.Write ("NULL")
                Else
                    If objProperty.CIMType <> wbemCimtypeUint32 And _
                        objProperty.CIMType <> wbemCimtypeUint64 And _
                        objProperty.CIMType <> wbemCimtypeSint64 Then
                        objFile.Write (objProperty.Value & GetUnits(objClass, objProperty.Name))
                    Else
                        strUnits = GetUnits(objClass, objProperty.Name)
                        intValue = SizeFormat(objProperty.Name, objProperty.Value, strUnits)
                        objFile.Write (intValue)
                    End If
                End If
            End If
        Next
    Next
End Sub
0
Comment
Question by:Grime121
2 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 500 total points
ID: 12194249
Use the Trim(yourtext) function. There are several posibilities:

1. Trim(text) will eliminate spaces from both edges
2. LTrim(text) eliminate spaces from the left side
3. RTrim(text) from the right side

S
0
 
LVL 1

Author Comment

by:Grime121
ID: 12195049
Cool, here's what I've got:

If ObjClass = "Win32_ComputerSystem" Then
  MyVar = RTrim(ObjProperty)
  objFile.Write (MyVar)
Else
  objFile.Write (objProperty.Value & GetUnits(objClass, objProperty.Name))
End If


Thanks for the help.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

820 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