Jump to content

Variable & Array Question


Xonos
 Share

Recommended Posts

I have a question. I'm piecing together a small script that will read a computer's name and break it apart to determine computers exact location within a school district. This will help us with deploying software that needs to be specifically tweaked on a wide-scale without manually doing it per each classroom.

With that in mind and knowing very little on storing data into arrays, I've decided to take on this challenge.

The naming convention works like this:

###-#####-#### <12 is Max # of characters in name as well.

Campus Abbreviation - Room Location - System Type - Count

So, if I were at Rodney King Highschool in room 402 at a teachers computer, it would read:

RHS-00402-DT01 (DT = Desktop Teacher) 01= number of system, if there were 2 teachers, there might be DT02 in the room as well.

Anyways, with this naming convention in mind, this is the script broken down:

#include <Array.au3>
#include <CampusVariables.au3>

Global $Computer = "MHS-0B234-DT22"
Global $CampusLocation = _IsArrayItemInString ( $CAMPUS, $Computer )
Global $TrimABVR = StringLen($CAMPUS[$CampusLocation])
Global $RoomLocation = _IsArrayItemInString ( $CAMPUS_SELECTOR[$CampusLocation], StringTrimLeft($Computer, $TrimABVR + 1))
Global $SystemTypeCheck = _IsArrayItemInString ($SystemType, StringRight($Computer, 4))
ConsoleWrite ( "Campus Array : " & $CAMPUS[$CampusLocation] & @CRLF)
ConsoleWrite ( "Room Array : " & $CAMPUS_SELECTOR[$CampusLocation[$RoomLocation]] & @CRLF)
ConsoleWrite ( "System Type : " & $SystemType[$SystemTypeCheck] & @CRLF)
Func _IsArrayItemInString ( $_Array, $_Item )
    For $_A = 1 To UBound ( $_Array ) - 1
        If $_Array[$_A] <> '' And StringInStr ( $_Item, $_Array[$_A], 2, 1, 1, StringLen($_Array[$_A])) <> 0 Then Return $_A
   ;Return ($_A & " and the value for this item is: " & $CAMPUS[$_A])
    Next
    Return "This system is either not named properly or is not a system needing LanSchool configured. LanSchool will not be installed."
EndFunc ;==>  _IsArrayItemInString ( )

CampusVariables.au3

;Workstation Type Variables
Dim $SystemType[6] = ["DT","DA","DL","DS","MS"]
Dim $AHS[21] = ["0A107","0A108","0A202","0B206","CM129","CM157","CM158","CM171","CM229","000F1","FA107","FA108","FA112","FA116","FA117","FA118","0V100","0V200","0V204","0V205","0V207"]
Dim $MHS[25] = ["0A120","0A160","0A161","0A170","0A228","0A229","0A232","0A236","0A242","0A244","0B101","0B134","0B205","0B210","0B217","0B234","0C133","0C138","0C243","0C244","0C248","0D106","0D113","0D122","D158B"]
Dim $ALC[4] = ["00118","00142","00218","00220"]
Dim $AJH[2] = ["00209","00400"]
Dim $FJH[2] = ["0A208","0B125"]
Dim $HJH[3] = ["00116","00211","00223"]
Dim $MJH[2] = ["00308","00406"]
Dim $RJH[2] = ["0A124","0B125"]
Dim $AES[2] = ["00403","00404"]
Dim $APS[1] = ["00210"]
Dim $DJE[3] = ["00119","00502","00703"]
Dim $ECM[2] = ["0210A","0210B"]
Dim $GYE[1] = ["00303"]
Dim $HCE[2] = ["00300","00301"]
Dim $LFE[2] = ["00418","00528"]
Dim $LIW[2] = ["00106","00302"]
Dim $MME[2] = ["00119","00501"]
Dim $MTP[2] = ["00015","00016"]
Dim $PME[2] = ["00501","00502"]
Dim $RLS[2] = ["00108","00401"]
Dim $SLE[2] = ["00106","00302"]
Dim $WDE[2] = ["00CL1","00MR3"]
Dim $TSD[2] = ["0LABA","0LABB"]
;Campus Name Variables
Dim $CAMPUS[23] = ["AES","APS","DJE","ECM","GYE","HCE","LFE","MME","MTP","PME","RLS","SLE","WDE","LIW","AJH","FJH","HJH","MJH","RJH","AHS","MHS","ALC","TSD"]
;Campus Variables using the same array range as $CAMPUS.
Dim $CAMPUS_SELECTOR[23] = [$AES,$APS,$DJE,$ECM,$GYE,$HCE,$LFE,$MME,$MTP,$PME,$RLS,$SLE,$WDE,$LIW,$AJH,$FJH,$HJH,$MJH,$RJH,$AHS,$MHS,$ALC,$TSD]

Everything works except for one thing - I am trying to call the appropriate campus variable by what is returned for $CAMPUS when reading the name. Whenever $CAMPUS returns a number, I then call $CAMPUS_SELECTOR[$CampusLocation[$RoomLocation]] in an effort to call the appropriate variable and the corrosponding array number.

Apparently I don't fully understand how this links together because it errors out:

DevelopmentSrv1DevelopmentSoftwareLanSchool DeploymentInstall LanSchool.au3 (14) : ==> Campus Array : MHS

Subscript used with non-Array variable.:

ConsoleWrite ( "Room Array : " & $CAMPUS_SELECTOR[$CampusLocation[$RoomLocation]] & @CRLF)

ConsoleWrite ( "Room Array : " & $CAMPUS_SELECTOR[$CampusLocation^ ERROR

>Exit code: 1 Time: 0.214

Does anyone have insight on a better way to do this or perhaps point out material that would help me? I don't expect anyone to re-write my code, just give me a hint. I am trying hard to learn but I'm hitting my head.

Edited by Richardo

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Link to comment
Share on other sites

$CampusLocation[$RoomLocation] is not an array! These are 2 integer values!

Btw, I would use a 3D array storing all the information.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I will read into 3d arrays however I do have a question.

I do understand that "$CampusLocation" is not an array however I am using the returned integer to specify which variable to return. $CampusSelector lists (in the same order as $Campus) all of the pre-defined variables as you can see in the variables.au3 file.

Global $CampusLocation = _IsArrayItemInString ( $CAMPUS, $Computer )

The function searches the computers name prefix in a list of 23 variants within $CAMPUS.

[center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center]

Link to comment
Share on other sites

Is this something for you?

#include <Array.au3>
Global $CAMPUS[23][26] = [ _
            ["AES", "00403","00404"], _
            ["APS", "00210"], _
            ["DJE" , "00119","00502","00703"], _
            ["ECM", "0210A","0210B"], _
            ["GYE", "00303"], _
            ["HCE", "00300","00301"], _
            ["LFE", "00418","00528"], _
            ["MME", "00119","00501"], _
            ["MTP", "00015","00016"], _
            ["PME", "00501","00502"], _
            ["RLS", "00108","00401"], _
            ["SLE", "00106","00302"], _
            ["WDE", "00CL1","00MR3"], _
            ["LIW", "00106","00302"], _
            ["AJH", "00209","00400"], _
            ["FJH", "0A208","0B125"], _
            ["HJH", "00116","00211","00223"], _
            ["MJH", "00308","00406"], _
            ["RJH", "0A124","0B125"], _
            ["AHS", "0A107","0A108","0A202","0B206","CM129","CM157","CM158","CM171","CM229","000F1","FA107","FA108","FA112","FA116","FA117","FA118","0V100","0V200","0V204","0V205","0V207"], _
            ["MHS", "0A120","0A160","0A161","0A170","0A228","0A229","0A232","0A236","0A242","0A244","0B101","0B134","0B205","0B210","0B217","0B234","0C133","0C138","0C243","0C244","0C248","0D106","0D113","0D122","D158B"], _
            ["ALC", "00118","00142","00218","00220"], _
            ["TSD", "0LABA","0LABB"]]
Global $SystemType[6] = ["DT","DA","DL","DS","MS"]
Global $Computer = "MHS-0B234-DT22"

If Check($Computer) Then
    MsgBox(0, "Test", "System is properly named")
Else
    MsgBox(0, "Test", "This system is either not named properly or is not a system needing LanSchool configured. LanSchool will not be installed.")
EndIf

Func Check($sToken)
    If StringLen($sToken) > 14 Then Return SetError(1, 0, False)
    Local $aTokens = StringSplit($sToken, "-", 2)
    If @error Then Return SetError(2, 0, False)
    Local $pos = _ArraySearch($CAMPUS, $aTokens[0], 0, 0, 0, 0, 1, 0)
    If @error Then Return SetError(3, 0, False)
    Local $f1 = False, $f2 = False, $i = 1, $ub = UBound($CAMPUS, 2)
    While $i < $ub
        If $CAMPUS[$pos][$i] = $aTokens[1] Then
            $f1 = True
            ExitLoop
        EndIf
        If $CAMPUS[$pos][$i] = "" Then ExitLoop
        $i += 1
    WEnd
    If $f1 And _ArraySearch($SystemType, StringLeft($aTokens[2], 2)) <> -1 Then Return True
    Return False
EndFunc

I used "only" a 2D array.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

×
×
  • Create New...