mrstinky Posted February 17, 2011 Share Posted February 17, 2011 (edited) 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 February 17, 2011 by mrstinky Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2011 Moderators Share Posted February 17, 2011 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 ThenAll clear? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mrstinky Posted February 17, 2011 Author Share Posted February 17, 2011 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 More sharing options...
hannes08 Posted February 17, 2011 Share Posted February 17, 2011 Hi mrstinky, just put the "ExitLoop" in your conditional statement: If StringInstr($hdslet,$firstlet) > 1 then $hd = $share & $hdt & $username & @CRLF ExitLoop EndIf That should do the trick. Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 17, 2011 Moderators Share Posted February 17, 2011 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mrstinky Posted February 17, 2011 Author Share Posted February 17, 2011 great stuff and explanation guys, well apreciated! it works now i can make it a bit more complex as we have a lot of user folders Cheers!! Kind regards, Harry Link to comment Share on other sites More sharing options...
hannes08 Posted February 17, 2011 Share Posted February 17, 2011 Hey mrstinky, You're welcome. Regards, Hannes Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now