gcue Posted March 25, 2013 Share Posted March 25, 2013 (edited) Hello world. I am trying to crop X amount of elements from a 2d array. In other words, I have an array with X amount of rows but I want to only keep the first 150. If X < 150 then keep them all of course. the example below doesnt have +150 records but i was just trying to get the concept going. in the example below I am trying to keep 3 records. I was thinking of doing it this way but it's not working correctly - simple math i know but i still cant do it thanks in advance expandcollapse popup#include <array.au3> $msg_normal = 0 local $array[5] $array[0] = "ABC" $array[1] = "DEF" $array[2] = "GHI" $array[3] = "JKL" $array[4] = "MNO" $number_of_records = UBound($array) $records_to_delete = $number_of_records - 3 debug($array, "BEFORE") For $x = $number_of_records To $records_to_delete Step -1 _ArrayDelete($array, $x) Next debug($array, "AFTER") Func Debug($variable1 = "", $variable2 = "", $variable3 = "") If IsArray($variable1) Then _ArrayDisplay($variable1) Else If $variable2 <> "" Then $variable1 &= @CRLF & $variable2 EndIf If $variable3 <> "" Then $variable1 &= @CRLF & $variable3 EndIf ClipPut($variable1) MsgBox($msg_normal, "Debug", $variable1) EndIf EndFunc ;==>Debug Edited March 25, 2013 by gcue Link to comment Share on other sites More sharing options...
water Posted March 25, 2013 Share Posted March 25, 2013 Why do you want to spend a lot of processor units to crop the array. Can't you just ignore rows > 150? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Nessie Posted March 25, 2013 Share Posted March 25, 2013 (edited) Why overcomplicate the thing? Even if you don't want to ignore rows > 150 (but why?) you can use Redim #include <Array.au3> Local $aResult[5] = ['hello', 'im', 'nessie', 'the Loch Ness', 'monster'] _ArrayDisplay($aResult,"Before") ReDim $aResult[3] _ArrayDisplay($aResult,"After") Hi! Edited March 25, 2013 by Nessie My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s). My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all! My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file Link to comment Share on other sites More sharing options...
water Posted March 25, 2013 Share Posted March 25, 2013 That's it - small and beautiful My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
careca Posted March 26, 2013 Share Posted March 26, 2013 (edited) This is how i do it: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $listview, $msg GUICreate("listview items", 320, 350, 100, 200, -1, $WS_EX_ACCEPTFILES) $listview = GUICtrlCreateListView("col1|col2", 10, 10, 250, 200) GUISetState() For $i = 1 To 20 If $i > 3 Then Sleep(100) Else GUICtrlCreateListViewItem("col1|col2", $listview) EndIf Next Do $msg = GUIGetMsg() Sleep(100) Until $msg = $GUI_EVENT_CLOSE Edited March 26, 2013 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
gcue Posted March 26, 2013 Author Share Posted March 26, 2013 awesome - thank you guys! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now