vb scripts programs - interview questions
' Reverse a string using mid function in vb script
'str,strrev,ch,i,l
str = inputbox("enter string")
l = Len(str)
For i = l To 1 Step -1
ch = Mid(str,i,1)
strrev = strrev & ch
Next
msgbox strrev
' mid function returns the characters or string
cba
2.How to use fix function in vb script
'Use of fix() function in vb script
'It will convert floating numbers to integers
a=fix(68.4)
msgbox a
b=fix(-68.4)
msgbox b
-68
3.How to use rnd() function in vb script
'Use of rnd() function in vb script
'The Rnd function generates a random number greater than or equal to 0.0 and less than 1.0.
x=rnd()
y=rnd()
msgbox x&" and "&y
i=rnd(68)
j=rnd(-68)
msgbox i&" and "&j
o/p:
0.705 and 0.502
Dim intMax, iLoop, k, intValue, strChar, strName, intNum
' Specify the alphabet of characters to use.
Const Chars = "abcdefghijklmnopqrstuvwxyz"
' Specify length of names.
intMax = 5
' Specify number of names to generate.
intNum = 3
'Randomize()
For iLoop = 1 To intNum
strName = ""
For k = 1 To intMax
' Retrieve random digit between 0 and 25 (26 possible characters).
intValue = Fix(26 * Rnd())
' Convert to character in allowed alphabet.
strChar = Mid(Chars, intValue + 1, 1)
' Build the name.
strName = strName & strChar
Next
Wscript.Echo strName
Next
uatvs
dihbn
iplmj
edjfb
1. Reverse a string using mid function in vb script
'str,strrev,ch,i,l
str = inputbox("enter string")
l = Len(str)
For i = l To 1 Step -1
ch = Mid(str,i,1)
strrev = strrev & ch
Next
msgbox strrev
' mid function returns the characters or string
O/P :
abccba
2.How to use fix function in vb script
'Use of fix() function in vb script
'It will convert floating numbers to integers
a=fix(68.4)
msgbox a
b=fix(-68.4)
msgbox b
O/P:
68-68
'Use of rnd() function in vb script
'The Rnd function generates a random number greater than or equal to 0.0 and less than 1.0.
x=rnd()
y=rnd()
msgbox x&" and "&y
i=rnd(68)
j=rnd(-68)
msgbox i&" and "&j
o/p:
0.705 and 0.502
4.Generate random names using vb script
Dim intMax, iLoop, k, intValue, strChar, strName, intNum
' Specify the alphabet of characters to use.
Const Chars = "abcdefghijklmnopqrstuvwxyz"
' Specify length of names.
intMax = 5
' Specify number of names to generate.
intNum = 3
'Randomize()
For iLoop = 1 To intNum
strName = ""
For k = 1 To intMax
' Retrieve random digit between 0 and 25 (26 possible characters).
intValue = Fix(26 * Rnd())
' Convert to character in allowed alphabet.
strChar = Mid(Chars, intValue + 1, 1)
' Build the name.
strName = strName & strChar
Next
Wscript.Echo strName
Next
o/p:
snphhuatvs
dihbn
iplmj
edjfb
No comments:
Post a Comment