Jump to content

_ArrayDelete problems


kalya
 Share

Go to solution Solved by MikahS,

Recommended Posts

Can someone tell me why I have not the same result when running this script . I mean that last posting should have 3 positions with this values .

 

 
#include <GUIConstantsEx.au3>
#include <Array.au3>

 $lista = InputBox("CLV", "greater than 9","10"," M3")
 
    if $lista < 10 Then
   
                    SplashTextOn("","   error ",300, 130, -1, -1, 4, "", 15)
                    Sleep(3000)
                    SplashOff()

    Else
                
                $proc = InputBox("%", "#  ________________", "70", " M2")    
                $procent = Round($lista*$proc/100)        
                $pr=100-$procent
    

Local $aArray[$lista+1]

For $i = 0 To $lista-1

        $aArray[$i]= $i
    
Next

        _ArrayDelete($aArray, 0)




For $j = 1 To $procent
    $ran=Random(0,UBound($aArray),1)
    _ArrayDelete($aArray,$ran)

Next
    
    MsgBox($MB_SYSTEMMODAL, "**********", _ArrayToString($aArray, ",  "))

 
EndIf
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

kalya,

When deleting the items from the array you are setting the top limit too high, so sometimes the _ArrayDelete fails as you pass an index outside the array bounds. :)

This seems to work for me - I say "seems" because it always returns an array with 3 elements, but I have no idea if they are what you want: :wacko:

For $j = 1 To $procent
    $ran = Random(0, UBound($aArray) - 1, 1) ; <<<<<<<<<<<<< Reduce the top limit to equal the highest index in the array
    _ArrayDelete($aArray, $ran)
Next
This does seem a very complex operation - if you could explain what you are trying to achieve we might be able to suggest an easier way to get there. ;)

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

  • Moderators

kalya,

That much I could guess - the question is not "what are you doing", but "what are you trying to achieve". ;)

From where do you get the "variable list? Why do you only need a certain percentage of its entries (and the code you posted always leads 3 elements so it does not meet with what you say you want)?

Help us to help you - what is it all about? :huh:

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

from a list must extract a certain items depend for % percentage.

example :

if the list have 100 items and percentage are 40 % randomly extract the items and in final must have 6 items

i put myself the list length and the percent so it's variable

Link to comment
Share on other sites

  • Moderators

kalya,

As I cannot make any sense of what you are saying (how can 40% of 100 equal 6) I am bowing out - you have a solution to your original problem. :bye:

M23

P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

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

kalya,As I cannot make any sense of what you are saying (how can 40% of 100 equal 6) I am bowing out - you have a solution to your original problem. :bye:M23P.S. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

my mistake, really sorry

i mean 60.i'm on my phone.

when i run my script usually have 3 items in the final list. but not every time so what's wrong. pls i need this script functionally

Link to comment
Share on other sites

When I ran the script with 60 instead of the default 70 you put I got 5 items in the final MsgBox.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

When I ran the script with 60 instead of the default 70 you put I got 5 items in the final MsgBox.

so, something it's wrong because must be only 4 items.

delete function.?!

i don't give up, i know for more peoples from here it's a ridiculously script

Edited by kalya
Link to comment
Share on other sites

Use a MsgBox throughout your code. Like so:

;example
$proc = InputBox("%", "#  ________________", "70", " M2")
$procent = Round($lista*$proc/100)
MsgBox(0, "", $procent) ; here <<<<<<<
$pr=100-$procent

This is very helpful and I see how it gave 5 values, instead of 4 ;)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Use a MsgBox throughout your code. Like so:

;example
$proc = InputBox("%", "#  ________________", "70", " M2")
$procent = Round($lista*$proc/100)
MsgBox(0, "", $procent) ; here <<<<<<<
$pr=100-$procent
This is very helpful and I see how it gave 5 values, instead of 4 ;)

$procent it's everytime ok. i can se in MsgBox. the items from last array is not ok.

Randomly is 4 or 5 more time is 3

Link to comment
Share on other sites

  • Solution

Use a MsgBox anywhere you are not sure of something. I'm sorry, but I barely understood your statements :(

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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