Append variable to an array ?

Discuss and share scripts and script files...
MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

highend wrote: 22 Dec 2023 17:18 Adding to an array is possible but it seems arrays can't contain subarrays...

Code: Select all

    $i = 0;
    foreach($iten,$askusr){
        $ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
        $pArray[$i] = $ccPath;
        $i += 1;
    }
Are you sure this is how you iterate though an Array. I tried this and it should atleast give me one index of 0; instead nothing ?

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

As if I hadn't written a single post in this thread...

Ofc it's possible to iterate this way. But you are (as always) providing NO DATA at all so I won't spend any more time on this
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

highend wrote: 01 Jan 2024 17:50 As if I hadn't written a single post in this thread...

Ofc it's possible to iterate this way. But you are (as always) providing NO DATA at all so I won't spend any more time on this
I have provided data in previous post; why post the same thing twice and what is wrong with some theory, nothing.

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

My original question was to append a variable to an array.
HighEnd mentioned to initiate the variable outside of the forEach loop, then within the forEach loop iterate over that variable.

Code: Select all

$i = 0;
    foreach($iten,$askusr){
        $ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),2,||);
        $pArray[$i] = $ccPath;
        $i += 1;
    }
One should be able to take that information and add to any code that they want to append a variable to an array; which I did but is it not working. Instead of trying to help; he just follows the administrators path and decides to ignore the post, what kind of garbage is going on here cause it's strange. Do you want people to script in XY or is it just for a select few cause that would make no sense considering anyone can buy XY and script.

RalphM
Posts: 1935
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Append variable to an array ?

Post by RalphM »

A bit rich of you to ask what is going on here in your post #17 and question the helpfulness of long standing forum members who have helped countless users over the years.
You post snippets of your code without any explanation what the variables at the start of your snippet contain and then expect us to come up with solutions to fix your code.
Firstly read the help on the commands you want to use carefully and, if you still need help, provide the full code and a detailed description of what you are trying to achieve with it.
Switching on step mode and checking the contents of your variables when your script fails might also be a good idea.
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

RalphM wrote: 03 Jan 2024 06:20 A bit rich of you to ask what is going on here in your post #17 and question the helpfulness of long standing forum members who have helped countless users over the years.
You post snippets of your code without any explanation what the variables at the start of your snippet contain and then expect us to come up with solutions to fix your code.
Firstly read the help on the commands you want to use carefully and, if you still need help, provide the full code and a detailed description of what you are trying to achieve with it.
Switching on step mode and checking the contents of your variables when your script fails might also be a good idea.
If the code doesn't make sense to you; that is because it's not complete. In the fifth line down I have a variable called $vArray which is an array which I have a variable assigned as mentioned by Highend so that each path gets assigned a index value. Although when I want to return the index value of 3 the output is the array variable with the number three in other words; $vArray[3] instead of whatever index path that index should have had assigned to it.

I understand what Highend did, what I don't understand is why it's not assigning an index to each path so I can return the index and I get the path for whatever index is assigned to that path. Once again, if the code doesn't make sense to you it's not complete.

Code: Select all

$askusr = inputfolder("C:\","Choose Source Folder");
 $i=0;
 foreach($iten,$askusr){
    foreach($nArray,$iten){
 $listpane = listpane(a,*,2,,);
 $vArray[$i] = array($listpane);
 echo $vArray[3];
    };
 };
 $ccPath = listfolder($iten,input("Folder to Find",,,e,300,300),1);
 $pArray[$i] = $ccPath;
 $i += 1;
 $gPath = pathreal($ccPath);

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

Are you f*** serious?

You've been told to activate "Syntax Checking". You didn't
You've been told that $askusr will only contain one item, iterating over one item is... <no comment>
And now you add another loop inside that ALSO loops over a single item???
No $i incrementation inside the loop: $vArray would always get assigned <something> at index 0^^
$vArray[3] = Always empty
You've been told that arrays in arrays aren't possible and you're still trying to assign it
listpane() on a chosen folder? If you are already inside the folder you wouldn't have to choose it first
If not, it's totally different data

The code gets worse every time

You have absolutely NO clue what you're doing here.
Learn basic scripting first and if you don't want to do that, stop scripting^^
It's leading nowhere...
One of my scripts helped you out? Please donate via Paypal

MonkeyButt
Posts: 19
Joined: 21 Dec 2023 01:31

Re: Append variable to an array ?

Post by MonkeyButt »

highend wrote: 03 Jan 2024 16:31 Are you f*** serious?

You've been told to activate "Syntax Checking". You didn't
You've been told that $askusr will only contain one item, iterating over one item is... <no comment>
And now you add another loop inside that ALSO loops over a single item???
No $i incrementation inside the loop: $vArray would always get assigned <something> at index 0^^
$vArray[3] = Always empty
You've been told that arrays in arrays aren't possible and you're still trying to assign it
listpane() on a chosen folder? If you are already inside the folder you wouldn't have to choose it first
If not, it's totally different data

The code gets worse every time

You have absolutely NO clue what you're doing here.
Learn basic scripting first and if you don't want to do that, stop scripting^^
It's leading nowhere...
I know the code was not perfect, I did say that twice in my last message. :eh:

You mention no $i incrementation inside the loop yet you didn't show the initialization of it inside the loop either. Instead of trying to help you just behave like a nasty bugger who just hates anyone who you deem to hate. God willing I hope you don't teach people how to drive, that probably is a nightmare.

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Append variable to an array ?

Post by highend »

You mention no $i incrementation inside the loop yet you didn't show the initialization of it inside the loop either
My code showed both^^ :blackstorm:

$i = 0;
$i += 1;

Thread closed, as already said: It leads nowhere...
One of my scripts helped you out? Please donate via Paypal

Locked