## Frequently Asked Coding Questions During Interview on UFT

### How to Add digits of a given number?

```
Dim num, sum
num=inputbox ("Enter a Four digit number")
If Len(num) = 4 Then
sum=0
sum=sum+num mod 10
num=num/10
num= left (num, 3)
sum=sum+num mod 10
num=num/10
num= left (num, 2)
sum=sum+num mod 10
num=num/10
num= left (num, 1)
sum=sum+num mod 10
msgbox ("Sum is " &sum)
else
msgbox "Number, you entered is not a 4 digit number"
End If
```

### How to read any Four-digit number and display the number in reverse order?

off course we can convert the given digit to String and use the inbuilt String reverse function.We can use recursion to solve the issue. Here is an approach to use the aabove-writtenmod logic to reverse the same.

```
Dim num,rev
num= inputbox("Enter a number")
If len(num)=4 Then
rev=rev*10 + num mod 10
num=num/10
num= left(num,3)
rev=rev*10 + num mod 10
num=num/10
num= left(num,2)
rev=rev*10 + num mod 10
num=num/10
num= left(num,1)
rev=rev*10 + num mod 10
msgbox "Reverse Order of the number is "&rev
Else
msgbox "Number, you entered is not a 4 digit number"
End If
```

one more approach to reverse the number:

```
Dim num,n
n=Inputbox ("Enter a Vaule")
For num=n to 1 step -1
msgbox num
Next
```

### How to calculate the grade for an examination and display the grade obtained?

The conditions are:

- If average marks Greater than or equal to 75, the grade is Distinction
- If average marks Greater than or equal to 60 and less than 75 , then the grade is First
- If average marks Greater than or equal to 50 and less than 60, then the grade is Second
- If average marks Greater than or equal to 40 and less than 50 , then the grade is Third
- Minimum marks 35 for any subject, otherwise ‘no grade fail’)

```
Dim e,m,p,c, tot
e=inputbox ("Enter english Marks")
m=inputbox ("Enter maths Marks")
p=inputbox ("Enter physics Marks")
c=inputbox ("Enter chemistry Marks")
tot= cdbl(e) + cdbl(m) + cdbl(p) + cdbl(c)
msgbox tot
If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35 and cdbl(c) >=35 and tot >=300 Then
msgbox "Grade is Distinction"
else If cdbl(e) >=35 and cdbl(m) >=35 and cdbl(p) >=35 and cdbl(c) >=35 and tot >=240 and tot<300 Then
...
...
End if
End if
```

### How to calculate Even or odd calculation till n(any given number)

```
Dim num,n
n=Inputbox ("Enter a Vaule")
For num= 1 to n step 2
msgbox num
Next
```

### Write a program for finding out whether the given year is a leap year or not?

```
Dim xyear
xyear=inputbox ("Enter Year")
If xyear mod 4=0 Then
msgbox "This is a Leap year"
Else
msgbox "This is NOT"
End If
```

### Read two numbers and display the sum?

```
Dim num1,num2, sum
num1=inputbox ("Enter num1")
num2=inputbox ("Enter num2")
sum= Cdbl (num1) + Cdbl (num2) 'if we want add two strings conversion require
msgbox ("Sum is " &sum)
```

### How to Calculate the odd even number in UFT?

```
Dim num
num=inputbox ("Enter a number")
If num mod 2=0 Then
msgbox "This is a Even Number"
Else
msgbox "This is a Odd Number"
End If
```

### How to Calculate the Simple Interest?

```
Dim p,t, r, si
p=inputbox ("Enter Principle")
t=inputbox ("Enter Time")
r=inputbox ("Enter Rate of Interest")
si= (p*t*r)/100 ' p= principle amount, t=time in years, r= rate of interest
msgbox ("Simple Interest is " &si)
```

### How to display natural numbers up to n and write in a text file?

```
Dim num, n, fso, myfile
n= inputbox ("Enter any Value")
num=1
For num= 1 to n step 1
Set fso= createobject ("scripting.filesystemobject")
set myfile=fso.opentextfile ("D:test.txt", 8, true)
myfile.writeline num
myfile.close
Next
```

