Sign in to follow this  
Followers 0
Hielper

Creating a loop in array

10 posts in this topic

#1 ·  Posted (edited)

Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"
;-

If @OSVersion == $windows[13] Then
msgbox (0, "correct", "correct")
EndIf

Im currently automating an installer, the installer has multiple supported plaftforms so i want to  create an loop checking if the  current PC is equal to the supported platform(array)

Could someone point me in the right direction for creating a loop to check if the current pc is equal to the array.

As im not able to do it on my own, tried to google but i dont seem to understand

Edited by Hielper

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"
;-
For $i = 0 to UBound($windows) - 1
    If ($windows[$i] == @OSVersion) Then
Exit
    Else
     msgbox(0, "", "windows niet gesupport")
    EndIf
Next

Thank you for the help,

Currently i have used your loop and when i come to the else statement, i will get  3 times the window "windows niet gesupport" until it reaches [4]

Do you have a solution for that?

Edited by Hielper

Share this post


Link to post
Share on other sites

Are you using Windows Vista? Because once you get to your system OS version you're exiting your whole script.

Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"
;-
For $i = 0 to UBound($windows) - 1
    If ($windows[$i] == @OSVersion) Then
        MsgBox("", "", "Your OS version is " & $windows[$i])
        ExitLoop    ; ExitLoop, not exit. This finishes the for loop
    Else
     msgbox(0, "", "windows niet gesupport")
    EndIf
Next

 

1 person likes this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

16 minutes ago, InunoTaishou said:

Are you using Windows Vista? Because once you get to your system OS version you're exiting your whole script.

Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"
;-
For $i = 0 to UBound($windows) - 1
    If ($windows[$i] == @OSVersion) Then
        MsgBox("", "", "Your OS version is " & $windows[$i])
        ExitLoop    ; ExitLoop, not exit. This finishes the for loop
    Else
     msgbox(0, "", "windows niet gesupport")
    EndIf
Next

 

im using windows 7,

Edited by Hielper

Share this post


Link to post
Share on other sites

Sorry, thought you said it exited on [4],  misread. you get 3 message boxes and then stops because it got to windows 7, your OSVersion, then exited completely.

Share this post


Link to post
Share on other sites
1 minute ago, InunoTaishou said:

Sorry, thought you said it exited on [4],  misread. you get 3 message boxes and then stops because it got to windows 7, your OSVersion, then exited completely.

yes is there a way to avoid these message boxes, and when the os is compatible just move on to the next comparison i have in mind?

and if its not compatible i want to display a box that says not compatible ( already know how to do that)

Share this post


Link to post
Share on other sites
1 minute ago, Hielper said:

yes is there a way to avoid these message boxes, and when the os is compatible just move on to the next comparison i have in mind?

and if its not compatible i want to display a box that says not compatible ( already know how to do that)

Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"

Global $sInvalidVersions = ""
Global $sValidVersion = ""

For $i = 0 to UBound($windows) - 1
    If ($windows[$i] == @OSVersion) Then
        $sValidVersion = $windows[$i]
    Else
     $sInvalidVersions &= @TAB & $windows[$i] & " niet gesupport" & @CRLF
    EndIf
Next

MsgBox("", "Results", "Valid Version:" & @CRLF & @TAB & $sValidVersion & @CRLF & @CRLF & "Invalid Versions:" & @CRLF & StringTrimRight($sInvalidVersions, 2))

 

1 person likes this

Share this post


Link to post
Share on other sites
6 minutes ago, InunoTaishou said:
Global $windows [13]
;-
$windows[0] = "WIN_10"
$windows[1] = "WIN_81"
$windows[2] = "WIN_8"
$windows[3] = "WIN_7"
$windows[4] = "WIN_VISTA"
$windows[5] = "WIN_XP"
$windows[6] = "WIN XPe"
$windows[7] = "WIN_2016"
$windows[8] = "WIN_2012R2"
$windows[9] = "WIN_2012"
$windows[10] = "WIN_2008R2"
$windows[11] = "WIN_2008"
$windows[12] = "WIN_2003"

Global $sInvalidVersions = ""
Global $sValidVersion = ""

For $i = 0 to UBound($windows) - 1
    If ($windows[$i] == @OSVersion) Then
        $sValidVersion = $windows[$i]
    Else
     $sInvalidVersions &= @TAB & $windows[$i] & " niet gesupport" & @CRLF
    EndIf
Next

MsgBox("", "Results", "Valid Version:" & @CRLF & @TAB & $sValidVersion & @CRLF & @CRLF & "Invalid Versions:" & @CRLF & StringTrimRight($sInvalidVersions, 2))

 

thanks for the help! i finally understand

Share this post


Link to post
Share on other sites

Quick note: "niet gesupport" should be "niet ondersteund" ;) 


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
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
Sign in to follow this  
Followers 0