Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vb.net if shorthand

Tags:

is there a way to use shorthand to do something like this?

If Not txtBookTitle.Text = String.Empty Then   objBook.DisplayName = txtBookTitle.Text End If 
like image 268
SkyeBoniwell Avatar asked Mar 13 '13 19:03

SkyeBoniwell


People also ask

How do you write if else in Visual Basic?

Syntax of Visual Basic If Else Statement Following is the sample example of using the If Else statement in a visual basic programming language. If you observe the above example, whenever the defined condition (x >= 10) returns true, the If condition will be executed; otherwise, the Else block of code will be executed.

How do I write an if statement in Visual Studio?

In Visual Basic, If statement is useful to execute the block of code or statements conditionally based on the value of an expression. Generally, in Visual Basic, the statement that needs to be executed based on the condition is known as a “Conditional Statement” and the statement is more likely a block of code.

Is nothing then Visual Basic?

For strings in Visual Basic, the empty string equals Nothing . Therefore, "" = Nothing is true. If you declare a variable without using an As clause and set it to Nothing , the variable has a type of Object . An example of this is Dim something = Nothing .

Is null in VB?

The IsNull function returns a Boolean value that indicates whether a specified expression contains no valid data (Null). It returns True if expression is Null; otherwise, it returns False.


1 Answers

objBook.DisplayName = If(Not (txtBookTitle.Text = String.Empty), txtBookTitle.Text, objBook.DisplayName) 
like image 102
Mike Corcoran Avatar answered Sep 19 '22 15:09

Mike Corcoran