Jump to content

cant get array to work properly


mrstinky
 Share

Recommended Posts

Hey all,

im trying to get this array to work but it will just read the first value of the array and copy that into my output.

ive been looking around the forum and in the helpfile either im blind or just not seeing the solution, so hope someone can help me with it

what i basicly want is that my array looks at the username where ill be using @username for the current logged in user, if the user starts with anything like a 01234...it should go to the folder \users0-f\ if the username starts with a ghijkl...etc.. i want it to go to the \usersg-t\ folder.

i just made the output will msgbox but will later make this drivemapadd to map a drive.

below is my test script used.

#Include <Array.au3>

#include <String.au3>

$share = "\\sharename\folder"

;we grab the first letter of the username

$username = "example"

$firstlet = StringLeft($username,1)

Dim $array[2]

$array[0] = "0123456789abcdef;\users0-f\"

$array[1] = "ghijklmnopqrst;\usersg-t\"

For $firstletter in $array

$hds = StringSplit($firstletter,";")

$hdslet = $hds[0]

$hdt = $hds[2]

If StringInstr($hdslet,$firstlet) > 1 then

$hd = $share & $hdt & $username & @CRLF

EndIf

exitloop

Next

$hd = $share & $hdt & $username

Msgbox(0,"testing","Result is: " & $hd)

Edited by mrstinky
Link to comment
Share on other sites

  • Moderators

mrstinky,

Welcome to the AutoIt forum. :)

You are setting $hdslet to the wrong element of the StringSplit array. [0] is a count - you need [1] to get the letters:

$hds = StringSplit($firstletter, ";")
$hdslet = $hds[1] ; $hds[0] <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$hdt = $hds[2]
If StringInStr($hdslet, $firstlet) > 1 Then

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

thanks for the welcome :)

and for the blazing fast reply!! i changed the 0 to 1 for the "hdslet" however i still get the output of array0, i changed the username to ghij so it should give output of array1 however i still get the output of array0. any other points?

With kind regards,

Harry

Link to comment
Share on other sites

  • Moderators

mrstinky,

Sorry about that - as the test gave the right answer I assumed that I had fixed it! Never assume- check! :)

Here is a version that does work - take a look at what I changed and ask if you are unsure why I did it:

#include <Array.au3>
#include <String.au3>
$share = "\\sharename\folder"
;we grab the first letter of the username
$username = "9"
$firstlet = StringLeft($username, 1)

Dim $array[2]
$array[0] = "0123456789abcdef;\users0-f\"
$array[1] = "ghijklmnopqrst;\usersg-t\"

; Now loop through the array to check for out leading letter
For $i = 0 To 1
    $hds = StringSplit($array[$i], ";")
    $hdslet = $hds[1] ; This is the letters
    $hdt = $hds[2] ; this is the folder
    ; Now see if out leading letter is in the list for this element
    If StringInStr($hdslet, $firstlet) > 0 Then ; You had >1 so it missed the first letter
        $hd = $share & $hdt & $username & @CRLF
        ExitLoop
    EndIf

Next

; Check we actually matched something
If $i = 2 Then
    MsgBox(0, "Ooops", "Not found")
Else
    MsgBox(0, "testing", "Result is: " & $hd)
EndIf

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...