### How to display Natural numbers summation up to n? (Using For…Next Loop)

```
Dim num, n, sum
n= inputbox ("Enter a Value")
sum=0
For num= 1 to n step 1
sum= sum+num
Next
msgbox sum
```

### How to display Natural numbers sum up to n? (using While…Wend Loop)

```
Dim num, n, sum
n= inputbox ("Enter a Value")
While num <=cdbl (n)
sum= sum+num
num=num+1
Wend
msgbox sum
```

### Display Natural numbers sum up to n? (Using Do…Until…Loop)

```
Dim num, n, sum
n= inputbox ("Enter a Value")
sum=0
num=1
Do
sum= sum+num
num=num+1
Loop Until num =cdbl (n+1)
msgbox sum
```

### Write a Function for Natural Numbers sum up to n

```
Function NNumCou (n)
Dim num, sum
sum=0
For num= 1 to n step 1
sum= sum+num
Next
msgbox sum
End Function
```

### Verify weather the entered 10 digit value is a numeric value or not

```
Dim a,x,y,z,num
num=Inputbox ("Enter a Phone Number")
d1= left (num,1)
d10=Right (num,1)
d2=mid (num, 2, len (1))
d3=mid (num, 3, len (1))
d4=mid (num, 4, len (1))
d5=mid (num, 5, len (1))
d6=mid (num, 6, len (1))
d7=mid (num, 7, len (1))
d8=mid (num, 8, len (1))
d9=mid (num, 9, len (1))
If isnumeric (d1) = "True" and isnumeric (d2) = "True" and isnumeric (d3) = "True" and isnumeric (d4) = "True"and isnumeric (d5) = "True"and isnumeric (d6) = "True"and isnumeric (d7) = "True"and isnumeric (d8) = "True"and isnumeric (d9) = "True"and isnumeric (d10) = "True" Then
msgbox "It is a Numeric Value"
else
Msgbox "It is NOT Numeric"
End If
```

#### Slightly upgraded logic

```
Dim a,x,y,z,num
num=Inputbox ("Enter a Phone Number")
d1= left (num,1)
d10=Right (num,1)
d2=mid (num, 2, len (1))
d3=mid (num, 3, len (1))
d4=mid (num, 4, len (1))
d5=mid (num, 5, len (1))
d6=mid (num, 6, len (1))
d7=mid (num, 7, len (1))
d8=mid (num, 8, len (1))
d9=mid (num, 9, len (1))
If len (num) =10 Then
If isnumeric (d1) = "True" and isnumeric (d2) = "True" and isnumeric (d3) = "True" and isnumeric (d4) = "True"and isnumeric (d5) = "True"and isnumeric (d6) = "True"and isnumeric (d7) = "True"and isnumeric (d8) = "True"and isnumeric (d9) = "True"and isnumeric (d10) = "True" Then
msgbox "It is a Numeric Value"
End If
End If
If len (num) <> 10 Then
Msgbox "It is NOT valid Number "
End If
```

### How to read a number and verify that number Range weather in between 1 to 100 or 101 to 1000?

```
Option explicit
Dim a,x
a=Inputbox ("Enter a Vaule")
a=cdbl(a)
If a<= 100 Then
For x= 1 to 100
If a=x Then
msgbox "a is in between 1 to 100 range"
End If
Next
else
For x= 101 to 1000
If a=x Then
msgbox "a is in between 101 to 1000 range"
End If
Next
End If
```

### How to check if a given letter is present in the given String ?

Yes, the interviewer wanted to know if I knew how to use the various Vbscript functions. That is why I needed to code in this way. It is not very efficient though but showed that I knew the VBscript inbuilt functions and how to use them.

```
Dim x
x=Inputbox ("Enter your String")
y=Inputbox ("Enter your search character")
x1=Right(x,1)
x2=Left (x,1)
x3=mid (x,2,Len(1))
x4=mid (x,3,Len(1))
y=len(x)
If y=4 Then
If x1=y or x2=y or x3=y or x4=y Then
msgbox y &" is there"
else
msgbox y &" is Not there"
End If
else
msgbox "Invalid Data"
End If
```

