Jump to content
Sign in to follow this  
grimmlock

Array pipe character used for next line

Recommended Posts

grimmlock

I am making an app that will allow the migration of users from one server to another (while changing permissions) easier for anyone and everyone. Below is my code, what I can't seem to figure out is what I am missing in my code so that the _uArray() reads the folder names in the destination folder and then uses them to set some of the permissions settings.

Right now the array pulls the data just fine, but either puts a "|" between the names (which I understand is "normal") or it removes the "|" and puts the folder names together in one long string, which is why I used StringSplit() only now it does not display anything at all.

If anyone has time, would it be possible for someone to look at this and help me solve this issue. I think it would a great app that anyone can use that, like me, needs to migrate users across domains or servers. Thank you in advance.

 
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <FileConstants.au3>
#include <ButtonConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <StringConstants.au3>

Global $set = 3

;==========================Main GUI===========================
$hGUI = GUICreate("Complex-Permissions", 250, 350)
;=============================================================

;==========================Inputs=============================
$hOld = GUICtrlCreateInput("", 95, 25, 130)
$hNew = GUICtrlCreateInput("", 95, 50, 130)
$hOldSvr1 = GUICtrlCreateInput("", 95, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr2 = GUICtrlCreateInput("", 130, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr3 = GUICtrlCreateInput("", 165, 75, 25)
GUICtrlSetLimit(-1, $set)
$hOldSvr4 = GUICtrlCreateInput("", 200, 75, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr1 = GUICtrlCreateInput("", 95, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr2 = GUICtrlCreateInput("", 130, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr3 = GUICtrlCreateInput("", 165, 100, 25)
GUICtrlSetLimit(-1, $set)
$hNewSvr4 = GUICtrlCreateInput("", 200, 100, 25)
GUICtrlSetLimit(-1, $set)
$hLetter = GUICtrlCreateInput("", 95, 125, 130)
$hShare = GUICtrlCreateInput("", 95, 150, 130)
$hLocal = GUICtrlCreateInput("", 95, 175, 130)
$hFolder = GUICtrlCreateInput("", 95, 200, 130)
$hUID = GUICtrlCreateInput("", 95, 225, 130)
$hExclude = GUICtrlCreateInput("", 95, 250, 130)
;=============================================================

;==========================Buttons============================
$hButton1 = GUICtrlCreateButton("Test", 25, 285, 50)
;~ GUICtrlSetState(-1, $GUI_HIDE)
$hButton2 = GUICtrlCreateButton("Migrate Data / " & @CRLF & "Change Permissions", 100, 285, 120, 50, $BS_MULTILINE)
;=============================================================

;==========================Labels=============================
$hLabel1 = GUICtrlCreateLabel("Old Domain", 10, 28)
$hLabel2 = GUICtrlCreateLabel("New Domain", 10, 53)
$hLabel3 = GUICtrlCreateLabel("Old Server (IP)", 10, 78)
$hLabel4 = GUICtrlCreateLabel("New Server (IP)", 10, 103)
$hLabel5 = GUICtrlCreateLabel("Drive Letter", 10, 128)
$hLabel5 = GUICtrlCreateLabel("Share Folder", 10, 153)
$hLabel6 = GUICtrlCreateLabel("Local Folder", 10, 178)
$hLabel7 = GUICtrlCreateLabel("Folder Name", 10, 203)
$hLabel8 = GUICtrlCreateLabel("User Name", 10, 228)
$hLabel9 = GUICtrlCreateLabel("Exclusions", 10, 253)
;=============================================================

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMSG()
        Case $GUI_EVENT_CLOSE
            ExitLoop


        Case $hButton1
            _uArray()

        Case $hButton2
;~             _NetUse()
;~             _RoboCopy()
            _Perm()

    EndSwitch

WEnd



;=============================================================
;~                     Functions
;=============================================================

Func _NetUse()
    RunWait(@ComSpec & " /c " & "net use \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\c$ /user:" & GUICtrlRead($hOld) & "\axeontech", "", @SW_HIDE)
    RunWait(@ComSpec & " /c " & "net use \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\Admin$ /user:" & GUICtrlRead($hOld) & "\axeontech", "", @SW_HIDE)
    Sleep(2000)
EndFunc    ;= _NetUse


Func _RoboCopy()
    If GUICtrlRead($hExclude) <> "" then
        RunWait(@ComSpec & " /k " & "robocopy /B \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " \\" & GUICtrlRead($hNewSvr1) & "." & GUICtrlRead($hNewSvr2) & "." & GUICtrlRead($hNewSvr3) & "." & GUICtrlRead($hNewSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " /E /mir /XD " & GUICtrlRead($hFolder) & "\" & GUICtrlRead($hExclude) & "/w:0 /r:0 /log:c:\users\" & @UserName & "\desktop\migrate_profiles.txt", "", @SW_SHOW)
        MsgBox(0, "", "RoboCopy w/ Exceptions: Complete")
    Else
        RunWait(@ComSpec & " /k " & "robocopy /B \\" & GUICtrlRead($hOldSvr1) & "." & GUICtrlRead($hOldSvr2) & "." & GUICtrlRead($hOldSvr3) & "." & GUICtrlRead($hOldSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " \\" & GUICtrlRead($hNewSvr1) & "." & GUICtrlRead($hNewSvr2) & "." & GUICtrlRead($hNewSvr3) & "." & GUICtrlRead($hNewSvr4) & "\" & GUICtrlRead($hShare) & "\" & GUICtrlRead($hFolder) & " /E /mir /w:0 /r:0 /log:c:\users\" & @UserName & "\desktop\migrate_profiles.txt", "", @SW_SHOW)
        MsgBox(0, "", "RoboCopy w/o Exceptions: Complete")
    EndIf

;~     Sleep(2000)
EndFunc    ;= _RoboCopy


Func _Perm()
;~     If GUICtrlRead($hLocal) = "" then
;~         GUICtrlSetData($hLocal, GUICtrlRead($hShare))
;~     EndIf

    Local $hFileOpen = FileOpen("c:\users\" & @UserName & "\desktop\log.txt", $FO_APPEND)

        Local $iPID = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&TAKEOWN /f " & GUICtrlRead($hFolder) & " /r /d y", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID)
            Local $sOutput = StdoutRead($iPID)
            FileWrite($hFileOpen, $sOutput)
;~         Sleep(1000)
        Local $iPID1 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /reset /T", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID1)
            Local $sOutput = StdoutRead($iPID1)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID2 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /inheritance:d /c /t", "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID2)
            Local $sOutput = StdoutRead($iPID2)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID3 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & 'system":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID3)
            Local $sOutput = StdoutRead($iPID3)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID4 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' &  @ComputerName & '\administrator":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID4)
            Local $sOutput = StdoutRead($iPID4)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID5 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' &  @ComputerName & '\administrators":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID5)
            Local $sOutput = StdoutRead($iPID5)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID6 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & GUICtrlRead($hNew) & '\domain admins":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID6)
            Local $sOutput = StdoutRead($iPID6)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID7 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /grant " & '"' & GUICtrlRead($hNew) & '\' & GUICtrlRead($hUID) & '":(OI)(CI)F /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID7)
            Local $sOutput = StdoutRead($iPID7)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID8 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & " /setowner " & '"' & GUICtrlRead($hNew) & '\' & GUICtrlRead($hUID) & '" /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID8)
            Local $sOutput = StdoutRead($iPID8)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID9 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /remove:g " & '"' & 'everyone" /c /t', "", @SW_HIDE, $STDERR_MERGED)
            ProcessWaitClose($iPID9)
            Local $sOutput = StdoutRead($iPID9)
            FileWrite($hFileOpen, $sOutput)
        Local $iPID10 = Run(@ComSpec & " /c " & GUICtrlRead($hLetter) & ":&&cd\" & GUICtrlRead($hLocal) & "&&icacls " & GUICtrlRead($hFolder) & "\*.* /remove:g " & '"' & GUICtrlRead($hNew) & '\axeontech" /c /t', "", @SW_HIDE, $STDERR_MERGED) ;
            ProcessWaitClose($iPID10)
            Local $sOutput = StdoutRead($iPID10)
            FileWrite($hFileOpen, $sOutput)

    FileClose($hFileOpen)
    MsgBox(0, "", "Permissions Change: Complete")

EndFunc    ;= _Perm


Func _uArray()

    $fFileList = _FileListToArray(GUICtrlRead($hLetter) & ":\" & GUICtrlRead($hLocal), "*", 2)
;~     _ArrayDisplay($fFileList, "$fFileList")
    $fFolder = _ArrayToString($fFileList, "|")
    $fSplit = StringSplit($fFolder, "|", $STR_ENTIRESPLIT)
    Run("Notepad")
    Sleep(1000)

For    $i = 1 To $fSplit[0]
    Send($fSplit[$i])

Next

EndFunc
 

Thanks

Grimm

Share this post


Link to post
Share on other sites
Melba23

grimmlock,

As you do not specify precisely, I presume it is this section that is causing you problems:

$fFileList = _FileListToArray(GUICtrlRead($hLetter) & ":\" & GUICtrlRead($hLocal), "*", 2)
;~     _ArrayDisplay($fFileList, "$fFileList")
    $fFolder = _ArrayToString($fFileList, "|")
    $fSplit = StringSplit($fFolder, "|", $STR_ENTIRESPLIT)
    Run("Notepad")
    Sleep(1000)

For    $i = 1 To $fSplit[0]
    Send($fSplit[$i])

Next
Firstly, the code is working exactly as the Help file describes. If you want to Send the result to Notepad as separate lines then you need to add a line delimiter like this: :)

Send($fSplit[$i] & @CR)
But better still would be to convert the array directly into a string containing the line delimiter and then send it in one: ;)

$fFolder = _ArrayToString($fFileList, @CR)
Run("Notepad")
Sleep(1000)
Send($fFolder)
All clear? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
grimmlock

Very clear thank you for the help and explination, as always I am humbled :bye:

But now the hard part for me, I need to somehow take the data from the array and use it set some of the variables :sweating:.


Thanks

Grimm

Share this post


Link to post
Share on other sites
Melba23

grimmlock,

As always, glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello Members of this best Forum
      i have a question please
      for example if i have a long string
      and i want to extract a text between two tag
      what i can do to make that?
      note :
      i know that there is a
      StringRegExp function
      it's do that work
      but it result is be as an array
      i want the result to be a string
      is there any function on autoit can do that?
      Thanks in advance.
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      First, I want to apologize with you for the title not very clear, but I thought a little bit on which title to set at the thread, and this is the one that came in mind.
      Now, let me explain what I'm trying to understand.

      I am making an application ( with n clients ), with an SQLite Database, which has a Main form, and n sub-forms... 
      Since these sub-forms are called several times, because they are used to add or update records to the Database, I put the code that generates the GUI of these sub-forms in Functions.
      There are two sub-forms which are "treated" as two main forms, since even them have n sub-forms, which perform various tasks.
      Where am I stucked?

      For the Main form I created a Status Bar, in order to display messages ( add/delete/update/search results ), and it works perfectly with all the forms which don't have other sub-forms.
      For the two forms, which indeed have n sub-forms, I created two separated Status Bars, which are (re)created everytime I call the function that then displays the form.
      Practically, I can't set icons to these two Status Bars, and I don't know why.
      I'm really sorry that I don't feel clear enough, so, here you are an example of what I am saying.
      I recreated exactly what my script does:
      #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $frmSubForm, _ $txtSubFormField, _ $sbSubFormStatusBar, _ $objSB_IconError = _WinAPI_LoadShell32Icon(109), _ $objSB_IconInformation = _WinAPI_LoadShell32Icon(277) #Region ### START Koda GUI section ### Form= $frmMainForm = GUICreate("Main Form", 300, 300, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "ExitApplication") $sbMainStatusBar = _GUICtrlStatusBar_Create($frmMainForm) $btnCreateSubForm = GUICtrlCreateButton("Create Sub Form", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "GenerateSubForm") GUICtrlSetFont(-1, 10, 400, 0, "Arial") _GUICtrlStatusBar_SetSimple($sbMainStatusBar) _GUICtrlStatusBar_SetText($sbMainStatusBar, "") GUISetState(@SW_SHOW, $frmMainForm) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func ExitApplication() Exit EndFunc Func GenerateSubForm() #Region ### START Koda GUI section ### Form= $frmSubForm = GUICreate("Sub-Form", 300, 300, -1, -1, -1, -1, $frmMainForm) GUISetOnEvent($GUI_EVENT_CLOSE, "DeleteSubForm") $txtSubFormField = GUICtrlCreateInput("", 0, 0, 100, 20) $btnCheckSubFormField = GUICtrlCreateButton("Check Field", 105, 110, 75, 41, BitOR($BS_CENTER,$BS_VCENTER,$BS_MULTILINE)) GUICtrlSetOnEvent(-1, "CheckSubFormField") GUICtrlSetFont(-1, 10, 400, 0, "Arial") $sbSubFormStatusBar = _GUICtrlStatusBar_Create($frmSubForm) _GUICtrlStatusBar_SetSimple($sbSubFormStatusBar) _GUICtrlStatusBar_SetText($sbSubFormStatusBar, "") GUISetState(@SW_SHOW, $frmSubForm) GUISetState(@SW_DISABLE, $frmMainForm) #EndRegion ### END Koda GUI section ### EndFunc Func DeleteSubForm() ; Declared Globally => $frmSubForm GUIDelete($frmSubForm) GUISetState(@SW_ENABLE, $frmMainForm) EndFunc Func WriteToStatusBar($sbStatusBar, $objSB_Icon, $strText) _GUICtrlStatusBar_SetIcon($sbStatusBar, 0, $objSB_Icon) _GUICtrlStatusBar_SetText($sbStatusBar, $strText) ConsoleWrite("Icon Handle: " & $objSB_Icon & @CRLF) EndFunc Func CheckSubFormField() ; Declared Globally => $txtSubFormField If GUICtrlRead($txtSubFormField) = "" Then ; Declared Globally => $sbStatusBar WriteToStatusBar($sbSubFormStatusBar, $objSB_IconError, "Field NOK.") Else WriteToStatusBar($sbSubFormStatusBar, $objSB_IconInformation, "Field OK.") EndIf EndFunc The text is set, but icon is not.
      Could someone please tell me why?
      Thanks everyone in advance  

      Best Regards.
    • mistersquirrle
      By mistersquirrle
      Hello!
       
      I wrote myself a script to follow Google Maps Polyline encoding steps: https://developers.google.com/maps/documentation/utilities/polylinealgorithm, and that works (although I think that it's a bit janky), but now I'm having issues getting the output.
       
      When I run the script, all the points come out correctly in the console, and even when they're the only things that I log, it displays them fine. However, I'm adding each point into a variable to return all of them at once at the end, fully formatted, and it's only taking the very first point. I can't figure out what I'm doing wrong, as it seems fine.
       
      When run with the default value, it should output this at the end: Custom Polygon: _p~iF~ps|U_ulLnnqC_mqNvxq`@
      But instead I'm just getting this: Custom Polygon: _p~iF
       
      I know that it's reaching the string combination lines because it's logging the data before it (and even if a put log AFTER the $sPolygon &= $aPoints[0], it's logged fine).
       
      Here's my full code (problem is lines ~209 - 234, search "$sPolygon &= $aPoints[1]"):
      #include <Array.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> _PolyGUI() Func _PolyGUI() #Region ### START Koda GUI section ### Form= $hInputGUI = GUICreate("Lat Long encoder", 403, 301, 192, 124) GUISetFont(8, 400, 0, "Consolas") GUICtrlCreateLabel("Input polygon points here, format as:", 8, 8, 263, 19) GUICtrlSetFont(-1, 10, 800, 0, "Consolas") GUICtrlCreateLabel("Lat Long - Single point", 8, 24, 142, 17) GUICtrlCreateLabel("Lat Long, Lat Long, Lat Long - Multiple points", 8, 40, 280, 17) Local $sPoints = GUICtrlCreateEdit("", 8, 64, 385, 201, BitOR($ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetData(-1, "38.5 -120.2, 40.7 -120.95, 43.252 -126.453") GUICtrlSetFont(-1, 10, 400, 0, "Consolas") $bOK = GUICtrlCreateButton("bOK", 16, 272, 123, 25) GUICtrlSetFont(-1, 12, 800, 0, "Consolas") $bCancel = GUICtrlCreateButton("bCancel", 304, 272, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Consolas") GUISetState(@SW_SHOW, $hInputGUI) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bCancel Exit Case $bOK $sPoints = GUICtrlRead($sPoints) GUISetState(@SW_HIDE, $hInputGUI) _GetPoly($sPoints, True) ExitLoop EndSwitch Sleep(10) WEnd EndFunc ;==>_PolyGUI ;https://developers.google.com/maps/documentation/utilities/polylinealgorithm ;https://app.dsmobileidx.com/api/DescribeSearchForLinkId?linkId=469787 ; Note that this will only really work inside the US (this side of the World), as it's assuming any negative is the Longitude ;https://gist.github.com/ismaels/6636986 - decoder ;Using: 41.83162 -87.64696 ; Expected: sfi~F np}uO ; Actual: sfi~f np}uo ; If we remove 32 from the last ASCII code, since the last bit chunk is 0, we get the correct case/ characters ; We need to run this logic back through all the indexes though and do this to all that that <= 63 ;LinkId=469787 ; Expected: q{`aHpa_iVi[kp@}`Aa{@e[eCoqBbAyc@iRy{@g_@mz@|gA{eAh~@Vf~Etv@gB~p@gQ`^yg@~p@ekAldA{KfFxIrJ^pO~Mtl@dPrJnUz[nSpo@wf@fc@yw@n@ob@ ; Actual: s{`aHpa_iVg[kp@}`Aa{@g[gCmqBbA{c@iRy{@e_@kz@|gA{eAh~@Td~Evv@gB|p@gQb^wg@|p@ekAndA{KfFvIpJ`@rO~Mrl@dPrJnU|[lSpo@wf@dc@yw@n@mb@ ; I assume that this is because of bad data, the points have repeating 9's and 0's, which looks fishy. The polygon is (very) close, but not quite the same. Func _GetPoly($sPoints, $bLog = False) Local $timer = TimerInit(), $sConsole[11] Local $sPolygon = "" ; Step 1, take the initial signed value: Local $aCoords = StringRegExp($sPoints, "(-*?\d*\.\d*) (-*?\d*\.\d*)", 3), $aPoints[2] ;~ _ArrayDisplay($aCoords) If $bLog Then _Log(_ArrayToString($aCoords)) For $c = 0 To (UBound($aCoords) - 1) Step 2 ;~ If $bLog Then _Log($c) If $c = 0 Then $aPoints[0] = $aCoords[$c] $aPoints[1] = $aCoords[$c + 1] Else $aPoints[0] = $aCoords[$c] - $aCoords[$c - 2] $aPoints[1] = $aCoords[$c + 1] - $aCoords[$c - 1] EndIf If $bLog Then _Log("- Step 1, take the initial signed value:") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 2, multiply each by 1e5, and round $aPoints[0] = Round($aPoints[0] * 1e5, 0) $aPoints[1] = Round($aPoints[1] * 1e5, 0) If $bLog Then _Log("- Step 2, multiply each by 1e5, and round") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 3, convert Decimal to Binary, using two's complement for negatives. Padded to 32 bits $aPoints[0] = _NumberToBinary($aPoints[0]) $aPoints[1] = _NumberToBinary($aPoints[1]) If $bLog Then _Log("- Step 3, convert Decimal to Binary, using two's complement for negatives. Padded to 32 bits") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 4, left-shifted 1 bit $aPoints[0] = StringTrimLeft($aPoints[0], 1) & "0" $aPoints[1] = StringTrimLeft($aPoints[1], 1) & "0" If $bLog Then _Log("- Step 4, left-shifted 1 bit") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf ; Step 5, if negative, invert binary If $c = 0 Then If $aCoords[$c] < 0 Then $aPoints[0] = _InvertBinary($aPoints[0]) If $aCoords[$c + 1] < 0 Then $aPoints[1] = _InvertBinary($aPoints[1]) Else If $aCoords[$c] - $aCoords[$c - 2] < 0 Then $aPoints[0] = _InvertBinary($aPoints[0]) If $aCoords[$c + 1] - $aCoords[$c - 1] < 0 Then $aPoints[1] = _InvertBinary($aPoints[1]) EndIf If $bLog Then _Log("- Step 5, if negative, invert binary") _Log(" " & $aPoints[0]) _Log(" " & $aPoints[1]) EndIf Local $aChunks[2][6], $0x20 For $i = 0 To 1 $0x20 = "1" ; This is out BitOR flag, 0x20 BitOR'd onto our 5-bit chunks is always 1*****, except the last chunk $sConsole[5] = "" ; Clearing console variables $sConsole[6] = "" $sConsole[7] = "" $sConsole[8] = "" $sConsole[9] = "" For $j = 0 To 5 ;There will always be 6 chunks ; Step 6 & 7, break into 5-bit chunks, and reverse order $aChunks[$i][$j] = StringTrimLeft($aPoints[$i], StringLen($aPoints[$i]) - 5) ; This splits into 5-bit chunks in reverse order, doing 6 & 7 in one operation ;~ If $bLog Then _Log(" " & $aPoints[$i]) ;~ If $bLog Then _Log(" " & StringLen($aPoints[$i])) ;~ If $bLog Then _Log(" " & StringTrimLeft($aPoints[$i], StringLen($aPoints[$i]) - 5)) ;~ If $bLog Then _Log(" " & $aChunks[$i][$j]) ; Here we consume the original binary string, so the next loop gets the correct next 5-bit chunk $aPoints[$i] = StringTrimRight($aPoints[$i], 5) $sConsole[5] &= $aChunks[$i][$j] & " " ; Once consumed, if the remaining length isn't enough for another bit chunk, switch 0x20 to 0 (no following chunks) If StringLen($aPoints[$i]) <= 5 Then $0x20 = "0" ; Step 8, BitOR 100000 (0x20) to our 5-bit chunks (effectively) $aChunks[$i][$j] = $0x20 & $aChunks[$i][$j] $sConsole[7] &= $aChunks[$i][$j] & " " ; Step 9, converting the chunk from Binary back to Decimal $aChunks[$i][$j] = _BinaryToDec($aChunks[$i][$j]) $sConsole[8] &= $aChunks[$i][$j] & " " ; Step 10, adding 63 to decimal values $aChunks[$i][$j] += 63 $sConsole[9] &= $aChunks[$i][$j] & " " If StringLen($aPoints[$i]) < 5 Then ExitLoop Next If $bLog Then _Log("- Step 6 & 7 (part " & $i & "), break into 5-bit chunks, and reverse order") _Log(" " & $sConsole[5]) _Log("- Step 8 (part " & $i & "), BitOR 100000 (0x20) to our 5-bit chunks (effectively)") _Log(" " & $sConsole[7]) _Log("- Step 9 (part " & $i & "), converting the chunk from Binary back to Decimal") _Log(" " & $sConsole[8]) _Log("- Step 10 (part " & $i & "), adding 63 to decimal values") _Log(" " & $sConsole[9]) EndIf Next Local $aASCII[0] For $i = 0 To 1 Dim $aASCII[0] ; Reset ASCII array For $j = 0 To (UBound($aChunks, 2) - 1) ; For both chunk sets ReDim $aASCII[UBound($aASCII) + 1] ; Add an index for the ASCII array If $aChunks[$i][$j] = "" Or $aChunks[$i][$j] <= 63 Then ; If the chunk is not useful $l = $j For $k = $l To 1 Step -1 If $aChunks[$i][$k] = "" Or $aChunks[$i][$k] <= 63 Or $aASCII[$k] <= 63 Then $aASCII[$k - 1] -= 32 If $aASCII[$k - 1] <= 63 Then _ArrayDelete($aASCII, $k - 1) Else ExitLoop EndIf Next ExitLoop EndIf $aASCII[$j] = Int($aChunks[$i][$j]) Next ;Step 11, convert each value to ASCII equivalent For $k = UBound($aASCII) - 1 To 0 If $aASCII[$k] <= 63 Or $aASCII[$k] = "" Then ReDim $aASCII[UBound($aASCII) - 1] Else ExitLoop EndIf Next $aPoints[$i] = StringFromASCIIArray($aASCII, 0, -1, 0) Next If $bLog Then _Log("- Step 11, convert each value to ASCII equivalent, finished") If $aCoords[$c] <= 0 Then ;@CRLF & " " & If $bLog Then _Log($aPoints[1]) _Log($aPoints[0]) _Log("Next set") EndIf $sPolygon &= $aPoints[1] $sPolygon &= $aPoints[0] Else If $bLog Then _Log($aPoints[0]) _Log($aPoints[1]) _Log("Next set") EndIf $sPolygon &= $aPoints[0] $sPolygon &= $aPoints[1] EndIf Next If $bLog Then _Log("Custom Polygon: " & $sPolygon) _Log(TimerDiff($timer) & @CRLF) EndIf Return $sPolygon EndFunc ;==>_GetPoly Func _NumberToBinary($iNumber) Local $sBinString = "" ; Maximum 32-bit # range is -2147483648 to 2147483647 If $iNumber < -2147483648 Or $iNumber > 2147483647 Then Return SetError(1, 0, "") ; Convert to a 32-bit unsigned integer. We can't work on signed #'s $iUnsignedNumber = BitAND($iNumber, 0x7FFFFFFF) ; Cycle through each bit, shifting to the right until 0 Do $sBinString = BitAND($iUnsignedNumber, 1) & $sBinString $iUnsignedNumber = BitShift($iUnsignedNumber, 1) Until Not $iUnsignedNumber ; Was it a negative #? Put the sign bit on top, and pad the bits that aren't set If $iNumber < 0 Then Return '1' & StringRight("000000000000000000000000000000" & $sBinString, 31) ; Always return 32 bit binaries If StringLen($sBinString) < 32 Then Return StringRight("0000000000000000000000000000000" & $sBinString, 32) Return $sBinString EndFunc ;==>_NumberToBinary Func _BinaryToDec($sBinary) Local Const $aPower[8] = [128, 64, 32, 16, 8, 4, 2, 1] Local $iDec If StringRegExp($sBinary, "[0-1]") Then If StringLen($sBinary) < 8 Then Do $sBinary = "0" & $sBinary Until StringLen($sBinary) = 8 EndIf $aBinary = StringSplit($sBinary, "", 2) For $i = 0 To UBound($aBinary) - 1 ;~ $aBinary[$i] = $aBinary[$i] * $aPower[$i] $iDec += $aBinary[$i] * $aPower[$i] Next Return $iDec Else Return SetError(0, 0, "Not a binary string") EndIf EndFunc ;==>_BinaryToDec Func _InvertBinary($iNumber) ;~ ConsoleWrite(@CRLF & $iNumber) Local $sNumber $aNumber = StringSplit($iNumber, "") For $i = 1 To $aNumber[0] If $aNumber[$i] = 0 Then $aNumber[$i] = 1 ElseIf $aNumber[$i] = 1 Then $aNumber[$i] = 0 Else Return SetError(0, 0, "Not a binary number") EndIf $sNumber &= String($aNumber[$i]) Next Return $sNumber EndFunc ;==>_InvertBinary Func _Log($data) ;~ Local Static $LogEnable = True ConsoleWrite(@CRLF & @HOUR & ":" & @MIN & "." & @SEC & " " & $data) LogData(@HOUR & ":" & @MIN & "." & @SEC & " " & $data, "logs/LOGFILE.txt") EndFunc ;==>_Log Func LogData($text, $File = "logs/LOGFILE.txt") Global $LogFile = "" If $LogFile = "" Then $LogFile = FileOpen($File, 9) OnAutoItExitRegister(CloseLog) EndIf FileWriteLine($LogFile, $text) EndFunc ;==>LogData Func CloseLog() If $LogFile <> "" Then _Log("Closing LoD script" & @CRLF) FileClose($LogFile) EndIf EndFunc ;==>CloseLog  
      I've tried:
      $sPolygon &= $aPoints[0] & $aPoints[1] ;---- $sPolygon = $sPolygon & $aPoints[0] & $aPoints[1] ;---- $sPolygon = $sPolygon & String($aPoints[0] & $aPoints[1]) ;---- $sPolygon = String($sPolygon) & String($aPoints[0]) & String($aPoints[1]) ;---- $sPolygon &= $aPoints[1] $sPolygon &= $aPoints[0] ;----  
      I'm sure it's something basic that I'm overlooking, but I don't understand why it's not combining the strings. 
      Also, unrelated, why doesn't $LogFile = FileOpen($File, 9) create the directory/ file if they don't exist? 9 should be $FO_CREATEPATH (8) + $FO_APPEND (1)?
      Thanks!
    • VollachR
      By VollachR
      Hi,
      I'm looking for a way to take a number value from a Row2 of a 2D array and according to this check if files that appear in rows 3-11 in the array exists.
      For example, if the number in Row2 is 5 I need to check for the files in Row 3-6 only, if it is 6 than rows 3-7 and so on.
      I thought on using a FOR loop but I have very little experience with those.
      Can you suggest the best way to do what I need?
      BTW, the files in Rows 3-11 will usually have blank value for any row above the number in Row2 (e.g. Row2 = 5 so Rows3-6 will have values but 8-11 be empty), The values I need are in Column 1 of the array, the name of the key from the INI file that the array was created from is in Column 0.
      Full Example:
      Row2 of Array:
      Col0 = Games# - Col1 = 5
      Rows3-6
      Col0 = Exe2 - Col1 = Path To File
      Col0 = Exe3 - Col1 = Path To File
      Col0 = Exe4 - Col1 = Path To File
      Col0 = Exe5 - Col1 = Path To File
      I need that if Row2 is 5 to check these above for rows if the file exists, if it was 6 then the next row as well and so on up until number 10 in Row2 as it can't go above 10.
      So basically for whatever number in Row2 from 2-10 need to check 1-9 rows from 3-11 to see if the files in Col1 exists and if any of them don't exist it should call a function that shows an error message.
      I'm pretty sure I have the first line of the for look correct:
      For $i = 1 To $aAIO[2][1] Just not sure how to continue from there, also not sure if $i should be equal 1 or 2.
      Help will be appreciated.
    • FMS
      By FMS
      Hello,
      I'm trying to get data from twitter to an array and so far I found an Twitter UDF whish lookes very intresting but couldn't get it to work.
      It lookes not supported any more(2010) and buggy when i read all te replies.
      More around this subject (autoit and twitter) i couldn't find on this forum.
      Is there sombody who know's a good way to get live data from twitter to an array inside autoit?
      (I kinda doubt that this isn't tackled before)
      In the end I was hoping to get all tweets from date to date from an specific subject inside a 2D array to work whit.
×