Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How To Remove Spaces From Object Property Before Writing To File

Posted on 2004-09-30
2
Medium Priority
?
179 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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…
Suggested Courses

971 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