English 中文(简体)
VB/VBA Variable Declaration Coding Standard - White Space
原标题:

What is the significance of declaring variables in VB/VBA like so:

Private m_sName         As String
Private m_lAge          As Long

As opposed to;

Private m_sName As String
Private m_lAge As Long

I am working on a project which up to now uses the latter, and has done since long before I joined the project. Two new developers have joined the team and have begun to use the former. I have seen such pagination previously and wondered; what is its heritage and what advantages/disadvantages does it have? My own preference has always been the latter and remains so, as much for consistency as anything else.

最佳回答

In the days when code editors were much dumber and were little more the text editors it was easier to maintain the "column-style" (the former example) of code. However even then it could be a pain when changes would require manual re-orginisation of code.

But then intellisense and auto-formatting came along and made it really difficult to maintain the "column-style" formatting code. Change something in the line and the IDE automatically eliminated "unnecessary" white-space.

I m all for readability but not to this extent, stick with latter style.

问题回答

It s only a matter of readability. Multiple whitespaces in VB/VBA are ignored.

I d use the former because it s more readable, but Visual Studio has its own formatting rules and will remove extra whitespaces, so I have to use the second form. :)

This is a coding convention from old C-days, where you had endless structs and you wanted to see the types and variable names starting in the same column. Do as you prefer!

Easier to read, in my opinion. You can clearly see the variable name and type in the former, whilst the latter becomes more difficult with more variable declarations.





相关问题
Prevent windows from queuing shellexecute requests

Win.ShellExecute 0, "open", "C:dirprogram.exe", "arguments", vbNullString, SW_SHOWNORMAL Win.ShellExecute 0, "open", "http://www.google.com", vbNullString, vbNullString, SW_SHOWNORMAL I want google....

Why is My Loop Only Deleting One File?

Using VB6 In a folder, i have n number of files, i want to delete a 0 kb files code Dim filename5 As String filename5 = Dir$(txtsourcedatabasefile & "*_*", vbDirectory) MsgBox filename5 Do ...

How to check the filesize?

Using VB6 I have the text file with different sizes, so i want to delete the file where filesize = 0 kb. How to make a vb6 code for deleting the 0 kb files. Need vb6 code Help

File Rename problem?

I m using VB6 and I have a folder where I have n number of files. I want to change the file extension to .txt. I used the code below to change the extension of all .fin files to .txt. Dim filename1 ...

Error 20728-F while in using Crystal Reports in VB6

I m using Crystal Reports in my VB6 project, but I m facing error while loading the report in crystalreport1.action=1; Please give me some solution for this problem. It is showing the error as Error ...

DllRegisterServer entry point was not found

When running my vb6 application I am getting error like, runtime error 53 : file not found: rscomclNoMsg.dll then i tried to register that dll from cmd line using regsvr32. Then I am getting ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签