Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiontsuji (TechnicalUser)
26 Sep 10 10:12
>use this function in vbs since 2 years
I don't know what happens on those 2 years of the vbs of yours. But, the script is certain not correct if only you got away because it errors out, at least, just at the end and you had escaped the mal-function by fortune. There is no way it works as such at any period of time.
It should at least look something like this. Still no gurantee, depending the proper url to process the post. To an xml extension, it seems strange; but I have no way to know.
Function SendToTwitter(strMessage, strUsername, strPassword)
'On Error Resume Next
Dim objHTTP, result
Set objHTTP = CreateObject("Microsoft.XMLHTTP")
WScript.Echo "Post Twitter : " & " " & numligne & " " & date() & " " & time () & " " & strMessage
objHTTP.open "POST", "http://twitter.com/statuses/update.xml", false, strUsername, strPassword
objHTTP.send "status=" & escape(strMessage)
'result = objHTTP.responseText
If objHttp.status <> 200 Then
Postageok=0
WScript.Echo "No Post Twitter" & Len(strMessage) & Statusok
result=""
Else
Postageok=1
WScript.Echo "Post Twitter OK " & Statusok
result=objHTTP.responseText
End if
'strMessage = ""
Set objHTTP = nothing 'Release the object
'This won't do anything, just because you have an on error resume next; it is wrong and you're fortunate to preserve result if it were a global variable to be used (but it is not global neither). Only postageok seems global.
'Set result = Nothing
'If result is some global variable (that should not be because you've dim result up there), you would be fortunate to get away and end the function there.
'If result is not global (that seems to be the case), you need to return to caller by this line, and during the 2 years, something happened to you if you think it works.
SendToTwitter=result
End Function
'for instance, the way to use it
dim s, postageok
s=SendToTwitter("some message","userx","passwordx")
'check postageok value too.
tsuji (TechnicalUser)
26 Sep 10 11:29
Upon re-reading my comments, they might tend to imply(?) the set result to nothing would error out, that is not what I would imply. I meant only it won't do anything, and it is contradictory in intention, and the result won't pass outside of the function and thereby died with the function as it is local to it.