### How to work with MSWORD in UFT?

The below snippet will open a word document and write something and save it as test.doc

```
Dim MyobjWD
Set MyobjWD = CreateObject("Word.Application")
MyobjWD.Documents.Add
MyobjWD.Selection.TypeText "This is some text." & Chr(13) & "This is some more text"
MyobjWD.ActiveDocument.SaveAs "D:test.doc"
MyobjWD.Quit
```

### How to count the number of occurance of a word in a given file?

```
sMyFileName="E:test.txt"
sMyString="hello world"
Const FOR_READING = 1
Dim oFso, oTxtFile, sReadTxt, oRegEx, oMatches
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFso.OpenTextFile(sMyFileName, FOR_READING)
sReadTxt = oTxtFile.ReadAll
Set oRegEx = New RegExp
oRegEx.Pattern = sMyString
oRegEx.IgnoreCase = bIgnoreCase
oRegEx.Global = True
Set oMatches = oRegEx.Execute(sReadTxt)
MatchesFound = oMatches.Count
Set oTxtFile = Nothing : Set oFso = Nothing : Set oRegEx = Nothing
msgbox MatchesFound
```

### How to Compare two test files in UFT?

```
Dim f1, f2
f1="e:test1.txt"
f2="e:test2.txt"
Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read
Str2 = File2.Read
CompareFiles = StrComp(Str1, Str2, 0)
If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop
File1.Close()
File2.Close()
End Function
Call Comparefiles(f1,f2)
If CompareFiles(f1, f2) = False Then
MsgBox "Files are identical."
Else
MsgBox "Files are different."
End If
```

### How to implement Mid Function Without Using String Functions?

I tried to implement the mid function here. What I have done is

1.transfer the string to Array

2.then take the size of the array

3.k is the counter to check if it is equal to strtcut that is which position i need to cut and the length is the variable to understand till how much i need to cut.

```
Sub Macro1()
Call midexplained("Animesh", 2, 2)
'same as mid("Animesh",2,2)
End Sub
Function midexplained(inputq, strtcut, length)
Dim bText() As Byte
Dim j As Integer
j = 0
Dim k As Integer
k = 0
Dim a(999)
Dim n As String
Dim MyString As String: MyString = inputq
bText = MyString
For i = 0 To UBound(bText) - 1
If (bText(i) = 0) Then
Else
a(j) = Chr(bText(i))
j = j + 1
End If
Next
For k = 0 To UBound(a) - 1
If a(k) = "" Then
ElseIf k + 1 >= strtcut And k < ((strtcut + length) - 1) Then
n = n & a(k)
Else
End If
Next
MsgBox "value of n is " & trim(n)
End Function
```

The output for both the variable is the same.

You have to offer away for example an e-book or hold a competition. Two significant

things should be considered when tracing both low quality and high volume joins.

That you need to learn it an individual will apply this strategy soon. Well, I

checked my own account, and it was not listed on the list of articles Got submitted.

Thanks HollisRapke21,

You are free to take up these strategies. I blog as I encourage people to take up these strategies. Secondly I will surely find out a way to list these articles

Regards,

Animesh

I want to hear your triggers for blogging, furthermore the reasons you visit blogs.

When you start to do a search for a niche for business you should

start with something that you know.

Hello SamualHawker27,

I do not follow any niche and micro niche as such, I blog as I love to share. But if you are targetting some area and want to stick to that to get better money out of the advertiser, yes you need to find an niche. There are plenty of videos available in youtube.

Regards,

Animesh

Start performing some abdominal training methods and some strength training exercises a few days 7 days.

A) Give subscribers a very important gift as a reward for giving their email address and details.

Wiith Adobe Photoshop, you will be able to boost or decrease contrast,

brightness, huge, and even color intensity.

Flowers come in a range of colors, and when you addd stems and

vines, you may get an incredible custom tattoo design.

In most cases tthis isn’t an issue as users can order prints completely from

the sharing site.

Thanks , I have just been looking for information approximately this subject for a while and

