Jump to content

Array in created text file.


Recommended Posts

Hi,

I am kind of new here, and have created already some tools that helped me a lot during the day.

However, I am having tough time getting this one right.

I have the following:

$file = FileOpen(@TempDir & "\sysinfo.txt", 1)
; Operation System
FileWrite($file, "Operation System - " & @TAB & @OSVersion & @CRLF)
; Physical Memory Installed
FileWrite($file, "Physical Memory Installed - " & @TAB & Round(GetMem() / 1024 ^2, 0) & " MB" & @CRLF)
Func GetMem($srv = "localhost")
    Local $mem, $colItems, $colItem, $ping, $x
    $ping = Ping($srv)
    If $ping Then
        $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $srv & "\root\cimv2")
        $colItems = $objWMIService.ExecQuery("Select Capacity from Win32_PhysicalMemory", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                $mem += $objItem.Capacity
            Next
            Return SetError(0, 0, $mem)
        Else
            Return SetError(2, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc
; Internet Explorer version
Local $ieVersion = FileGetVersion(@ProgramFilesDir & "\Internet Explorer\iexplore.exe")
FileWrite($file, "IE version - " & @TAB & $ieVersion & @CRLF)
; Firefox version
Local $ffVersion = RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Mozilla\Mozilla Firefox', 'CurrentVersion')
FileWrite($file, "Firefox version - " & $ffVersion & @CRLF)
FileClose($file)

Which gives me the following text file:

Operation System -  WIN_7
Physical Memory Installed -     2048 MB
IE version -    8.0.7600.16722
Firefox version - 3.6.13 (en-US)

But I want it to be array like this:

Operation System                   WIN_7
Physical Memory Installed          2048 MB
IE version                         8.0.7600.16722
Firefox version                    3.6.13 (en-US)

I've tried several ways offered here, but could get it right yet.

How can I do it ?

Thanks for the help! - Love it here!

Link to comment
Share on other sites

You'd need to look at the lengths of the first bit, pick the longest, plus a few spaces, then pad the others out with the required number of spaces.

Or, just guess the number of @TAB s you'd need based on typical results.

Does it need to be a txt file?

Could you write it in html, in the form of a table [with or without visible cell boundaries]?

William

Edited by saywell
Link to comment
Share on other sites

  • Moderators

saywell,

Apologies for butting in. :)

drorshem,

Two possibilities here depending on the font you want to use:

- 1. Use a monospaced font such as Courier New or Consolas. Count the number of characters in the first part of the line and add enough spaces to get to the value required before adding the second part of the string. This is the easier option. :)

- 2. If you want to use a proportional font (where the characters are of different widths) it gets more complicated. My StringSize UDF (look in my sig) will give you the length of a string, so you can add spaces to the end of your intial string in a loop until it reaches the required value. However, this can look a little scrappy as the total value is often a pixel or 2 out (even spaces have a width!) so I have found that adding a @TAB at the end can help alignment of the second column. :D

I would provide an example, but I am a bit busy at the moment. Give it a try yourself and come back if you run into problems. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...