j'aimerais avoir un script vbs
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionOption Explicit CONST STR_WEPLAYYOURMUSICDBFILE = "C:\Program Files\ActiveXperts\SMS Messaging Server\Projects\Voting Demo (Music)\Database\WePlayYourMusic.mdb" CONST STR_DEBUGFILE = "C:\Program Files\ActiveXperts\SMS Messaging Server\Sys\Tmp\WePlayYourMusic.txt" CONST STR_USAGE = "To send a request, type: Horos . For instance: Vote belier" Dim g_objMessageDB, g_objDebugger, g_objConstants ' Creation of global objects Set g_objConstants = CreateObject( "AxMmServer.Constants" ) Set g_objMessageDB = CreateObject( "AxMmServer.MessageDB" ) Set g_objDebugger = CreateObject( "ActiveXperts.VbDebugger" ) ' Set Debug file g_objDebugger.DebugFile = STR_DEBUGFILE g_objDebugger.Enabled = True ' // ======================================================================== ' // ProcessMessage ' // ------------------------------------------------------------------------ ' // ProcessMessage trigger function ' // ======================================================================== Function ProcessMessage( numMessageID ) Dim objMessageIn, objMessageOut, arrMessage Dim strMessageOutBody Dim numSongID, strCommand g_objDebugger.WriteLine ">> ProcessMessage" ' Open the Message Database g_objMessageDB.Open If( g_objMessageDB.LastError <> 0 ) Then g_objDebugger.WriteLine "<< ProcessMessage, unable to open database" Exit Function End If ' Retrieve the message that has just been received. If it fails then exit script Set objMessageIn g_objMessageDB.FindFirstMessage( "ID " & numMessageID ) If g_objMessageDB.LastError <> 0 Then g_objMessageDB.Close g_objDebugger.WriteLine "<< ProcessMessage, unable to find message" Exit Function End If ' Set incoming SMS message status to: SUCCESS (previous state was: PENDING) objMessageIn.StatusID = g_objConstants.MESSAGESTATUS_SUCCESS g_objMessageDB.Save objMessageIn g_objDebugger.WriteLine " Incoming message saved, result: [" & g_objMessageDB.LastError & "]" ' Split received message body into pieces (separated by spaces) arrMessage = Split( UCase( objMessageIn.Body ), " " ) If( UBound( arrMessage ) = 0 ) Then ' Just 1 param, so ? is expected. But on any other single word, also show help strMessageOutBody = ShowHelp() ElseIf( UBound( arrMessage ) = 1 ) Then strCommand = GetCommand( arrMessage(0) ) ' Converts any word starting with v or V to V numSongID = GetSongID( arrMessage(1) ) ' Converts string to number, if possible. Also checks range If( strCommand <> "V" ) Then strMessageOutBody = ShowWrongParam( arrMessage(0) ) ElseIf( numSongID = 0 ) Then strMessageOutBody = ShowWrongParam( arrMessage(1) ) Else strMessageOutBody = UpdateSongRequests( objMessageIn.FromAddress, numSongID ) End If Else strMessageOutBody = ShowSyntaxError() End If ' Create a new reply message Set objMessageOut = g_objMessageDB.Create g_objDebugger.WriteLine " New message created, result: [" & g_objMessageDB.LastError & "]" If( g_objMessageDB.LastError = 0 ) Then objMessageOut.DirectionID = g_objConstants.MESSAGEDIRECTION_OUT objMessageOut.TypeID = g_objConstants.MESSAGETYPE_SMS objMessageOut.StatusID = g_objConstants.MESSAGESTATUS_PENDING objMessageOut.ToAddress = objMessageIn.FromAddress objMessageOut.ChannelID = objMessageIn.ChannelID ' Use same channel as used for the incoming message. objMessageOut.BodyFormatID = objMessageIn.BodyFormatID objMessageOut.Body = strMessageOutBody g_objMessageDB.Save objMessageOut g_objDebugger.WriteLine " New message saved, result: [" & g_objMessageDB.LastError & "]" End If ' Close the Message Database g_objMessageDB.Close g_objDebugger.WriteLine "<< ProcessMessage" End Function ' // ======================================================================== ' // UpdateSongRequests ' // ------------------------------------------------------------------------ ' // Update the SongRequests table with the request that was just received ' // ======================================================================== Function UpdateSongRequests( strSenderNumber, numSongID ) On Error Resume Next Dim objConn, strQuery, RS, hexError, strResult Dim cnt1, cnt2 Dim strSong g_objDebugger.WriteLine( ">> UpdateSongRequests( " & strSenderNumber & "," & numSongID & ")" ) ' Create database object; open the database Set objConn = CreateObject("ADODB.Connection") objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & STR_WEPLAYYOURMUSICDBFILE & ";" ' Retrieve Song title, to display it later in the reply ' If it does not exist then return with an error strQuery = "SELECT * FROM SongTitles WHERE ID=" & numSongID Err.Clear ' Clear a previous error Set RS = objConn.Execute( strQuery ) hexError = Hex( Err.Number ) If( hexError <> "0" ) Then g_objDebugger.WriteLine( "<< UpdateSongRequests, Err.Number: " & Err.Number & "; Err.Description: " & Err.Description ) UpdateSongRequests = "Request could not be processed (database error #" & hexError & " occured ). " objConn.Close Set objConn = Nothing Exit Function End If If( RS.EOF ) Then g_objDebugger.WriteLine( "<< UpdateSongRequests, song does not exist" ) UpdateSongRequests = "Request could not be processed (song #" & numSongID & " does not exist). " objConn.Close Set objConn = Nothing Exit Function End If strSong = RS( "Artist" ) & "-" & RS( "Title" ) strSong = Trim( strSong ) ' Execute INSERT statement strQuery = "INSERT INTO SongRequests( SmsNumber, DateVal, TimeVal, SongID ) VALUES ( '" & strSenderNumber & "', '" & Date() & "', '" & Time() & "', " & numSongID & " )" Err.Clear ' Clear a previous error objConn.Execute( strQuery ) ' Catch error - if any hexError = Hex( Err.Number ) If( hexError <> "0" ) Then g_objDebugger.WriteLine( "Err.Number: " & Err.Number & "; Err.Description: " & Err.Description ) UpdateSongRequests = "Request could not be processed. " objConn.Close Set objConn = Nothing Exit Function End If strResult = "Request successfully processed. " ' Now, calculate #request for this particular song (cnt1) and totla requests(cnt2). ' If both can be calculated then append it to the reponse cnt1 = 0 cnt2 = 0 strQuery "Select Count(*) As cnt1 FROM SongRequests WHERE SongID " & numSongID g_objDebugger.WriteLine( strQuery ) Set RS = objConn.Execute( strQuery ) hexError = Hex( Err.Number ) If( hexError = "0" ) Then cnt1 = RS( "cnt1" ) strQuery = "Select Count(*) As cnt2 FROM SongRequests" Set RS = objConn.Execute( strQuery ) hexError = Hex( Err.Number ) If( hexError = "0" ) Then cnt2 = RS( "cnt2" ) strResult = strResult & "#Votes for [" & strSong & "] so far: " & cnt1 & "; #Total Votes (any song) : " & cnt2 End If End If objConn.Close Set objConn = Nothing UpdateSongRequests = strResult g_objDebugger.WriteLine( "<< UpdateSongRequests, result: " & UpdateSongRequests ) End Function ' // ======================================================================== ' // Show... functions ' // ------------------------------------------------------------------------ ' // Some error handling Show errors ' // ======================================================================== Function ShowWrongParam( strParam ) ShowWrongParam = "Wrong parameter: " & strParam End Function Function ShowWrongCommand( strCommand ) ShowWrongCommand = "Wrong command: " & strCommand End Function Function ShowSyntaxError() ShowSyntaxError = "Syntax error. " & STR_USAGE End Function Function ShowHelp() ShowHelp = STR_USAGE End Function ' // ======================================================================== ' // GetCommand ' // ------------------------------------------------------------------------ ' // Get the command. The only supported command is: Vote (or 'H' or 'H', or ' // anything else that starts with 'h' ' // ======================================================================== Function GetCommand( strCommand ) Dim strUCommand g_objDebugger.WriteLine( ">> GetCommand ( " & strCommand & " )" ) GetCommand = "" strUCommand = UCase( strCommand ) If( Left( strUCommand, 1 ) <> "H" ) Then GetCommand = "" g_objDebugger.WriteLine( "<< GetCommand, first character is not a 'h' or 'H'" ) Exit Function End If GetCommand = "H" g_objDebugger.WriteLine( "<< GetCommand, return: H" ) End Function ' // ======================================================================== ' // GetSongID ' // ------------------------------------------------------------------------ ' // Function returns the song ID. ' // If paramter cannot be ocnverted to a number, or if number not in ' // range [1..1000] then 0 is returned ' // ======================================================================== Function GetSongID( strSongID ) On Error Resume Next ' Necessary to catch error because of a non-numeric value Dim numSongID g_objDebugger.WriteLine( ">> GetSongID ( " & strSongID & " )" ) numSongID = 0 ' do this because next call may fail upon non-integer numSongID = CInt( strSongID ) If( numSongID = 0 ) Then GetSongID = 0 Exit Function End If If( numSongID < 1 Or numSongID > 1000 ) Then GetSongID = 0 Exit Function End If GetSongID = numSongID g_objDebugger.WriteLine( "<< GetSongID, return: " & numSongID ) End Function