Solved

How To Remove Spaces From Object Property Before Writing To File

Posted on 2004-09-30
2
172 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

773 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