VB.NET Interview Questions and Answers (91) - Page 1

How to find data with generics list in VB.NET (Write code).

In the code example below, the function “FindData” will return list(“sublist”) of the objects having matchingKey same as viewstate value.

Dim sublist As List(Of MyClass)

sublist = allClient.FindAll(AddressOf FindData) ‘sublist will contain objects matching specified matching condition

Function FindData(ByVal b As MyClass) _
As Boolean
If (b.matchingKey = CInt(ViewState("matchingKey "))) Then ‘matching condition
Return True
Return False
End If
End Function

How to deal with return value of stored procedure when you are using DataReader ?

To deal with such scenario, you can find “ParameterDirection.ReturnValue”.
You can use this parameter direction to read the return value of the stored procedure.
Following example can make it more clearer.
In case, you have following or similar type of return statement somewhere in your stored procedure.
Return -999

To read this value, following code works,
Dim result As Integer = 0

Dim retValParam As New SqlClient.SqlParameter("@RETURN_VALUE", SqlDbType.Int)
retValParam.Direction = ParameterDirection.ReturnValue
result = retValParam.Value ‘ here the result must contain the returned value. In this case, it will be -999

Bhakti Shah
Which Keyword is used in VBScript to increase or decrease the counter variable by the value?

NOTE: This is objective type question, Please click question title for correct answer.
How to assign font to label at run-time in vb.net ?

Label1.Font.Size = 12
Label1.Font.Name = "Broadway"
How to assign width to label/button/textbox in vb.net ?

With some scenarios you need to assign width to the controls rubtime. Generally we tend to make it soecified with percentage. At runtime we can use following way to make such assignments.

Label1.Width = Unit.Percentage(12.12)

You can have “pixel” or “point” as measurement unit and get your desired result set.
Have you ever used IIF? Explain.

Sometimes, you need to bind data using ternary functions from code file. With VB, you can achieve this thing using IIF function.

For an example, here in code below at the time of databinding I need to check value of “testString”. If the value is null/empty string it shows “NA” else the value.

<%#IIf(String.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "testString")), "NA", DataBinder.Eval(Container.DataItem, " testString "))%>

You can achieve the same result from code behind by placing appropriate code in itemdatabound method.(if applicable)
DateTime variables can be null.

NOTE: This is objective type question, Please click question title for correct answer.
What is “fix” ?

Fix is a function available in VB, which returns integer part of the number.
Difference between Fix and Int.

Both of them returns integer part of the provided number. Difference lies, how they deal with the negative numbers.
Fix returns the first negative integer greater than or equal to provided Number while Int returns the first negative integer less than or equal to provided Number.
For an example,
Int(-99.2)  ' Returns -100.

Fix(-99.2) ' Returns -99.

Write output: Dim testString = "TestingStringHere" Mid(testString, 5) = "..Bore.."

Justification : here we have used is MID statement not the MID function.
What is difference between Mid function and Mid Statement ?

Mid function returns the characters while the Mid statement replaces the characters.
What is difference between String.Substring and MID function?

Said both performs the same type of operation on string. The basic difference lies, how they indice the string characters.

In case, if you have got string "TEST", the MID function will indice the characters as 1,2,3,4. But with String.substring they will be indiced as 0,1,2,3.
With Visual Basic Runtime, NOTHING gets evaluated as,

NOTE: This is objective type question, Please click question title for correct answer.
What is VAL function?

This function is used to return integer part contained in the string argument.
It stops reading further as soon as first invalid character is recognized.
Valid characters for this function are: Blanks, tabs, and linefeed characters,
radix prefixes &O (for octal) and &H (for hexadecimal) and period(.)

test = Val(" 1 2 3         4") ' Returns 1234

test = Val("1 cannot be 2") 'Returns 1

To reverse a string which function is used in VB.NET?

StrReverse(String):- This function reverse the specified string.

Dim Str,RStr As String
Which method is used to delete a file in VB.NET?

Kill(File name with path) :- This method deletes the said file/files from the disk. The name of the file
to be deleted is passed to this method as string type arguments. Files are simply deleted and not moved to recycle-bin. The use of wild card(* and /) is permitted in this function.

This will delete the file abc.txt locates in C:\Files\

This will delete all the files with .txt extension from C:\Files\
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories