Sign in to follow this  
Followers 0
Sypher

Splitting an array

5 posts in this topic

Hey,

I have a rather big array with around 260 entries. This array has to be splitted in pieces of 5.

I want to import this array into a ListView.

Is there a way to do this effective?

Share this post


Link to post
Share on other sites



Hi,

Why do need to split the array? it already splited to elements, easy then that you never can get :whistle:

I want to import this array into a ListView.

Try like this:

GUICreate("List View Test", 400, 300)

$ListViewID = GuiCtrlCreateListView("List", 10, 20, 380, 250)

Dim $Array[6]
$Array[0] = 5
$Array[1] = "Item1"
$Array[2] = "Item2"
$Array[3] = "Item3"
$Array[4] = "Item4"
$Array[5] = "Item5"

For $iL = 1 To Ubound($Array) - 1
    GuiCtrlCreateListViewItem($Array[$iL], $ListViewID)
Next

GUISetState()

While GUIGetMsg() <> -3
    Sleep(10)
WEnd

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Okay, long story short:

In my network there are around 500 switches. All these switches are being monitored by one of our webservers.

This server caches snmp data from the switches, and refreshes it on demand.

At first i planned on doing the snmp part myself, but because AutoIT doesn't have SNMP support and nobody seems to be able to help me out with it (My topic).

Anyhow, i load the data from the selected switch into my program. With a bit of _ArrayPop'ping, i removed some unwanted entries. Now the only thing lasting is 48 FastEthernet ports and 4 Gigabit ports. (that makes 52 ports)

I want to show these ports in a ListView, with all the data from these switches.

This is an example of that i get:

FastEthernet0/1

A07-02 pc

up

10

307

This is:

* Name of the port (Row 1)

* Description of the port (Row 2)

* Status of the port (Row 3)

* Speed of the port (Row 4)

* Vlan of the port (Row 5)

So in my listview this should be something like:

FastEthernet0/1|A07-02 pc|up|10|307

That is why i have to split is as all the ports have 4 specific entries, and their name.

I hope you understand my reason of splitting this array *somehow*

Thanks!

Share this post


Link to post
Share on other sites

Hi,

???

#include <file.au3>
#include <Array.au3>
Global $lines_A
Global $filePath = @ScriptDir & '\read.txt'
Global $newfilePath = @ScriptDir & '\read.txt' ; wenn es dieselbe sein soll :-)
Global $countCRLF = 5
Global $delimiter = '|'
Global $newFile[1]

If Not _FileReadToArray($filePath, $lines_A) Then
    MsgBox(4096, "Error", " Error reading log to Array     error:" & @error)
    Exit
EndIf
;_ArrayDisplay($lines_A, "")
For $i = 1 To $lines_A[0] Step $countCRLF
    _ArrayAdd($newFile, $lines_A[$i] & $delimiter & $lines_A[$i + 1] & $delimiter & $lines_A[$i + 2] & $delimiter & $lines_A[$i + 3] & $delimiter & $lines_A[$i + 4])
Next
;_ArrayDisplay($newFile, "")
_FileWriteFromArray($newfilePath, $newFile, 1)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Mega,

Thanks for the reply.

I'll try the code, from a test:

ONE

1

2

3

4

TWO

1

2

3

4

THREE

1

2

3

4

it ended up like it should be! :whistle:

ONE|1|2|3|4

TWO|1|2|3|4

THREE|1|2|3|4

I adapted your code to match what i want:

For $ix = 1 To UBound($avArray) Step 5
    _ArrayAdd($newFile, $avArray[$ix] & $delimiter & $avArray[$ix + 1] & $delimiter & $avArray[$ix + 2] & $delimiter & $avArray[$ix + 3] & $delimiter & $avArray[$ix + 4])
Next
;~  
_ArrayDisplay($newFile, "")
_FileWriteFromArray($newfilePath, $newFile, 1)oÝ÷ Ø­Ø"½ë&y©Þ®º+ªê-ºÚÊö«¦åz¬w(®·¶{¦mêè~˱Êâ¦Û(®Ë±Êâ¦×béìëjx{yתê-Â¥y«­¢+Ø%µÍ½à À°ÅÕ½ÐìÅÕ½Ðì°ÀÌØíÙÉÉålÀÌØí¥átµÀìÀÌØí±¥µ¥ÑȵÀìÀÌØíÙÉÉålÀÌØí¥à¬ÅtµÀìÀÌØí±¥µ¥ÑȵÀìÀÌØíÙÉÉålÀÌØí¥à¬ÉtµÀìÀÌØí±¥µ¥ÑȵÀìÀÌØíÙÉÉålÀÌØí¥à¬ÍtµÀìÀÌØí±¥µ¥ÑȵÀìÀÌØíÙÉÉålÀÌØí¥à¬Ñt¤oÝ÷ Û
+Í÷Ø­JoyØ­ºÈ§«­¢+Ù±½°ÀÌØí¹Ý¥±lÅulÅt

Now i only have to get rid of [0] and [52] to [55]

Edited by Sypher

Share this post


Link to post
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
Sign in to follow this  
Followers 0