I'm learning Autoit and have searched for a UDF as below, expecting people to help
Func FB_Post($Handle, $Content, $Pri = 0, $UID = False)
Local $Post_pri[3] = ["300645083384735", "291667064279714", "286958161406148"], $data, $UserID = ($UID ? $UID : $Handle[1]), $Post_body, $Get_id
If not IsArray($Handle) then Return SetError(1, 0, False)
If $Pri < 0 Or $Pri > 2 or (not IsNumber($Pri)) Then $Pri = 0
$data = "privacyx=" & ($UID ? "" : $Post_pri[$Pri]) & "&xhpc_targetid=" & $UserID &"&xhpc_message=" & _URIEncode($Content) & "&fb_dtsg=" & $Handle[2]
$Post_body = _HttpRequest(2, "https://www.facebook.com/ajax/updatestatus.php",$data, $Handle[0], "https://www.facebook.com/profile.php?id=" & ($UID ? $UID :$Handle[1]))
$Get_id = StringRegExp($Post_body, "top_level_post_id":"(.*?)"",3)
If #error then Return SetError(2, 0, True)
Return $Get_id[0]
EndFunc
Click Full Source
Related
I am trying to run the below code and getting the below error -
Error: Syntax: Missing comma or ) in argument list
Below is the complete code, I watned to create.
function tournamentWinner(competetions, results)
teams = Dict()
for i in range(1, length(results))
if (results[i] == 1) && (competetions[i][0] not in teams)
teams[competetions[i][0]] = 1
elseif (results[i] == 1) && (competetions[i][0] in teams)
teams[competetions[i][0]] += 1
elseif (results[i] == 0) && (competetions[i][1] not in teams)
teams[competetions[i][1]] = 1
elseif (results[i] == 0) && (competetions[i][1] in teams)
teams[competetions[i][1]] += 1
end
end
return findmax(teams)[2]
end
competetions = [["HTML", "Java"],["Java", "Python"], ["Python", "HTML"],["C#", "Python"],["Java", "C#"],["C#", "HTML"]]
results = [0, 1, 1, 1, 0, 1]
tournamentWinner(competetions, results)
The below code worked for me, replaced 'in', 'not in' with 'haskey', '!haskey' for dictionary
function tournamentWinner(competetions, results)
teams = Dict()
for i in range(1, length(results))
if (results[i] == 1) && !haskey(teams, competetions[i][1])
teams[competetions[i][1]] = 1
elseif (results[i] == 1) && haskey(teams, competetions[i][1])
teams[competetions[i][1]] += 1
elseif (results[i] == 0) && !haskey(teams, competetions[i][2])
teams[competetions[i][2]] = 1
elseif (results[i] == 0) && haskey(teams, competetions[i][2])
teams[competetions[i][2]] += 1
end
end
return findmax(teams)[2]
end
competetions = [["HTML", "Java"],["Java", "Python"], ["Python", "HTML"],["C#", "Python"],["Java", "C#"],["C#", "HTML"]]
results = [0, 1, 1, 1, 0, 1]
tournamentWinner(competetions, results)
It is possible, in AU3, use WinHttp.WinHttpRequest.5.1 with a progress bar? Actually what I need is to know how many MB have already been downloaded.
I need to use "WinHttp.WinHttpRequest.5.1" because I have to use the parameter "Referer" in the header.
Of course it is
#include "WinHttp.au3"
; Download some gif
;~ http://33.media.tumblr.com/dd3ffab90cc338666f192fd86f6a4f8f/tumblr_n0pefhIpss1swyb6ao1_500.gif
; Initialize and get session handle
$hOpen = _WinHttpOpen()
; Get connection handle
$hConnect = _WinHttpConnect($hOpen, "http://33.media.tumblr.com")
; Specify the reguest
$hRequest = _WinHttpOpenRequest($hConnect, Default, "dd3ffab90cc338666f192fd86f6a4f8f/tumblr_n0pefhIpss1swyb6ao1_500.gif")
; Send request
_WinHttpSendRequest($hRequest)
; Wait for the response
_WinHttpReceiveResponse($hRequest)
;~ ConsoleWrite(_WinHttpQueryHeaders($hRequest) & #CRLF)
ProgressOn("Downloading", "In Progress...")
Progress(_WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_LENGTH))
Local $sData
; Check if there is data available...
If _WinHttpQueryDataAvailable($hRequest) Then
While 1
$sChunk = _WinHttpReadData_Ex($hRequest, Default, Default, Default, Progress)
If #error Then ExitLoop
$sData &= $sChunk
Sleep(20)
WEnd
Else
MsgBox(48, "Error", "Site is experiencing problems (or you).")
EndIf
Sleep(1000)
ProgressOff()
; Close handles
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
; Do whatever with data, write to some file or whatnot. I'll just print it to console here:
ConsoleWrite($sData & #CRLF)
Local $hFile = FileOpen(#DesktopDir & "\test.gif", 26)
FileWrite($hFile, $sData)
FileClose($hFile)
Func Progress($iSizeAll, $iSizeChunk = 0)
Local Static $iMax, $iCurrentSize
If $iSizeAll Then $iMax = $iSizeAll
$iCurrentSize += $iSizeChunk
Local $iPercent = Round($iCurrentSize / $iMax * 100, 0)
ProgressSet($iPercent, $iPercent & " %")
EndFunc
Func _WinHttpReadData_Ex($hRequest, $iMode = Default, $iNumberOfBytesToRead = Default, $pBuffer = Default, $vFunc = Default)
__WinHttpDefault($iMode, 0)
__WinHttpDefault($iNumberOfBytesToRead, 8192)
__WinHttpDefault($vFunc, 0)
Local $tBuffer, $vOutOnError = ""
If $iMode = 2 Then $vOutOnError = Binary($vOutOnError)
Switch $iMode
Case 1, 2
If $pBuffer And $pBuffer <> Default Then
$tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]", $pBuffer)
Else
$tBuffer = DllStructCreate("byte[" & $iNumberOfBytesToRead & "]")
EndIf
Case Else
$iMode = 0
If $pBuffer And $pBuffer <> Default Then
$tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]", $pBuffer)
Else
$tBuffer = DllStructCreate("char[" & $iNumberOfBytesToRead & "]")
EndIf
EndSwitch
Local $sReadType = "dword*"
If BitAND(_WinHttpQueryOption(_WinHttpQueryOption(_WinHttpQueryOption($hRequest, $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_PARENT_HANDLE), $WINHTTP_OPTION_CONTEXT_VALUE), $WINHTTP_FLAG_ASYNC) Then $sReadType = "ptr"
Local $aCall = DllCall($hWINHTTPDLL__WINHTTP, "bool", "WinHttpReadData", _
"handle", $hRequest, _
"struct*", $tBuffer, _
"dword", $iNumberOfBytesToRead, _
$sReadType, 0)
If #error Or Not $aCall[0] Then Return SetError(1, 0, "")
If Not $aCall[4] Then Return SetError(-1, 0, $vOutOnError)
If IsFunc($vFunc) Then $vFunc(0, $aCall[4])
If $aCall[4] < $iNumberOfBytesToRead Then
Switch $iMode
Case 0
Return SetExtended($aCall[4], StringLeft(DllStructGetData($tBuffer, 1), $aCall[4]))
Case 1
Return SetExtended($aCall[4], BinaryToString(BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]), 4))
Case 2
Return SetExtended($aCall[4], BinaryMid(DllStructGetData($tBuffer, 1), 1, $aCall[4]))
EndSwitch
Else
Switch $iMode
Case 0, 2
Return SetExtended($aCall[4], DllStructGetData($tBuffer, 1))
Case 1
Return SetExtended($aCall[4], BinaryToString(DllStructGetData($tBuffer, 1), 4))
EndSwitch
EndIf
EndFunc
You here find the WinHTTP.au3 here: https://github.com/dragana-r/autoit-winhttp/releases.
It is my favorite UDF!
I have comments all around the code to explain you the process.
$aArray = _IEFrameGetCollection($ObjIE)
$max = #extended
ConsoleWrite("Array Length: " & $max & #CR)
For $item in $aArray
ConsoleWrite("Value" & $item.src)
Next
The code causes the following error:
--> COM Error Encountered in ITSM-GUI-Automation.au3
----> $IEComErrorScriptline = 106
----> $IEComErrorNumberHex = 80020003
----> $IEComErrorNumber = -2147352573
----> $IEComErrorWinDescription = Member not found.
----> $IEComErrorDescription =
----> $IEComErrorSource =
----> $IEComErrorHelpFile =
----> $IEComErrorHelpContext = 0
----> $IEComErrorLastDllError = 0
The weird thing is that $max is getting set to 3 but then it cannot find the iframes. How can it find it and immediately not find it?
This is because of my lack of understanding of the Autoit objects. This does not return an array of objects but a collection which must be accessed through a different way.
Hope this helps someone else.
$collection = _IEFrameGetCollection($ObjIE)
$max = #extended
ConsoleWrite("Array Length: " & $max & #CR)
For $item = 0 to $max - 1
$obj = IEFrameGetCollection($ObjIE, $item)
ConsoleWrite("Value" & $item.src)
Next
#include <IE.au3>
Local $oIE = _IE_Example("frameset")
Local $oFrames = _IEFrameGetCollection($oIE)
Local $iNumFrames = #extended
For $i = 0 To ($iNumFrames - 1)
Local $oFrame = _IEFrameGetCollection($oIE, $i)
$FrameHTML = _IEDocReadHTML($oFrame); or
$FrameHTML = _IEPropertyGet($oFrame, "innerhtml"); or
$FrameHTML = _IEPropertyGet($oFrame, "outerhtml")
ConsoleWrite($FrameHTML & #LF)
Next
Im having a problem with an IF statement.
The purpose of this statement is that all 3 managers must approve an order before it can prossesed.
This is the statement :
Dim RstAllchk
Dim RstAllchk_numRows
Set RstAllchk = Server.CreateObject("ADODB.Recordset")
RstAllchk.ActiveConnection = MM_DBConn_STRING
RstAllchk.Source = "SELECT comitee.OrderNo, comitee.Bart, comitee.Carel, comitee.Charl FROM comitee WHERE (((comitee.OrderNo)='" + Replace(RstAllData__varOrderNum, "'", "''") + "'));"
RstAllchk.CursorType = 0
RstAllchk.CursorLocation = 2
RstAllchk.LockType = 1
RstAllchk.Open()
RstAllchk_numRows = 0
if (RstAllchk.Fields.Item("Bart").Value)= "Approved" then
if (RstAllchk.Fields.Item("Carel").Value)= "Approved" then
if (RstAllchk.Fields.Item("Charl").Value)= "Approved" then
set cdata1 = Server.CreateObject("ADODB.Command")
cdata1.ActiveConnection = MM_DBConn_STRING
cdata1.CommandText = " UPDATE TblOrderData SET Fldapproved = 'Approved' WHERE FldOrderID = '" & RstAllData__varOrderNum & "'"
cdata1.CommandType = 1
cdata1.CommandTimeout = 0
cdata1.Prepared = true
cdata1.Execute()
cdata1.ActiveConnection.Close
set cdata2 = Server.CreateObject("ADODB.Command")
cdata2.ActiveConnection = MM_DBConn_STRING
cdata2.CommandText = " UPDATE TblOrderDetail SET FldMainapproved = 'Approved' WHERE FldOrderNum = '" & RstAllData__varOrderNum & "'"
cdata2.CommandType = 1
cdata2.CommandTimeout = 0
cdata2.Prepared = true
cdata2.Execute()
cdata2.ActiveConnection.Close
`
Sometimes if only one of the managers confirmed the order, the order is still approved. I have been struggling with this for days. Hope any of you can give me some advice.
Thanks
Assuming VB.NET:
IF (RstAllchk.Fields.Item("Bart").Value = "Approved" AND _
RstAllchk.Fields.Item("Carel").Value = "Approved" AND _
RstAllchk.Fields.Item("Charl").Value = "Approved") THEN
In C#:
if (RstAllchk.Fields.Item("Bart").Value == "Approved" &&
RstAllchk.Fields.Item("Carel").Value == "Approved" &&
RstAllchk.Fields.Item("Charl").Value == "Approved")
With C# (&& is And , == is equal)
if ( RstAllchk.Fields.Item("Bart").Value == "Approved"
&& RstAllchk.Fields.Item("Carel").Value == "Approved"
&& RstAllchk.Fields.Item("Charl").Value == "Approved"
)
{
//treatment
}
You can merge all like
(if var1 == x && var2 == y && var3 == z) {
//Do what you want
}
I'm trying to write an AutoIt script that uninstalls all MSI packages with a specific Upgrade Code. This is my code so far:
$i = 0
Do
$buffer = DllStructCreate("wchar[39]")
$ret = DllCall("msi.dll", "UINT", "MsiEnumRelatedProductsW", _
"wstr", "{a1b6bfda-45b6-43cc-88de-d9d29dcafdca}", _ ; lpUpgradeCode
"dword", 0, _ ; dwReserved
"dword", $i, _ ; iProductIndex
"ptr", DllStructGetPtr($buffer)) ; lpProductBuf
$i = $i + 1
MsgBox(0, "", $ret[0] & " " & DllStructGetData($buffer, 1))
Until($ret[0] <> 0)
This works flawlessly to determine the Product Code for the first installed product, but it returns 87 (ERROR_INVALID_PARAMETER) as soon as iProductIndex is incremented to 1. Usually this error is returned when the input GUID is malformed, but if that would be the case, it shouldn't work with iProductIndex = 0 either...
What I expected from this code (when 2 packages with the same Upgrade Code are installed) is:
Print "0 <first Product Code>"
Print "0 <second Product Code>"
Print "259" (ERROR_NO_MORE_ITEMS)
What it currently does:
Print "0 <first Product Code>"
Print "87" (ERROR_INVALID_PARAMETER)
Any ideas?
(If you want to test this code on your own computer, you will need to have two MSI packages with the same UpgradeCode installed. Here are my WiX test packages: http://pastie.org/3022676 )
OK, I've found a simple workaround: I just remove every product I can find with iProductIndex = 0 in a loop.
Func GetProduct($UpgradeCode)
$buffer = DllStructCreate("wchar[39]")
$ret = DllCall("msi.dll", "UINT", "MsiEnumRelatedProductsW", _
"wstr", $UpgradeCode, _ ; lpUpgradeCode
"dword", 0, _ ; dwReserved
"dword", 0, _ ; iProductIndex
"ptr", DllStructGetPtr($buffer)) ; lpProductBuf
Return DllStructGetData($buffer, 1)
EndFunc
$Last = ""
$Product = ""
Do
$Last = $Product
$Product = GetProduct("{a1b6bfda-45b6-43cc-88de-d9d29dcafdca}")
If $Product = "" Then Exit
$Ret = RunWait("msiexec /qn /x " & $Product)
ConsoleWrite($Ret & " " & $Product & #CRLF)
If $Product = $Last Then Exit 1
Until($product = "")
This doesn't work because using DllCall() the DLL is not kept open. The function MsiEnumRelatedProducts propably has internal state that is required for the enumeration and is only initialized when the index is zero. When the DLL is closed, this state is lost.
To fix this, call DllOpen() before the loop. Keep the DLL open while the loop is running and pass the DLL handle instead of its filename to DllCall(). Close the DLL using DllClose() when the loop has been finished.
Here is a function that returns an array of ProductCodes for the given UpgradeCode. It returns Null in case the function didn't found any products.
Func GetRelatedProducts( $UpgradeCode )
Local $result[ 1 ] ; Can't declare empty array :/
Local $dll = DllOpen( "msi.dll" )
If #error Then Return SetError( 1, #error, Null )
Local $buffer = DllStructCreate( "wchar[39]" )
Local $index = 0
Local $success = False
Do
Local $ret = DllCall( $dll, "UINT", "MsiEnumRelatedProductsW", _
"wstr", $UpgradeCode, _ ; lpUpgradeCode
"dword", 0, _ ; dwReserved
"dword", $index, _ ; iProductIndex
"ptr", DllStructGetPtr($buffer)) ; lpProductBuf
If #error Then
DllClose( $dll )
Return SetError( 1, #error, Null )
EndIf
$success = $ret[ 0 ] = 0 ; $ret[ 0 ] contains the DLL function's return value
If( $success ) Then
Local $productCode = DllStructGetData( $buffer, 1 )
Redim $result[ $index + 1 ]
$result[ $index ] = $productCode
$index += 1
EndIf
Until( Not $Success )
DllClose( $dll )
if( $index ) Then
Return $result
Else
Return Null
EndIf
EndFunc
Usage:
Local $productCodes = GetRelatedProducts( "{insert-upgradecode-here}" )
If( IsArray( $productCodes ) ) Then
MsgBox( 0, "Success!", "Found products:" & #CRLF & _ArrayToString( $productCodes, #CRLF ) )
EndIf