#74633 - 2003-04-22 10:10 AM
Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Hello to one and all,
I'm not the most gifted code writer in the world, some of you may have already noticed from some of the previous scripts I've posted, but I do give it the old college try.
I'm trying to make the following script work with an Array. But the only thing I can ever get it to print out is the number of elements in the array (not the elements itself, but the actual number of elements I've declared in the the Dimensioning of the Array).
I've looked at some examples to do it, but I'm not sure how to get it to work correctly and the manual's helpfile example is about as useful as a box of matches in the middle of a windstorm.
In the example below, I'd like to be able to read from an array and ping the various machines. For a variety of reasons I've had to replace IP addresses with "machine1, machine2, etc."
The "$scf" found in the script would eventually be replaced by the Array variable.
Thanks in advance for any and all help to one and all.
Z.
code:
;******************************** Déclaration des vairables ********************************* ; GLOBAL $ddl,$ddl1,$bdl1,$bdl2,$ping_file,$ping,$reponse,$scf,$scf2 ; $scf="machine1" $scf="machine2" $scf2="machine3" $ddl="machine4" $bdl1="machine5" $bdl2="machine6" $ping_file=c:\temp\ping.txt ;fichier de sauvegarde pour les pings $ping="" ;variable de la ligne en cours de lecture ; ;*************************************** Vérification des réponses ************************* ; CLS ? "Pinging the $scf, please wait a moment" shell '%comspec% /c "ping $scf >> $ping_file"' IF Open (1,$ping_file)=0 $ping=ReadLine(1) WHILE @ERROR = 0 SELECT CASE INSTR($ping,"de la") $reponse = "The $scf down" CASE INSTR($ping,"TTL") $reponse = "The $scf is Alive" ENDSELECT $ping=ReadLine(1) LOOP $nul=close(1) del $ping_file ENDIF ? $reponse
|
|
Top
|
|
|
|
#74635 - 2003-04-22 10:30 AM
Re: Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Lorenko,
This is what I have tried in a previous example :
code:
DIM $Array(0) DIM $ddl,$ddl1,$bdl1,$bdl2,$scf,$scf2 $z=7 ReDIM $array($z) CLS ? "Pinging the $Array($z), please wait a moment" shell '%comspec% /c "ping $Array($z) >> $ping_file"'
The script basically stays the same as in the original example I gave below. The lines come just after the Remarked line of "Vérification des réponses "
|
|
Top
|
|
|
|
#74637 - 2003-04-22 11:05 AM
Re: Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
? "Pinging the $Array[$z], please wait a moment".
I've modified the () for [] and have removed the above mentioned line from my script, but I still can't make it do what I want it to do.
Is what I want to do, possible at all?
Thx Z.
|
|
Top
|
|
|
|
#74641 - 2003-04-22 11:35 AM
Re: Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Lorenko thanks for your 4 little lines of advise. From those little lines I was able to do what I wanted my script to do.
I've gone with the following
code:
$array=$machine1,$machine2,$machine3,$machine4 FOR EACH $element in $array ? "Pinging $element, please wait a moment" shell '%comspec% /c "ping $element >> $ping_file"' ... ... ... NEXT
But, I'm still trying to compare your example with the one in the manual and I still don't trully "get" the one in the manual.
Thanks again, Z. [ 22. April 2003, 11:57: Message edited by: zdarma ]
|
|
Top
|
|
|
|
#74642 - 2003-04-23 12:19 AM
Re: Making an array
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$array='machine1','machine2','machine3','machine4' for $x=0 to ubound($array) ? 'pinging '+$array[$x]+', please wait a moment' shell '%comspec% /c ping '+$Array[$x]+' >> '+$ping_file next [ 22. April 2003, 12:19: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#74643 - 2003-04-22 01:12 PM
Re: Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Radimus thanks for your example, I adapted it for my needs and it works as well.
I was just wondering if anyone can tell me if the way Lorenko or Radimus showed me how to make the array, if one was better than the other. I noticed a couple of differences in the writting, but I'm not sure if one is better than the other.
Thx, Z.
|
|
Top
|
|
|
|
#74645 - 2003-04-22 03:48 PM
Re: Making an array
|
zdarma
Getting the hang of it
Registered: 2002-10-08
Posts: 83
|
Thanks for the info Lorenko.
I think I'm starting to get it; but until I'm sure, I'll keep trying.
Z.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 384 anonymous users online.
|
|
|