Jump to content

Multiple Created Data into Array


James
 Share

Recommended Posts

Yep, it's me again. I am in need of some more help with putting data into a 2D array.

Here is my poor attempt at putting data into an array:

Func _Drives()
    For $a = 1 To $_AllD[0]
        $Total = Round(DriveSpaceTotal($_AllD[$a]))
        $Free = Round(DriveSpaceFree($_AllD[$a]))
        $Used = Round($Total - $Free)
        $Letter = StringUpper($_AllD[$a])
        $Label = DriveGetLabel($_AllD[$a])
        $Type = DriveGetType($_AllD[$a])
        $Status = DriveStatus($_AllD[$a])
        $FSys = DriveGetFileSystem($_AllD[$a])
        $Serial = DriveGetSerial($_AllD[$a])
        $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
        _GUICtrlListView_SetItemText($DriveList, $iItem, $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & _
                $FSys & "|" & _
                $Serial & "|" & _
                $Free & "|" & _
                $Used & "|" & _
                $Total, -1)
        GUICtrlSetData($Progress[$a], $Used / 1024); not precise
        $Data = _ArrayCreate($Letter, $Label, $Type, $Status, $FSys, $Serial, $Free, $Used, $Total) ; Put the data into an array
    Next
    If @error Then
        If $Warnings = True Then _GUICtrlEdit_AppendText($ConsoleBox, "There was an error reading disk data!")
    EndIf
    _GUICtrlStatusBar_SetText($StatusBar, "Drive Data was loaded!")
EndFunc   ;==>_Drives

I know why it's not working, because it will read through all the data till the last one and then insert it. I need to use 3D array I am guessing?

If you don't understand me, then I need to retrieve all the data for the devices which were found, then I need to put each data into a single array.

Thanks,

James

Link to comment
Share on other sites

Yep, it's me again. I am in need of some more help with putting data into a 2D array.

Here is my poor attempt at putting data into an array:

Func _Drives()
    For $a = 1 To $_AllD[0]
        $Total = Round(DriveSpaceTotal($_AllD[$a]))
        $Free = Round(DriveSpaceFree($_AllD[$a]))
        $Used = Round($Total - $Free)
        $Letter = StringUpper($_AllD[$a])
        $Label = DriveGetLabel($_AllD[$a])
        $Type = DriveGetType($_AllD[$a])
        $Status = DriveStatus($_AllD[$a])
        $FSys = DriveGetFileSystem($_AllD[$a])
        $Serial = DriveGetSerial($_AllD[$a])
        $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
        _GUICtrlListView_SetItemText($DriveList, $iItem, $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & _
                $FSys & "|" & _
                $Serial & "|" & _
                $Free & "|" & _
                $Used & "|" & _
                $Total, -1)
        GUICtrlSetData($Progress[$a], $Used / 1024); not precise
        $Data = _ArrayCreate($Letter, $Label, $Type, $Status, $FSys, $Serial, $Free, $Used, $Total) ; Put the data into an array
    Next
    If @error Then
        If $Warnings = True Then _GUICtrlEdit_AppendText($ConsoleBox, "There was an error reading disk data!")
    EndIf
    _GUICtrlStatusBar_SetText($StatusBar, "Drive Data was loaded!")
EndFunc   ;==>_Drives

I know why it's not working, because it will read through all the data till the last one and then insert it. I need to use 3D array I am guessing?

If you don't understand me, then I need to retrieve all the data for the devices which were found, then I need to put each data into a single array.

Thanks,

James

You could do it with a 1-dimensional array I think. You need to make sure that the upper bound is not exceeded.

You could change to

$sItem = $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & _
                $FSys & "|" & _
                $Serial & "|" & _
                $Free & "|" & _
                $Used & "|" & _
                $Total
$iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
_GUICtrlListView_SetItemText($DriveList, $iItem, $sItem,-1)
GUICtrlSetData($Progress[$a], $Used / 1024); not precise
$Data[$a - 1] = StringSplit($sItem)

But have somewhere before this

Global $data[ $_AllD[0]]

Then each element of the array $Data holds an array.

But since the information will be held in the listview it could be that you could read it from there rather than have a separate array.

EDIT. spelling, errors

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Error:

D:\Programming\AutoIt\HDD PM\HDD PM2.au3(155,37) : ERROR: StringSplit() [built-in] called with wrong number of args.
        $Data[$a - 1] = StringSplit($sItem)
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^oÝ÷ ØX±yØ­Â+ajëh×6$Data[$a - 1] = StringSplit($sItem, "|")
Edited by JamesB
Link to comment
Share on other sites

It still only shows the last drive data.

Apologies for missing out the separator in StrinSplit.

Can you show your code?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It's ok, were all allowed to make mistakes :)

