Answered One line Ifs

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
Hello, I am slowly converting all my If's to 1 liners, does this improve exectution spead? IMO it makes it easier to read.

I am also wondering, is it possible to execture more than one sub or function, e.g. show 2 messages boxes instead of 1 in this 1 liner:

VB.NET:
If Me.Text = "Pie" Then MsgBox("Hello")

Such as:

VB.NET:
If Me.Text = "Pie" Then MsgBox("Hello"), Msgbox("Erm, yeah..")


Thanks a bunch, folks!
 
Last edited:
IMO it makes it worse to read. It doesn't change execution speed because there in no change in code instructions. Did you know you can put ":" between statements to put them on same line? That way you can write your whole application in a single line. Alas, also bad to read.
 
As a question to a question, correct me if I am wrong. Would it reduce the amount of written code?
No, using the single line version makes you type more, ie you have to type "If clause Then", while for the multiline version you just type "If clause" and press Enter and the code editor finishes the code structure by inserting "Then" and "End If".
 
Back
Top