Solved

How To Remove Spaces From Object Property Before Writing To File

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now