Solved

How To Remove Spaces From Object Property Before Writing To File

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

707 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

17 Experts available now in Live!

Get 1:1 Help Now