Func _Drives()
    For $a = 1 To $_AllD[0]
        $Total = Round(DriveSpaceTotal($_AllD[$a]))
        $Free = Round(DriveSpaceFree($_AllD[$a]))
        $Used = Round($Total - $Free)
        $Letter = StringUpper($_AllD[$a])
        $Label = DriveGetLabel($_AllD[$a])
        $Type = DriveGetType($_AllD[$a])
        $Status = DriveStatus($_AllD[$a])
        $FSys = DriveGetFileSystem($_AllD[$a])
        $Serial = DriveGetSerial($_AllD[$a])
        
        $sItem = $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & _
                $FSys & "|" & _
                $Serial & "|" & _
                $Free & "|" & _
                $Used & "|" & _
                $Total
        $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
        _GUICtrlListView_SetItemText($DriveList, $iItem, $sItem, -1)
        GUICtrlSetData($Progress[$a], $Used / 1024); not precise ~ Valuater edited my Me
        $Data[$a - 1] = StringSplit($sItem, "|")
        
        #cs
            $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
            _GUICtrlListView_SetItemText($DriveList, $iItem, $Letter & "|" & $Label & "|" & $Type & "|" & _
            $Status & "|" & _
            $FSys & "|" & _
            $Serial & "|" & _
            $Free & "|" & _
            $Used & "|" & _
            $Total, -1)
            GUICtrlSetData($Progress[$a], $Used / 1024); not precise
        #ce
        $Data = _ArrayCreate($Letter, $Label, $Type, $Status, $FSys, $Serial, $Free, $Used, $Total) ; Put the data into an array
    Next
    If @error Then
        If $Warnings = True Then _GUICtrlEdit_AppendText($ConsoleBox, "There was an error reading disk data!" & @CRLF)
    EndIf
    _GUICtrlStatusBar_SetText($StatusBar, "Drive Data was loaded!")
EndFunc   ;==>_Drives

Func _ExportData()
    _ArrayDisplay($Data[$_AllD[0]])
    If @error Then
        _GUICtrlEdit_AppendText($ConsoleBox, "Error exporting data!" & @CRLF)
    Else
        _GUICtrlStatusBar_SetText($StatusBar, "Data was exported" & @CRLF)
    EndIf
EndFunc   ;==>_ExportData

I do have the Global $data[ $_AllD[0]] at the top of my script.

Link to comment
Share on other sites

It's ok, were all allowed to make mistakes :)

Func _Drives()
    For $a = 1 To $_AllD[0]
        $Total = Round(DriveSpaceTotal($_AllD[$a]))
        $Free = Round(DriveSpaceFree($_AllD[$a]))
        $Used = Round($Total - $Free)
        $Letter = StringUpper($_AllD[$a])
        $Label = DriveGetLabel($_AllD[$a])
        $Type = DriveGetType($_AllD[$a])
        $Status = DriveStatus($_AllD[$a])
        $FSys = DriveGetFileSystem($_AllD[$a])
        $Serial = DriveGetSerial($_AllD[$a])
        
        $sItem = $Letter & "|" & $Label & "|" & $Type & "|" & $Status & "|" & _
                $FSys & "|" & _
                $Serial & "|" & _
                $Free & "|" & _
                $Used & "|" & _
                $Total
        $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
        _GUICtrlListView_SetItemText($DriveList, $iItem, $sItem, -1)
        GUICtrlSetData($Progress[$a], $Used / 1024); not precise ~ Valuater edited my Me
        $Data[$a - 1] = StringSplit($sItem, "|")
        
        #cs
            $iItem = _GUICtrlListView_InsertItem($DriveList, "", -1, 1)
            _GUICtrlListView_SetItemText($DriveList, $iItem, $Letter & "|" & $Label & "|" & $Type & "|" & _
            $Status & "|" & _
            $FSys & "|" & _
            $Serial & "|" & _
            $Free & "|" & _
            $Used & "|" & _
            $Total, -1)
            GUICtrlSetData($Progress[$a], $Used / 1024); not precise
        #ce
        $Data = _ArrayCreate($Letter, $Label, $Type, $Status, $FSys, $Serial, $Free, $Used, $Total) ; Put the data into an array
    Next
    If @error Then
        If $Warnings = True Then _GUICtrlEdit_AppendText($ConsoleBox, "There was an error reading disk data!" & @CRLF)
    EndIf
    _GUICtrlStatusBar_SetText($StatusBar, "Drive Data was loaded!")
EndFunc   ;==>_Drives

Func _ExportData()
    _ArrayDisplay($Data[$_AllD[0]])
    If @error Then
        _GUICtrlEdit_AppendText($ConsoleBox, "Error exporting data!" & @CRLF)
    Else
        _GUICtrlStatusBar_SetText($StatusBar, "Data was exported" & @CRLF)
    EndIf
EndFunc   ;==>_ExportData

I do have the Global $data[ $_AllD[0]] at the top of my script.

Remove the line

$Data = _ArrayCreate($Lette.......

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

No data is shown at all now.

I thought it was because I had:

_ArrayDisplay($Data)

Instead of:

_ArrayDisplay($Data[$_AllD[0]])

Now I get an error.

_ArrayDisplay($Data[$_AllD[0]]) 
_ArrayDisplay(^ ERROR
Mabe it's because you are using _ArrayDisplay($Data[$_AllD[0]])

but $Data[$_AllD[0]0 might not be an array.

In the for loop (For $a = 1 to..) you started at 1 so $Data[0] is not an array.

If that's not it then I need to see more of your code.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I am confused.

The Loop for the Drives Function needs to start at 0 for it to get all data. When I changed the Export Function to fit the data, it doesn't do anyting.

I need to see your script then before I can make a sensible suggestion.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...