Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Tuesday, June 27, 2017

Speak any Text

Example to create Speak vbs file.

Set voice = CreateObject("SAPI.SpVoice")
voice.Rate = 1
voice.Volume = 90
Say = InputBox("Say Something", "Say Something", "Hey !! how is going on...")
If (Len(Say) > 0) Then
    voice.Speak Say
End If


Thursday, May 19, 2016

Retrieving data from SQL Server using RecordSet object in VBScript

Option Explicit

Dim Conn ' Connection Variable
Dim rs ' Recordset Variable
Dim sqlQuery
Dim serverName
Dim field


'Declare the SQL statement that will query the database
sqlQuery = "SELECT UserName FROM dbo.UserList WHERE ID = '9'"


'Create an instance of the ADO connection and recordset objects

Set Conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")


'Open the connection to the database
Conn.Open "DSN=getUser;UID=user1;PWD=password;Database=dbUserList"


'Open the recordset object executing the SQL statement and return records 
rs.Open sqlQuery,Conn


'Check if any record exist in table 
If rs.EOF Then 
wscript.echo "No Record Found"
wscript.quite
Else 

Do While NOT rs.Eof   
field = rs("UserName")
if field <> "" then
  wscript.echo field
end if
rs.MoveNext     
Loop

End If


'Close Connection and Recordset
rs.Close
Set rs=nothing
Conn.Close
Set Conn=nothing

VBScript Prompt a User for Input


It was been ask by one of my friend that how to get input from user in VBScript. I though by adding this to blog, that will help other.

getStringValue = InputBox("Please enter some value :","Window Title")

You can also use this in condition also in this.

If getStringValue="" then

 Wscript.Quite

else

  Wscript.Echo getStringValue

End if

Wednesday, May 18, 2016

VBScript to update Access Database


Save following line to .VBS file


Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
    "Provider = Microsoft.Jet.OLEDB.4.0;; Data Source = C:\Temp\Local.mdb"

objRecordSet.Open "Update Set = ", _
        objConnection, adOpenStatic, adLockOptimistic

OR

objRecordSet.Open "Insert into Values(,,...)", _
        objConnection, adOpenStatic, adLockOptimistic




Execute script Via Command Line

  1. Hold your windows key and press “R” to open the command prompt
  2. type: “%windir%\SysWoW64\wscript.exe
  3. Press OK