Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

If ElseIf question


  • Please log in to reply
2 replies to this topic

#1 moorsey

moorsey

    Seeker

  • Active Members
  • 7 posts

Posted 26 August 2009 - 01:20 PM

I have written a script that installs some software. But depending on the computer name, enters a different serial code (each code can be applied to a varying number of PCs depending on when it was bought etc).

Only problem is, the script only ever enters the first serial code and never chooses any others. Could anyone suggest why this is?

if @ComputerName = "PCVN121" or "PCVN122" or "PCVN123" or "PCVN124" or "PCVN125" Then     send("serial code 1 {enter}") ElseIf @ComputerName = "PCVN126" or "PCVN127" or "PCVN128" or "PCVN129" or "PCVN1210" Then     send("serial code 2 {enter}") ElseIf @ComputerName = "PCVN1211" or "PCVN1212" or "PCVN1213" or "PCVN1214" or "PCVN1215" Then     send("serial code 3 {enter}") ElseIf @ComputerName = "PCVN21" or "PCVN22" or "PCVN23" or "PCVN24" or "PCVN25" Then     send("serial code 4 {enter}") ElseIf @ComputerName = "PCVN26" Then     send("serial code 5 {enter}") ElseIf @ComputerName = "PCVN27" Then     send("serial code 6 {enter}") ElseIf @ComputerName = "PCVN28" Then     send("serial code 7 {enter}") ElseIf @ComputerName = "PCVN29" Then     send("serial code 8 {enter}") ElseIf @ComputerName = "PCVN210" Then     send("serial code 9 {enter}") EndIf








#2 Nutster

Nutster

    Developer at Large

  • Developers
  • 1,450 posts

Posted 26 August 2009 - 01:57 PM

I have written a script that installs some software. But depending on the computer name, enters a different serial code (each code can be applied to a varying number of PCs depending on when it was bought etc).

Only problem is, the script only ever enters the first serial code and never chooses any others. Could anyone suggest why this is?

if @ComputerName = "PCVN121" or "PCVN122" or "PCVN123" or "PCVN124" or "PCVN125" Then     send("serial code 1 {enter}") ElseIf @ComputerName = "PCVN126" or "PCVN127" or "PCVN128" or "PCVN129" or "PCVN1210" Then     send("serial code 2 {enter}") ElseIf @ComputerName = "PCVN1211" or "PCVN1212" or "PCVN1213" or "PCVN1214" or "PCVN1215" Then     send("serial code 3 {enter}") ElseIf @ComputerName = "PCVN21" or "PCVN22" or "PCVN23" or "PCVN24" or "PCVN25" Then     send("serial code 4 {enter}") ElseIf @ComputerName = "PCVN26" Then     send("serial code 5 {enter}") ElseIf @ComputerName = "PCVN27" Then     send("serial code 6 {enter}") ElseIf @ComputerName = "PCVN28" Then     send("serial code 7 {enter}") ElseIf @ComputerName = "PCVN29" Then     send("serial code 8 {enter}") ElseIf @ComputerName = "PCVN210" Then     send("serial code 9 {enter}") EndIf

In If and ElseIf, each condition is independent. That is to say, that in each condition separated by "or", the variable must be restated.
If @ComputerName = "Mach1" OR @ComputerName = "Mach2" OR @ComputerName = "Mach3" Then

In this situation, where you are comparing one value to a series of values, using a Switch statement is more efficient.
Switch (@ComputerName) Case "PCVN121", "PCVN122", "PCVN123", "PCVN124", "PCVN125"     Send("serial code 1 {enter}") Case "PCVN126", "PCVN127", "PCVN128", "PCVN129", "PCVN1210"     Send("serial code 2 {enter}") Case "PCVN1211", "PCVN1212", "PCVN1213", "PCVN1214", "PCVN1215"     Send("serial code 3 {enter}") Case "PCVN21", "PCVN22", "PCVN23", "PCVN24", "PCVN25"     Send("serial code 4 {enter}") Case "PCVN26"     Send("serial code 5 {enter}") ; etc. EndSwitch

David Nuttall

Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius
AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...


#3 moorsey

moorsey

    Seeker

  • Active Members
  • 7 posts

Posted 26 August 2009 - 02:39 PM

ahhh, that makes sense, great!

Really appreciate the information, lots to learn to get efficient at AutoIt! Will hopefully save me a lot of time on manual software installs though!

Thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users