Jump to content
Sign in to follow this  
gcue

Array Crop

Recommended Posts

gcue

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

#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 by gcue

Share this post


Link to post
Share on other sites
water

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Nessie

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 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

Share this post


Link to post
Share on other sites
water

That's it - small and beautiful ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
careca

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 by careca

Spoiler

Paster - Main function is to paste text, but has more functions.

OpenW - Open With... alternative, Open any file with any application, set it's icon, set application as default.

Renamer - Rename files and folders, remove portions of text from the filename etc.

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

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.

Firefox Profile Backup - Backup/restore previously saved profile.

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.