Showing posts with label Vbscript. Show all posts
Showing posts with label Vbscript. Show all posts

Saturday, 11 May 2019

ADODB my SQL Connection with VbScript

Function test()

On Error Resume Next

Set obj = CreateObject("ADODB.Connection")
Set obj1 = CreateObject("ADODB.RecordSet")
Dim dbquery
dbquery = "INSERT INTO test (firstname,lastname) VALUES ('neha','deshmukh');"

obj.Open "Server=db4free.net;Data Source=mysql; Database=sumit1234; User=sumit1234; Password=sumit1234;"

MsgBox obj1.State & ""

MsgBox Err.Description
obj1.Open dbquery, obj

MsgBox Err.Description

obj.Close
obj1.Close
Set obj1 = Nothing
Set obj = Nothing


End Function

Sunday, 12 November 2017

Vbscript: Print the Pattern

Expected Pattern:
*
**
***


Code:

str=""
For r = 0 To 2 Step 1
   
   
    For c=0 to 2 Step 1
   
   
     If c<=Then
        
         str=str+"*"
        
     End If
       
    Next
   
    str=str+vbnewline
Next

print str

Friday, 10 November 2017

UFT Interview Question: Alternate lowercase and uppercase letter in word: Capegemini==>CaPeGeMiNi

str="Capegemini"

strfinaltext=""
 
For i = 1 To len(str) Step 1
    If i mod 2 <>0 Then
        strfinaltext=strfinaltext+ ucase(mid(str,i,1))
       
    Else
   
        strfinaltext=strfinaltext+lcase(mid(str,i,1))
    End If
Next

msgbox strfinaltext  'CaPeGeMiNi

Sunday, 5 November 2017

QTP Interview Questions:

Listing All the questions I faced in interviews so far:

UFT:

1)Explain Framework used in your project
2) Explain your roles and responsibilities
2)How do you do Error Handling
3) How many cases are there in your test suite
4)How do you do reporting
5) Open test from present in ALM using AOM
6)If hierarchy if object present in OR changes and its affecting 50 scripts, how would you deal with it
7) If I give yo something to automate how would you automate. What will be the steps.
8)what is virtual Objects
9)What is Visual Relation Identification works
10) How object Identification works






VBSCRIPT: Questions:

1)How to covert number to string ( 123 should be shown as One Two Three)
2) Explain On Error Resume Next
3) If function had 3 arguments and I want to pass 4th argument how would you deal with it
4) Count occurrence of each character in a string
5) How to handle xml files. If I want to get particular node value in xml file how can I get it.
6) Can function return multiple values
7) If I want to return multiple values from subroutine how can i do it
8) Separate xls,txt,csv files from folder
9)


Vbscript: Instr() or Regular Expression

 sString = “Welcome User, You have 5 New Mails”
 sSubString = “Welcome .*, You have .* New Mails”‘Check if the string pattern matches – using 

RegExp object
Set objRE = New RegExp
objRE.Global = True
objRE.Pattern = sSubString
msgbox objRE.Execute(sString).Count ‘ — msgbox returns the value 1 as the RegExp object returns 1 match 

‘Check if the string pattern matches  – using InStr
msgbox InStr(1, sString, sSubString, 1)  ‘ — msgbox returns the value 0  as it is not able to find the match using InStr

Tuesday, 24 October 2017

UFT: ADODB connection to Sql Server

'Create Connection Object

Set con=CreateObject("ADODB.connection")

'Create RecordSet Object
Set Rs=CreateObject("ADODB.Recordset")

On Error Resume next

'Open the Connection 
con.Open "Provider = sqloledb.1;Server=SUNSHINE-PC;Database=northwind;User Id=sa;Password=password;"


'run the query with record set object over opened connection


rs.open "select * from [dbo].[Categories]",con

While rs.EOF<>True


msgbox rs.Fields.Item(0)&" "&rs.Fields.Item(1)

'Bad Record for testing
msgbox rs.Fields.Item(100)

rs.MoveNext
   
   
Wend

If Err.Num<>0 Then
   
    msgbox "Something Wrong with ADOBDB"
End If

rs.Close
con.Close

Set rs=nothing
Set con=nothing

Monday, 23 October 2017

UFT FIreEvent:Dealing with MouseOver Menus


'http://way2automation.com/way2auto_jquery/index.php
Browser("Welcome_2").Page("Welcome_2").Link("Widget").FireEvent "OnMouseOver"
Browser("Welcome_2").Page("Welcome_2").Link("Datepicker").Click

Monday, 16 October 2017

VBscript: Finding Occurance of Each Character in the string

Dim a()
Dim strtext
'Provide the text 
strtext="this is sparta"

'Create An Array with each letter of the text
ReDim a((len(strtext)-1))
For i=1 to len(strtext) Step 1
a(i-1)=mid(strtext,i,1)
Next

'Create Dictionary Object to store unique values of the text

Set odic=CreateObject("Scripting.Dictionary")
'ReDim a((len(strtext)-1))
For i=1 to len(strtext) Step 1

If NOT odic.Exists(mid(strtext,i,1)) Then
    odic.add (mid(strtext,i,1)),"i"
End If
   
Next

alluniquekeys=odic.Keys

'Compare unique items with each item present in the array and increase the counter when there is a match
For i = 0 To ubound(alluniquekeys) Step 1
    count=0
    For j = 0 To ubound(a) Step 1
       
        If alluniquekeys(i)=a(j) Then
        count=count+1
        End If
    Next
    print " "&a(i)& "appears "&count&"times"
Next




REM===> OUTPUT
 t appears 2 times
 h appears 1 times
 i appears 2 times
 s appears 3 times
   appears 2 times
 p appears 1 times
 a appears 2 times
 r appears 1 times

Thursday, 15 September 2016

VBScript: Function Returning Array



Function Getdata()

Dim a()
strt = "sumit"
strt2 = "raut"
a = Array(strt, strt2)

Getdata = a()


End Function

Sub main()


Dim oExcel, oWB, oSheet, setVal
Set oExcel = CreateObject("Excel.Application")
Set oWB = oExcel.Workbooks.Open("D:\Macrowork\Call from Sub.xlsx")
Set oSheet = oWB.WorkSheets("data")
oExcel.Visible = True
Dim Arr1()

rowcount = oSheet.usedrange.rows.Count

For r = 2 To rowcount Step 1

Arr1 = Getdata
oSheet.cells(r, 4) = Arr1(0)
oSheet.cells(r, 5) = Arr1(1)

Next

oWB.Save
Set oExcel = Nothing

End Sub


Rest Assured Chectsheet

REST Assured Cheat Sheet 🚀 REST Assured Cheat Sheet Complete Reference for ...