yolurs is thee best I have foujd oout till now. But, what in regards to

the bottom line? Aree you sure about the source?

Great blog here! Also your web site loads up very fast!

What web host are you using? Can I get your affiliate link to your host?

I wish my website loaded up as fast as yours lol

F*ckin’ remarkable issues here. I am very satisfied to peer your article. Thanks a lot and i am taking a look forward to touch you. Will you kindly drop me a e-mail?

You need to be a part of a contest for one of the greatest blogs on the web.

I will highly recommend this website!

Hello, I would like to subscribe for this weblog to obtain hottest updates, therefore where can i do it please

help out.

What i do not realize is actually how you are no longer really a lot more neatly-appreciated than you might be right now. You’re very intelligent. You recognize thus considerably in terms of this matter, produced me individually consider it from numerous varied angles. Its like men and women are not interested until it is one thing to do with Lady gaga! Your own stuffs excellent. Always maintain it up!

Really appreciate you sharing this article post.Really thank you! Fantastic.

My brother suggested I would possibly like this web

site. He was entirely right. This publish truly made my day.

You cann’t imagine just how much time I had

spent for this information! Thanks!

Attractive element of content. I simply stumbled

upon your site and in accession capital to assert that I get actually loved

account your blog posts. Any way I’ll be subscribing

in your feeds and even I achievement you access persistently quickly.

Wonderful blog! Do you have any suggestions for aspiring writers?

I’m planning to start my own blog soon but I’m a little lost on everything.

Would you suggest starting with a free platform like WordPress or go for a

paid option? There are so many options out there that I’m totally

confused .. Any ideas? Appreciate it!

Nice post. I learn something new and challenging on blogs I stumbleupon everyday.

It’s always helpful to read content from other writers and

practice a little something from their web sites.

Do you mind if I quote a couple of your articles as

long as I provide credit and sources back to your site?

My blog is in the very same niche as yours and my users would

genuinely benefit from a lot of the information you provide here.

Please let me know if this ok with you. Many thanks!

Today, I went to the beach with my kids. I found a sea shell and gave it

to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and

screamed. There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is

totally off topic but I had to tell someone!

Thanks on your marvelous posting! I genuinely enjoyed reading it, you may be a great author.

I will be sure to bookmark your blog and will eventually come back someday.

I want to encourage continue your great work, have a nice day!

Hello to every , for the reason that I am in fact eager of reading

this webpage’s post to be updated on a regular basis.

It includes pleasant stuff.

Heya i’m for the first time here. I came across this board and

I find It truly useful & it helped me out a lot. I hope to give something back and help

others like you aided me.

Yes! Finally something about quest bars cheap.

What’s Happening i’m new to this, I stumbled upon this I’ve discovered It absolutely

useful and it has helped me out loads. I’m hoping to give a contribution & help different users like its

aided me. Good job.

Today, I went to the beach with my kids. I found a sea shell and

gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed

the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

Thanks in favor of sharing such a pleasant thinking,

article is pleasant, thats why i have read it entirely

Hi it’s me, I am also visiting this site

on a regular basis, this site is actually good and the

visitors are actually sharing good thoughts.

Hey, thanks for the article post. Fantastic.

Thank you for every other great article. Where else may just anyone get that kind of information in such an ideal approach of writing?

I have a presentation next week, and I’m at the search for such info.

Say, you got a nice post.Really thank you! Cool.

Im thankful for the article.Really thank you! Will read on…

This is a topic that’s near to my heart… Many thanks! Exactly where are your contact details though?

Have you ever thought about publishing an ebook or guest

authoring on other blogs? I have a blog based upon on the same topics you discuss and would love to

have you share some stories/information. I know my audience would

enjoy your work. If you’re even remotely interested,

feel free to send me an email.

It’s really very difficult in this full of activity life to listen news on TV, so

I simply use the web for that purpose, and obtain the most up-to-date news.

adreamoftrains best web hosting sites

I need to to thank you for this wonderful read!! I absolutely enjoyed

every little bit of it. I have you bookmarked

to look at new things you post…