Assistance using Arrays
Posted: 17 Jan 2010 18:28
Hey guys, I'm trying to figure out how to use 'arrays' and I'm having some trouble. I wasn't able to get the :getipconfig function to work under Windows 7; I was using some sample code from another post that pulled .IPAddress from the array
call:getIPConfig arr
echo.%arr[1].IPv4Address%
echo.%arr[2].IPv4Address%
echo.%arr[3].IPv4Address%
I think in vista though the IP Address line actually reads IPv4 and IPv6 so the sample code to echo the IPAddress may not have been correct. I tried changing it to IPv4Address and that didn't seem to work either.
I also found the :l2a and :dumparr functions and attempted to get those working. I created a text file (list.txt) in the same folder as the batch file and passed it to :l2a using call:l2a list.txt test and then used call:dumparr test in an attempt to output the data, no luck. I'm just missing something and it's not making sense right now.
I'm attempting to store variables in an array and obviously query them as needed, but I also need to be able to update specific variables as well.
Array (at least, in my head) looks something like this:
THREADS 1 2 3 4
RUNNING yes yes no no
OVERFIVEMIN yes no no no
TIMESTARTED 23000000 23040000 0 0
PID 1823 1938 0 0
So basically, If the number of threads overfivemin is equal to the number of threads running, then start an additional thread (in this case, up to 4), when each thread is started I'll need to set the RUNNING, PID, and TIMESTARTED variables for that thread. Later I'll query each PID and when a process ends I'll reset the variables for that thread, then loop back through everything.
Is an array just a bunch of numbered variables, or does it function a little differently? I probably could just set 20 different variables to get this done, but where is the fun in that. If someone could explain arrays, and how the data is stored and retreived, that would be great.
...v
call:getIPConfig arr
echo.%arr[1].IPv4Address%
echo.%arr[2].IPv4Address%
echo.%arr[3].IPv4Address%
I think in vista though the IP Address line actually reads IPv4 and IPv6 so the sample code to echo the IPAddress may not have been correct. I tried changing it to IPv4Address and that didn't seem to work either.
I also found the :l2a and :dumparr functions and attempted to get those working. I created a text file (list.txt) in the same folder as the batch file and passed it to :l2a using call:l2a list.txt test and then used call:dumparr test in an attempt to output the data, no luck. I'm just missing something and it's not making sense right now.
I'm attempting to store variables in an array and obviously query them as needed, but I also need to be able to update specific variables as well.
Array (at least, in my head) looks something like this:
THREADS 1 2 3 4
RUNNING yes yes no no
OVERFIVEMIN yes no no no
TIMESTARTED 23000000 23040000 0 0
PID 1823 1938 0 0
So basically, If the number of threads overfivemin is equal to the number of threads running, then start an additional thread (in this case, up to 4), when each thread is started I'll need to set the RUNNING, PID, and TIMESTARTED variables for that thread. Later I'll query each PID and when a process ends I'll reset the variables for that thread, then loop back through everything.
Is an array just a bunch of numbered variables, or does it function a little differently? I probably could just set 20 different variables to get this done, but where is the fun in that. If someone could explain arrays, and how the data is stored and retreived, that would be great.
...v