Read / Write VBA

squiresk

New Member
Joined
Jun 24, 2008
Messages
10
Hi,

Quick question.

Does anyone else find it easier to write VBA than to read it?

(and comprehend).



Kai.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I find it much easier to write VBA than to read it (unless I am the one who previously wrote the code). The reason why is because I know exactly what each line is referencing to and the like. However, almost everything I have learned about VBA has come from picking apart other people's coding from these forums.
 
Generally yes, but it definitely depends who wrote the VBA, whether they use the same naming conventions (if they use any!) as I do, and whether they bothered commenting any of it! I also find it much harder when people use the colon to put multiple instructions on one line.
 
You can use a colon to put more than one instructions on each line?!? Now I can further obfuscate my code to complicate my life several years down the road when I attempt to decipher it! :biggrin:
 
Even better is to put lots of comments in but never change them when you change the code - gets really confusing, really fast! :)
 
Ah, my favorite code obfusication method(I read about it in some wacky guide), was to use a nondescriptive varilable, like "i", and use it as a totally different variable, depending on the scope you are looking at it.
 
My favourite is when the code hasn't been indented, or indented weirdly.:)

And to understand code it's always nice to actually have an idea of it's purpose.

Oh, and then there's the (non) use of code tags.:evil:
 
Ah, my favorite code obfusication method(I read about it in some wacky guide), was to use a nondescriptive varilable, like "i", and use it as a totally different variable, depending on the scope you are looking at it.

Code:
Sub CONFUSING()
Dim i as Integer, LR as Integer, currenttime as Integer, panda as Integer
i = Range("A" & rows.count).End(xlUp).Row
'This will insert a new row at potato
currenttime = Sheets.count
'Insert a sheet counter here
For LR = 2 to i
    For panda = 1 to currenttime
        sheets(panda).Cells(LR,panda).Value = ""
        'Populates the cell
    Next panda
Next LR
End Sub
 
My favourite is when the code hasn't been indented, or indented weirdly. And to understand code it's always nice to actually have an idea of it's purpose.

descriptive identification of data item.
I'm often 'fixing' others work and have to deal with the following:
iCount
R
cnt
Field3TXT

Come on, how hard is it to write out the shortest identifier?
 
I'm a lot better with naming variables compared to when I started writing VBA. I was taught FORTRAN as my first computer language, and the person teaching me had a convention of using "i" for outer loop counter, "j" for next level loop, "k" for the next, and so on for "l", "m", and "n" ... and I was writing like that for many years, and was still the same when I started with VBA.

I guess people write the way that they are used to, and without taking into account readability. I am trying much harder these days, even though I am the only one ever likely to look at the code.
 

Forum statistics

Threads
1,222,653
Messages
6,167,367
Members
452,111
Latest member
NyVmex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top