Jump to content

AlwaysLearning

Members
  • Posts

    11
  • Joined

  • Last visited

Recent Profile Visitors

173 profile views

AlwaysLearning's Achievements

  1. Water, Unfortunately, reversing the order of the input data isn't an option. In your example, you have fixed my issue by reversing the order of data inputted in column H (it is in ascending order which will of course work as expected -- that is the default operating mode). However, my data comes from a live array fed in by an API in DESCENDING order. I realize I could add a command to filter this into ascending order in excel, but that would make it very ineffective because the script is expected to cycle 5 times per second or more. Essentially, I need to edit the chart's x-axis plotting order to Descending mode, which is a feature I don't see in the UDF.
  2. Hello Water I will have to extract that portion of the script as there are private API keys involved and the function that executes this chart generation is dependent on several other functions in the script which use these API keys. I can remove this and rebuild it but it will take me some time because I learned as I went making this and didn't manage my code very well. Half my mistakes were fixed with duct taping "if/then" and random variables (once I have everything functioning, I plan to rebuild it with less "workarounds" -- your UDF and others has helped me understand why a quick and sloppy fix can end up costing you time in the long run). For now I am attaching a photo which may be sufficient. Notice on the x-axis that the UNIX timestamps are time passed in seconds since 1970. As such, the most recent time is always the higher number. Excel's plotting order doesn't like this as it goes descending by default. Edit: extracting an example was easier than I thought! Here is the code: #include <String.au3> #include <Array.au3> #include <Inet.au3> #include <Excel.au3> #include <ExcelChart.au3> Global $oExcelProcess = _Excel_Open() ;; ---- Set to false to make invisible Global $iXLC_Debug = 2 ;(or = 1) Global $oExcel = _Excel_BookNew($oExcelProcess) $aChartData = ChartData() #Region Chart Rendering ;; Render chart on first run to save time when refreshing the JPEG for GUI later _XLChart_ScreenUpdateSet($oExcel, 2) _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "Date", "A1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "O", "B1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "H", "C1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "L", "D1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "C", "E1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "P", "G1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "S2", "H1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "S1", "I1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "R2", "J1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "R1", "K1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, $aChartData, "A2") $Graph_position = "B8:K32" $XValueRange = "=Sheet1!R2C1:R6C1" Local $DataRange[5] = [4, "=Sheet1!R2C2:R6C2", "=Sheet1!R2C3:R6C3", "=Sheet1!R2C4:R6C4","=Sheet1!R2C5:R6C5"] Local $DataName[5] = [4, "=Sheet1!B1", "=Sheet1!C1", "=Sheet1!D1", "=Sheet1!E1"] Local $iWorksheet = 1 Global $oChart1 = _XLChart_ChartCreate($oExcel, $iWorksheet, $xlStockOHLC, $Graph_position, "", $XValueRange, $DataRange, $DataName) ; Format chart _XLChart_LayoutSet($oChart1, Default, 46) _XLChart_FillSet($oChart1.Chartgroups(1).UpBars, -4) ; Set the UpBars to green If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_ChartCreate' on line " & @ScriptLineNumber) _XLChart_FillSet($oChart1.Chartgroups(1).DownBars, -3) ; Set the DownBars to red If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_ChartCreate' on line " & @ScriptLineNumber) _XLChart_ColumnGroupSet($oChart1.ChartGroups(1), 450) ; Make the bars smaller (by making the gap between the bars bigger) If @error Then MsgBox(64, "Excel Chart Example Script", "Error " & @error & " returned by function '_XLChart_ChartCreate' on line " & @ScriptLineNumber) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ;_XLChart_FillSet($oChart1.ChartArea, 0xF0F0F0) ;If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Add a data series for P _XLChart_SeriesAdd($oChart1, $XValueRange, "=Sheet1!R2C7:R" & (6) & "C7", "=Sheet1!G1") If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Line with markers _XLChart_SeriesSet($oChart1.SeriesCollection(5), $xlLineMarkers) ; Set the size and the type of markers _XLChart_MarkerSet($oChart1.SeriesCollection(5), 7, $xlMarkerStyleDiamond, default, 0x0057e7) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Set data labels to display the value _XLChart_DatalabelSet($oChart1.SeriesCollection(5)) ; Set the size of the values _XLChart_FontSet($oChart1.SeriesCollection(5).Datalabels, Default, 8) ; Set data line to invisible _XLChart_LineSet($oChart1.SeriesCollection(5), Default, Default, False, Default, Default, $xlSheetHidden) ; Add a data series for S2 _XLChart_SeriesAdd($oChart1, $XValueRange, "=Sheet1!R2C8:R" & (6) & "C8", "=Sheet1!H1") If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Line with markers _XLChart_SeriesSet($oChart1.SeriesCollection(6), $xlLineMarkers) ; Set the size and the type of markers _XLChart_MarkerSet($oChart1.SeriesCollection(6), 10, $xlMarkerStyleDash, Default, 0xC80014) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Set data labels to display the value _XLChart_DatalabelSet($oChart1.SeriesCollection(6)) ; Set the size of the values _XLChart_FontSet($oChart1.SeriesCollection(6).Datalabels, Default, 8) ; Set data line to invisible _XLChart_LineSet($oChart1.SeriesCollection(6), Default, Default, False, Default, Default, $xlSheetHidden) ; Add a data series for S1 _XLChart_SeriesAdd($oChart1, $XValueRange, "=Sheet1!R2C9:R" & (6) & "C9", "=Sheet1!I1") If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Line with markers _XLChart_SeriesSet($oChart1.SeriesCollection(7), $xlLineMarkers) ; Set the size and the type of markers _XLChart_MarkerSet($oChart1.SeriesCollection(7), 10, $xlMarkerStyleDot, Default, 0xDE6672) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Set data labels to display the value _XLChart_DatalabelSet($oChart1.SeriesCollection(7)) ; Set the size of the values _XLChart_FontSet($oChart1.SeriesCollection(7).Datalabels, Default, 8) ; Set data line to invisible _XLChart_LineSet($oChart1.SeriesCollection(7), Default, Default, False, Default, Default, $xlSheetHidden) ; Add a data series for R2 _XLChart_SeriesAdd($oChart1, $XValueRange, "=Sheet1!R2C10:R" & (6) & "C10", "=Sheet1!J1") If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Line with markers _XLChart_SeriesSet($oChart1.SeriesCollection(8), $xlLineMarkers) ; Set the size and the type of markers _XLChart_MarkerSet($oChart1.SeriesCollection(8), 10, $xlMarkerStyleDash, Default, 0x78c800) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Set data labels to display the value _XLChart_DatalabelSet($oChart1.SeriesCollection(8)) ; Set the size of the values _XLChart_FontSet($oChart1.SeriesCollection(8).Datalabels, Default, 8) ; Set data line to invisible _XLChart_LineSet($oChart1.SeriesCollection(8), Default, Default, False, Default, Default, $xlSheetHidden) ; Add a data series for R1 _XLChart_SeriesAdd($oChart1, $XValueRange, "=Sheet1!R2C11:R" & (6) & "C11", "=Sheet1!K1") If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Line with markers _XLChart_SeriesSet($oChart1.SeriesCollection(9), $xlLineMarkers) ; Set the size and the type of markers _XLChart_MarkerSet($oChart1.SeriesCollection(9), 10, $xlMarkerStyleDot, Default, 0xc9e999) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ; Set data labels to display the value _XLChart_DatalabelSet($oChart1.SeriesCollection(9)) ; Set the size of the values _XLChart_FontSet($oChart1.SeriesCollection(9).Datalabels, Default, 8) ; Set data line to invisible _XLChart_LineSet($oChart1.SeriesCollection(9), Default, Default, False, Default, Default, $xlSheetHidden) ; Align primary and secondary Y-axis _XLChart_AxisSet($oChart1.Axes($xlValue, 2), $oChart1.Axes($xlValue).MinimumScale, $oChart1.Axes($xlValue).MaximumScale) ; Delete the secondary Y-axis _XLChart_ObjectDelete($oChart1.Axes($xlValue, 2)) ; Enable Screen updating _XLChart_ScreenUpdateSet($oExcel, 1) ; get the values for the Y-axis ;MsgBox(0, "Y-axis minimum value", $oChart1.Axes($xlValue).MinimumScale) ;MsgBox(0, "Y-axis maximum value", $oChart1.Axes($xlValue).MaximumScale) ; Save chart as PNG Local $iFile = @ScriptDir & "\chart.jpg" _XLChart_ChartExport($oChart1, $iFile, "JPEG", False, True) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) #EndRegion While 1 $aChartData = ChartData() GUIGraph($aChartData) Sleep ( 10 ) WEnd Func ChartData($sParameters = '') ; ChartData -- Time, Open, High, Low, Close, Volume =========> $sChartData = _INetGetSource("https://coincheck.com/api/charts/candle_rates?limit=20&market=coincheck&pair=btc_jpy&unit=900&v2=true") $sChartData = StringTrimLeft($sChartData, 2) $sChartData = StringTrimRight($sChartData, 2) $sChartData = StringReplace($sChartData, '],[', @LF) $sChartData = StringReplace($sChartData, ',', " ") $aChartData = _VarTo2D($sChartData) ReDim $aChartData[UBound($aChartData)][UBound($aChartData, 2) + 5] ;; === Pivot Point $tot = 0 For $i = 0 To UBound($aChartData) - 1 ; Row by row For $j = 1 To 4 ; Column by column $tot += $aChartData[$i][$j] ; 1 * current cell = tot, then tot * next cell Next $tot = Round(($tot / 4), 0) $aChartData[$i][UBound($aChartData, 2) - 5] = $tot ; write the final total $tot = 0 ;reset and move to next row Next ;; === S1=P-(H-L) For $i = 0 To UBound($aChartData) - 1 ; Row by row Local $p = $aChartData[$i][UBound($aChartData, 2) - 5] Local $h = $aChartData[$i][2] Local $l = $aChartData[$i][3] $aChartData[$i][UBound($aChartData, 2) - 4] = $p - ($h - $l) Next ;; === S2= P + 2×P-H For $i = 0 To UBound($aChartData) - 1 ; Row by row Local $p = $aChartData[$i][UBound($aChartData, 2) - 5] Local $h = $aChartData[$i][2] Local $l = $aChartData[$i][3] $aChartData[$i][UBound($aChartData, 2) - 3] = $p - (2 * ($h - $p)) Next ;; === R1 For $i = 0 To UBound($aChartData) - 1 ; Row by row Local $p = $aChartData[$i][UBound($aChartData, 2) - 5] Local $h = $aChartData[$i][2] Local $l = $aChartData[$i][3] $aChartData[$i][UBound($aChartData, 2) - 2] = $p + (2 * ($p - $l)) Next ;; === R2 For $i = 0 To UBound($aChartData) - 1 ; Row by row Local $p = $aChartData[$i][UBound($aChartData, 2) - 5] Local $h = $aChartData[$i][2] Local $l = $aChartData[$i][3] $aChartData[$i][UBound($aChartData, 2) - 1] = $p + ($h - $l) Next ;_ArrayDisplay($aChartData) Return $aChartData EndFunc ;==>ChartData Func GUIGraph($aChartData) ; Disable Screen updating (forced even when debugging is activated) _XLChart_ScreenUpdateSet($oExcel, 2) _Excel_RangeWrite($oExcel, $oExcel.Activesheet, "Date", "A1") _Excel_RangeWrite($oExcel, $oExcel.Activesheet, $aChartData, "A2") ; Align primary and secondary Y-axis _XLChart_AxisSet($oChart1.Axes($xlValue, 2), $oChart1.Axes($xlValue).MinimumScale, $oChart1.Axes($xlValue).MaximumScale) ; Delete the secondary Y-axis _XLChart_ObjectDelete($oChart1.Axes($xlValue, 2)) ; Enable Screen updating _XLChart_ScreenUpdateSet($oExcel, 1) ; get the values for the Y-axis ;MsgBox(0, "Y-axis minimum value", $oChart1.Axes($xlValue).MinimumScale) ;MsgBox(0, "Y-axis maximum value", $oChart1.Axes($xlValue).MaximumScale) ; Save chart as JPEG ===> The GUI part is commented out because my GUI code isn't necessary here. _XLChart_ChartExport($oChart1, @ScriptDir & "\chart.jpg", "JPEG", False, True) If @error Then ConsoleWrite("Line number: " & @ScriptLineNumber & " - Error: " & @error & @CR) ;GUICtrlSetImage($ChartImage, @ScriptDir & "\chart.jpg") Return EndFunc ;==>Example Func _VarTo2D($var, $sSeparator = " ") Local $aRows = StringSplit(StringStripCR($var), @LF), $aColumns, $aResult[$aRows[0]][1] For $iRow = 1 To $aRows[0] $aColumns = StringSplit($aRows[$iRow], $sSeparator) If $aColumns[0] > UBound($aResult, 2) Then ReDim $aResult[$aRows[0]][$aColumns[0]] For $iColumn = 1 To $aColumns[0] $aResult[$iRow - 1][$iColumn - 1] = $aColumns[$iColumn] Next Next Return $aResult EndFunc ;==>_VarTo2D Since we have the code there, one more issue I had was trying to change the GraphPosition based on Ubound($aChartData). I actually wanted to change the Chart Data size by just clicking buttons in my GUI, but this would mean the GraphPosition and Graph Size would depend on the size of $aChartData. While this works and generates the expected Excel Result, all my exported JPEGs/PNGs are 0KB unless I keep the Position of the chart relatively near the top of the spreadsheet.
  3. Hello Water, Hope you are well. I am trying to work with UNIX time on my x-axis and Excel plots it in descending order (when in fact UNIX time is ascending!). Is there anyway to modify the plotting order in your UDF? I don't need example code, just need to know if the option exists and what it is (didn't find it in the UDF files). Edit: The workaround I am using is to multiply the unix time value by -1... but that looks ugly and is a recipe for disaster by "best practice"
  4. Hello, I have been struggling with this for nearly 20 hours, and I just cannot seem to figure out the formatting for the header request. To test this, you will need to use this api key I set up for your testing purposes. (note, I sent tracexx a direct message about this as I didn't realize I could limit API restrictions until just now, so I am now hoping on of you may have the answer on hand) I need to be able to GET balance and POST orders. Right now, I can't get past the 401/403 errors on my own. I believe the Content is formatted for JSON, but using the JSON format didn't work for me ( although that may be because I'm an idiot and formatted something wrong). I want to get: GET balance page POST delete order page Here is a temporary API key + Secret API key with only the "View Balance Page" and "Delete Order" functions enabled: Access-key: tq6GeUrEvfxyF-LG Secret Access-Key: cZlz75K1wb8-Ed67pRaXvUWTPW6RTH9q Here is the site's API guide (I followed this closely and doubt the error is there): https://coincheck.com/documents/exchange/api#libraries And here is running source code (needs those keys inputted) which will hash the above keys to the required HMAC SHA256: #include <Crypt.au3> #include<WinHttp.au3> Global Const $CALG_SHA_256 = 0x0000800c ;; ===== $api = "/api/accounts/balance" $accessNonCE = _TimeGetStamp() $url = "https://coincheck.com/api/accounts/balance" $body = "" WinHTTP($url, $body) Func WinHTTP($sUrl, $sBody) Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "https://coincheck.com/api/accounts/balance") ; Specify the reguest: ;Local $hRequest = _WinHttpOpenRequest($hConnect, Default, $sApi) $accessKey = "" ;; Add the key from above $secretKey = "" ;; Add the secret key from above $message = $accessNonCE & $sUrl $BinarySignature = HMAC($secretKey, $message) $signature = _Base64Encode($BinarySignature) ;Encode signature Local $hRequest = _WinHttpOpenRequest($hConnect, "GET") _WinHttpAddRequestHeaders($hRequest, 'ACCESS-KEY: '&$accessKey) _WinHttpAddRequestHeaders($hRequest, 'ACCESS-NONCE: '&$accessNonCE) _WinHttpAddRequestHeaders($hRequest, 'ACCESS-SIGNATURE: '&$signature) ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Local $sHeader = _WinHttpQueryHeaders($hRequest) ; ...get full header Local $sData = _WinHttpReadData($hRequest) ; Clean _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ; Display retrieved data MsgBox(0, "Data", $sData) EndFunc Func sha256($message) Return _Crypt_HashData($message, $CALG_SHA_256) EndFunc Func HMAC($key, $message, $hash="sha256") Local $blocksize = 64 Local $a_opad[$blocksize], $a_ipad[$blocksize] Local Const $oconst = 0x5C, $iconst = 0x36 Local $opad = Binary(''), $ipad = Binary('') $key = Binary($key) If BinaryLen($key) > $blocksize Then $key = Call($hash, $key) For $i = 1 To BinaryLen($key) $a_ipad[$i-1] = Number(BinaryMid($key, $i, 1)) $a_opad[$i-1] = Number(BinaryMid($key, $i, 1)) Next For $i = 0 To $blocksize - 1 $a_opad[$i] = BitXOR($a_opad[$i], $oconst) $a_ipad[$i] = BitXOR($a_ipad[$i], $iconst) Next For $i = 0 To $blocksize - 1 $ipad &= Binary('0x' & Hex($a_ipad[$i],2)) $opad &= Binary('0x' & Hex($a_opad[$i],2)) Next Return Call($hash, $opad & Call($hash, $ipad & Binary($message))) EndFunc Func _TimeGetStamp() Local $av_Time $av_Time = DllCall('CrtDll.dll', 'long:cdecl', 'time', 'ptr', 0) If @error Then SetError(99) Return False EndIf Return $av_Time[0] EndFunc Func _Base64Encode($input) $input = Binary($input) Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]") DllStructSetData($struct, 1, $input) Local $strc = DllStructCreate("int") Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _ "ptr", DllStructGetPtr($struct), _ "int", DllStructGetSize($struct), _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($strc)) If @error Or Not $a_Call[0] Then Return SetError(2, 0, ""); error encoding EndIf Return DllStructGetData($a, 1) EndFunc ;==>_Base64Encode
  5. That would be a good idea. I'm totally new here and didn't know the etiquette. I'll be more careful next time :-) Here is the fixed code: Global $cmarr[10] Global $cmmode = False Global $hkt = TimerInit() Global $hktd = TimerInit() Global $override Global $cmpressable ;; Many of these variables don't need to be Global, but I set it this way to help simplify debugging. HotKeySet ("{1}", "HotKey1") HotKeySet ("{2}", "HotKey2") HotKeySet ("{3}", "HotKey3") HotKeySet ("{4}", "HotKey4") HotKeySet ("{5}", "HotKey5") HotKeySet ("{6}", "HotKey6") HotKeySet ("{7}", "HotKey7") HotKeySet ("{8}", "HotKey8") HotKeySet ("{9}", "HotKey9") HotKeySet ("{0}", "HotKey0") HotKeySet ("{-}", "HotKey11") HotKeySet ("{=}", "HotKey12") While 1 = 1 $hktd = TimerDiff($hkt) ;; Check how much time has passed since the last time the mode was toggled (prevents this script from running before the native applications UI has a chance to display the thumbnail on the screen) If $hktd >= 500 Then $override = False ;; It is now OK for this portion of the script to look at the thumbnail bar and change the mode if necessary. This is here because sometimes the HotKey function will interrupt the For...Next loop below. If that happens, I need the script to know not to make any changes on its own after it goes back from finishing the HotKey function continues where it left off in its looping process. For $cm = 0 to UBound($cmarr) - 1 $cmpressable = PixelGetColor(1290, 876) ;; Check if mode can be changed (Hotkeys 1-3 have a 5 second loading window on occassion, so this variable is necessary to make sure the current task has finished) $xposition = 600 + ($cm * 25) ;; This is for scanning the thumbnail bar. $cmarr[$cm] = PixelGetColor($xposition, 55) ;; check the pixel at location If $cmarr[$cm] = 15636838 And $override = False Then $cmmode = True ExitLoop ElseIf $override = False and $cm = UBound($cmarr) - 1 Then ;; THIS was the problem. I needed to make sure this line only runs on the LAST round going through this loop. Otherwise, my results would be somehting like "False, False, True, False, False, False". The True in the middle was overwritten by a "False" result in the subsequent loops) $cmmode = False EndIf Next EndIf WEnd Func HotKey1() HotKeySet ("{1}") $hktd = TimerDiff($hkt) $cmpressable = PixelGetColor(1290, 876) ;; buttons 1-3 need to check if the option to toggled is available or not If $cmmode = True and $cmpressable = 9013641 Then $hkt = TimerInit() $override = True $cmmode = False Send ("9") Else Send ("{1}") EndIf HotKeySet ("{1}", "HotKey1") EndFunc Func HotKey2() HotKeySet ("{2}") $hktd = TimerDiff($hkt) $cmpressable = PixelGetColor(1290, 876) ;; buttons 1-3 need to check if the option to toggled is available or not If $cmmode = True and $cmpressable = 9013641 Then $hkt = TimerInit() $override = True $cmmode = False Send ("9") Else Send ("2") EndIf HotKeySet ("{2}", "HotKey2") EndFunc Func HotKey3() HotKeySet ("{3}") $hktd = TimerDiff($hkt) $cmpressable = PixelGetColor(1290, 876) ;; buttons 1-3 need to check if the option to toggled is available or not If $cmmode = True and $cmpressable = 9013641 Then $hkt = TimerInit() $override = True $cmmode = False Send ("9") Else Send ("3") EndIf HotKeySet ("{3}", "HotKey3") EndFunc Func HotKey4() HotKeySet ("{4}") If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("4") EndIf HotKeySet ("{4}", "HotKey4") EndFunc Func HotKey5() HotKeySet ("{5}") ;If $cmmode = False Then ; $override = True ; $cmmode = True ; Send ("9") ; $hkt = TimerInit() ;Else ; Send ("5") ;EndIf Send ("5") HotKeySet ("{5}", "HotKey5") EndFunc Func HotKey6() HotKeySet ("{6}") If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("6") EndIf HotKeySet ("{6}", "HotKey6") EndFunc Func HotKey7() HotKeySet ("{7}") $hktd = TimerDiff($hkt) If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Sleep ( 600 ) Send ("{7}") Else Send ("7") EndIf HotKeySet ("{7}", "HotKey7") EndFunc Func HotKey8() HotKeySet ("{8}") $hktd = TimerDiff($hkt) If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("8") EndIf HotKeySet ("{8}", "HotKey8") EndFunc Func HotKey9() HotKeySet ("{9}") Send ("{9}") HotKeySet ("{9}", "HotKey9") EndFunc Func HotKey0() HotKeySet ("{0}") Send ("{0}") HotKeySet ("{0}", "HotKey0") EndFunc Func HotKey11() HotKeySet ("{-}") Send ("{-}") HotKeySet ("{-}", "HotKey11") EndFunc Func HotKey12() HotKeySet ("{=}") Send ("{=}") HotKeySet ("{=}", "HotKey12") EndFunc
  6. I actually managed to fix it while cleaning up my code in the above post. I needed to make sure that it only declares False at the END of the array For...Next loop.
  7. Hello, I'm trying to make a script that checks for a UI element to tell if the correct mode is toggled turned on. The native program's UI displays the status of this mode via a thumbnail. I'm trying to get the script to toggle the mode between true or false, but sometimes it gets messed up when I'm pressing the keys very quickly or switching between functions (calling a function more than once, Send command doesn't send, etc). So I tried to add a self correct function that would scan the thumbnails at the top of the program menu. This would update and self-correct those errors every two seconds or so (in reality I want to do it faster, but two seconds seemed like a safe "test run"). It's simply not working the way I intended, and I've tried so many different approaches. Here is the latest approach: Global $hkt = TimerInit() Global $hktd Global $overide Global $cmarr[10] Global $cmpressable Global $cmmode HotKeySet ("{1}", "HotKey1") HotKeySet ("{2}", "HotKey2") HotKeySet ("{3}", "HotKey3") HotKeySet ("{4}", "HotKey4") HotKeySet ("{5}", "HotKey5") HotKeySet ("{6}", "HotKey6") HotKeySet ("{7}", "HotKey7") HotKeySet ("{8}", "HotKey8") HotKeySet ("{9}", "HotKey9") HotKeySet ("{0}", "HotKey0") HotKeySet ("{-}", "HotKey11") HotKeySet ("{=}", "HotKey12") While 1 = 1 $hktd = TimerDiff($hkt) ;; Yes, I know this is processor intensive. In reality there are some other instructions in the While loop, but for now I'll add a Sleep ( 50 ) at the bottom of loop. If $hktd >= 2000 Then ;; I added these time delays to prevent it from trying to correct the toggle status too often (the program UI takes some time to display which mode it is in). $override = False For $cm = 0 to UBound($cmarr) - 1 $hktd = TimerDiff($hkt) $cmpressable = PixelGetColor(1290, 876) $xposition = 600 + ($cm * 25) $cmarr[$cm] = PixelGetColor($xposition, 55) If $hktd >= 2000 and $cmarr[$cm] = 15636838 and $override = False Then ;; I added these time delays to prevent it from trying to correct the toggle status too often (the program UI takes some time to display which mode it is in). $cmmode = True ;; This seems to cause some trouble when the For...Next loop is sometimes interrupted via HotKeyX() ExitLoop ElseIf $hktd >= 2000 and $override = false and $cm = UBound($cmarr) - 1 Then $cmmode = False ;; This seems to cause some trouble when the For...Next loop is sometimes interrupted via HotKeyX() EndIf Next ;; I also tried doing an _ArraySearch function here after the loop completes, but it's still the same problem. The UI element appeared at $cm[3] while the For... Next loop was searching on $cm[4]+, the For...Next therefore thinks "NOT FOUND, LETS DECLARE IT FALSE", but in reality it showed up with bad timing. EndIf Sleep ( 50 ) ;; Not actually in my script. Just added for this forum post. WEnd Func HotKey1() HotKeySet ("{1}") $hktd = TimerDiff($hkt) If $cmmode = True Then $cmpressable = PixelGetColor(1290, 876) If $cmpressable = 9013641 Then $override = True $cmmode = False Send ("9") $hkt = TimerInit() EndIf EndIf Sleep (250) ;; Just put these sleeps in a few of the calls to see if it improved the functions, it didn't seem to make a difference. Send ("{1}") HotKeySet ("{1}", "HotKey1") EndFunc Func HotKey2() HotKeySet ("{2}") $hktd = TimerDiff($hkt) If $cmmode = True Then $cmpressable = PixelGetColor(1290, 876) If $cmpressable = 9013641 Then $hkt = TimerInit() Send ("9") $override = True $cmmode = False EndIf EndIf Sleep (250) Send ("2") HotKeySet ("{2}", "HotKey2") EndFunc Func HotKey3() HotKeySet ("{3}") $hktd = TimerDiff($hkt) If $cmmode = True Then $cmpressable = PixelGetColor(1290, 876) If $cmpressable = 9013641 Then $hkt = TimerInit() $override = True $cmmode = False Send ("9") EndIf EndIf Sleep (250) Send ("3") HotKeySet ("{3}", "HotKey3") EndFunc Func HotKey4() HotKeySet ("{4}") If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("4") EndIf Sleep (250) Send ("4") HotKeySet ("{4}", "HotKey4") EndFunc Func HotKey5() HotKeySet ("{5}") If $cmmode = True Then $override = True $cmmode = False Send ("9") $hkt = TimerInit() Else Send ("5") EndIf Sleep (250) Send ("5") HotKeySet ("{5}", "HotKey5") EndFunc Func HotKey6() HotKeySet ("{6}") If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("6") MouseMove (840, 435, 0) EndIf Sleep (250) HotKeySet ("{6}", "HotKey6") EndFunc Func HotKey7() HotKeySet ("{7}") $hktd = TimerDiff($hkt) If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("7") EndIf Sleep (250) HotKeySet ("{7}", "HotKey7") EndFunc Func HotKey8() HotKeySet ("{8}") $hktd = TimerDiff($hkt) If $cmmode = False Then $override = True $cmmode = True Send ("9") $hkt = TimerInit() Else Send ("8") EndIf Sleep (250) HotKeySet ("{8}", "HotKey8") EndFunc Func HotKey9() HotKeySet ("{9}") Send ("{9}") HotKeySet ("{9}", "HotKey9") EndFunc Func HotKey0() HotKeySet ("{0}") Send ("{0}") HotKeySet ("{0}", "HotKey0") EndFunc Func HotKey11() HotKeySet ("{-}") Send ("{-}") HotKeySet ("{-}", "HotKey11") EndFunc Func HotKey12() HotKeySet ("{=}") Send ("{=}") HotKeySet ("{=}", "HotKey12") EndFunc
  8. I actually read that before coming here and bothering you good folks. But being new to coding, some of the wording confused and overwhelmed me. I ended up with more questions than answers after reading it, and I probably should have tested a bit more on my own (and will in the future). Thanks. I actually already read a few of those, but reading and FULLY understanding are two very different things. I'll have to go back and reread them more carefully. The learning to script tutorial is especially nice! I hadn't seen that one before and I'm reading it now. Thanks again.
  9. Melba23, I figured it out after looking at your script. The problem was that I didn't understand how to reference/modify data in an array. Now I can see that put simply, when working with a 2D array, the first number in brackets after an array variable ($aArray) is rows, the second number is columns. Everything is treated as an independent variable under the simple tag $aArray. I can edit a cell by just putting $aArray[insert row number starting from 0][insert column number starting from 0] = ___________ In my case, the second column is a straight number so it's as easy as: For $i = 0 to Ubound($aArray) - 1 ; From 0 (first time running this portion of script) to whatever the size of this array is (minus 1), do the following: If $array[$i][0] <> "Valik" Then $array[$i][1] += 1 ; If the data in row [$i] (goes down one by one each time) for column [0] (first column) is NOT "Valik" then add 1 to column [1] (second column) Next ; As stated in the "For" statement, stop looping this section once $i (number of times run) = the size of this 2D array - 1 Please pay special attention to my wording in the comments. That is how I'm understanding each line of code right now. Am I understanding correctly? Do you have any corrections that might help me better describe the logic in plain English? Finally, one question: Why don't I need a line saying $i += 1 inside that "For...Next" statement? Does AutoIt understand by default what I am trying to do with $i in "For...Next" statements? Is that why it is different from a "Do... Until" statement? Thank you for your advice and taking the time to reply.
  10. I found this script for 2D arrays in another help topic: ;# ==================================================================================== ;# Sample 1 ;# First make 2d array, make sure u know how many entries u need, hire I made 6 rows #include <Array.au3> Global $aArray1[6] $aArray1[1] = "Holger" $aArray1[2] = "Jon" $aArray1[3] = "Larry" $aArray1[4] = "Jeremy" $aArray1[5] = "Valik" _ArrayDisplay($aArray1, '$aArray1') ; show it Global $aArray2[6] $aArray2[1] = "$2" $aArray2[2] = "$1" $aArray2[3] = "$0" $aArray2[4] = "$2" $aArray2[5] = "$1" _ArrayDisplay($aArray2, '$aArray2') ; show it ;# Creating 2D array Global $2D_arr[6][2] ; 6 rows & 3 columns _ArrayDisplay($2D_arr, '$2D_arr') ; show it _fill_2d_array($aArray1, 0) _ArrayDisplay($2D_arr, '$2D_arr') ; show it _fill_2d_array($aArray2, 1) _ArrayDisplay($2D_arr, '$2D_arr') ; show it ;# Loop through given array & pur its contents into 2d Array func _fill_2d_array($_Input_Array, $Column) For $i = 1 To UBound($_Input_Array) -1 $2D_arr[$i][$Column] = $_Input_Array[$i] Next EndFunc The $2D_arr looks similar to what I want to make, but how would I set and edit data for column 2 based on the cell in column 1. For example, Everyone received $1 except Valik. How much money did Holger have? Holger had $2. $2 + $1 = $3 Holger now has $3 (repeat until all people are updated except Valik) Any ideas how to do something like that?
×
×
  • Create New...