|
-
Apr 9th, 2007, 04:38 PM
#1
Thread Starter
Hyperactive Member
If you could give 1 tip, what would it be?
So, there are loads of tips on this forum, which would you reccomend somone to do. Mine is "Always use Option Explicit on all your forms, modules, etc."
Please try not to repeat the same tip twice. Say what works for you.
-
Apr 9th, 2007, 05:38 PM
#2
Fanatic Member
Re: If you could give 1 tip, what would it be?
I would tell people to use variable names that make sence to the variables purpose in life, and indent their work to make it easy to read and understand. sorry thats 2
-
Apr 9th, 2007, 05:41 PM
#3
Lively Member
Re: If you could give 1 tip, what would it be?
I would tell people to stop using an obsolete language, and to use VB.NET instead, where you don't have to set Option Explicit and your work is automatically indented.
-
Apr 9th, 2007, 07:55 PM
#4
Re: If you could give 1 tip, what would it be?
 Originally Posted by stettybet0
I would tell people to stop using an obsolete language, and to use VB.NET instead, where you don't have to set Option Explicit and your work is automatically indented. 
VB Code:
Option Explicit On 'VB.NET!
-
Apr 9th, 2007, 07:58 PM
#5
Addicted Member
Re: If you could give 1 tip, what would it be?
always comment your code... especially if it is a large project.
The extra little effort now will save you a lot of time later on.
-
Apr 9th, 2007, 08:01 PM
#6
Re: If you could give 1 tip, what would it be?
Use Watches to debug Objects, learn to find and use VB Native Constants, Use TAB Key to Indent (It's much easier to write/read!)
-
Apr 10th, 2007, 06:37 AM
#7
Re: If you could give 1 tip, what would it be?
-
Apr 10th, 2007, 07:46 AM
#8
Re: If you could give 1 tip, what would it be?
Try to keep it simple - doesn't matter the language.
Don't write the functions or even classes when all you need to do is A = B + C.
-
Apr 10th, 2007, 08:44 AM
#9
Re: If you could give 1 tip, what would it be?
Always have Option strict on
-
Apr 10th, 2007, 09:20 AM
#10
Fanatic Member
Re: If you could give 1 tip, what would it be?
Don't re-invent the wheel.
Martin J Wallace (Slaine)
-
Apr 10th, 2007, 10:18 AM
#11
Re: If you could give 1 tip, what would it be?
Use the right tool for the job.
-
Apr 10th, 2007, 10:56 AM
#12
Re: If you could give 1 tip, what would it be?
Always know what you are going to do before you do it.
-
Apr 10th, 2007, 11:50 AM
#13
Re: If you could give 1 tip, what would it be?
Know your 'audience'.
Developers often forget their users and their needs and come up with bells and whistles that feed their ego but don't do their users much good. For example, one POS system I saw in operation had a cutesy cash register opening sound, kind of a "Thank You for shopping at QuickieMart" with a jingle in the background. It was very annoying and it could not be turned off. I think if the programmer had been there the clerks would have strangled him.
Of course, it may have been a marketing or operations manager who came up with that bit of nonsense. Which leads to the second part of my tip, make sure your project sponsor knows the audience and be brave enough to challenge questionable ideas.
-
Apr 10th, 2007, 02:49 PM
#14
Addicted Member
Re: If you could give 1 tip, what would it be?
Spend 70% of your time researching and planning and 30% programming so you don't end up spending twice as much time fixing bugs and coding yourself into corners.
"And most of the evils of society can, in fact, be cured through information. We have a society that has been disinformed and based on the disinformation has made irrational choices. And that's what I mean by 'ignorance.' People, who ordinarily might be smart, are deprived of the data by which to make a rational decision, don't have the data to do it."
Frank Zappa
-
Apr 17th, 2007, 01:10 PM
#15
Thread Starter
Hyperactive Member
Re: If you could give 1 tip, what would it be?
 Originally Posted by penagate
Use the right tool for the job.
Can you brief ?
-
Apr 17th, 2007, 01:20 PM
#16
Re: If you could give 1 tip, what would it be?
I always code a couple of lines or a small sub/func and then step through it to see how it functions - examining variables and such.
So basically - code and debug at the same time, test small portions - don't write a whole program and debug it at the end!
-
Apr 18th, 2007, 05:51 AM
#17
Re: If you could give 1 tip, what would it be?
Just because a lot of people are doing things incorrectly doesn't make it right. It just makes a lot of people wrong.
-
Apr 18th, 2007, 08:48 AM
#18
Lively Member
Re: If you could give 1 tip, what would it be?
The old classic... Do a regular back up of your files.
-
Apr 18th, 2007, 02:37 PM
#19
Re: If you could give 1 tip, what would it be?
 Originally Posted by RhinoBull
Try to keep it simple - doesn't matter the language.
Don't write the functions or even classes when all you need to do is A = B + C.
I agree with Rhino.
But for complex/large projects if you feel a piece of code can be used in some other parts of your program or moving a few line into a function will icrease readability....do so.
I prefer to break my code into as many functions as I can. But those functions must be 'logically independent' or they must be reusable.
Place correct error handeling code in all those functions and debugging will be a lot easier.
-
Apr 18th, 2007, 02:38 PM
#20
Re: If you could give 1 tip, what would it be?
Search the forums first or read the FAQ threads before posting on "How to ....." something
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 01:36 AM
#21
Re: If you could give 1 tip, what would it be?
Don't use floating point variable for storing money related data.
-
Apr 19th, 2007, 01:40 AM
#22
Re: If you could give 1 tip, what would it be?
 Originally Posted by Merrion
Don't use floating point variable for storing money related data.
Bad experience?
-
Apr 19th, 2007, 08:37 AM
#23
Re: If you could give 1 tip, what would it be?
 Originally Posted by Merrion
Don't use floating point variable for storing money related data.
Why not? I don't suppose you suggest to use Strings...
-
Apr 19th, 2007, 08:51 AM
#24
Re: If you could give 1 tip, what would it be?
Floating point for money tracking systems is evil - I know that from first hand experience myself.
The inherent inaccuracies when doing math on float's leads to loss of precision.
-
Apr 19th, 2007, 09:13 AM
#25
Re: If you could give 1 tip, what would it be?
How do you feel about decimal types?
My usual boring signature: Nothing
 
-
Apr 19th, 2007, 09:42 AM
#26
Re: If you could give 1 tip, what would it be?
 Originally Posted by szlamany
Floating point for money tracking systems is evil - I know that from first hand experience myself.
The inherent inaccuracies when doing math on float's leads to loss of precision.
... and the solution is ... Perhaps you tell us.
-
Apr 19th, 2007, 10:00 AM
#27
Re: If you could give 1 tip, what would it be?
In VB6 we used currency data type - which as you know is really an integer type with an implied decimal point.
Never had to use decimal types - but I believe they supercede currency in .Net - right?
On mainframes we used STRING arithmetic - with 60 places of precision.
Isn't floating point imprecision well known to programmers?? Stuff like you divide 16 by 4 and get 3.9999 (a silly example - might not be one that actually happens).
From a link I just found:
I love how people keep going on about various types of rounding, even though they make no sense to the actual problem here.
Here's what his roundTo function does:
-Inputs are a number to round and the number of digits to round it to.
-First, it figures out a multiplier. This will be 10 ^ digits. It calls this 'factor'.
-It multiplies the number by factor in order to move the digits to the left of the decimal point.
-Adding .5 at this point is supposed to do the round operation. If it already had .5 or more in the fractional part, this would cause the integer to round up. This is where the failure happens, of course.
-Finally, it truncates off the fractional part (that's what Int() does), and divides by the factor to move the decimal back up.
The failure is that it's doing this not to actual decimal numbers, but to floating point numbers. As has been pointed out already, 39.995 cannot be represented exactly in that limited space, and you actually get 39.994998931884766. When you do the math on that, you get:
39.9949989 * 100 = 3999.49989
3999.49989 + 0.5 = 3999.99989
Int(3999.999) = 3999
3999 / 100 = 39.99
So your rounding fails for certain cases. This can't actually be completely fixed using floating point numbers. Limited size floating point numbers simply cannot represent some parts of the number line in the same way that limited size decimals can't either (0.333... = 1/3). Yes, adding more than .5 (like .501) would work, but it would make the answers wrong for some other chunk of the numbers.
If you're doing your math in base 10, use a different representation. Visual Basic has a Decimal data type for this very reason (which I think uses a BCD format internally). Most other languages have something similar.
http://worsethanfailure.com/Comments...and_Round.aspx
and more...
http://docs.sun.com/source/806-3568/ncg_goldberg.html
and more...
http://blogs.msdn.com/oldnewthing/ar...16/634078.aspx
did you tell your friend that he should be using the Decimal type? It would allow him to add .01 about 10^28 times before losing precision. Anybody doing arithmetic with monetary figures should be using it.
-
Apr 19th, 2007, 11:56 AM
#28
Re: If you could give 1 tip, what would it be?
 Originally Posted by szlamany
Isn't floating point imprecision well known to programmers?? Stuff like you divide 16 by 4 and get 3.9999[/url]
It has nothing to do with "floating point imprecision" but rather VB's using Banker's rounding algorithm which was always a problem.
-
Apr 19th, 2007, 11:59 AM
#29
Re: If you could give 1 tip, what would it be?
 Originally Posted by RhinoBull
It has nothing to do with "floating point imprecision" but rather VB's using Banker's rounding algorithm which was always a problem.
I don't agree - but I see no point in discussing this further - the links I posted can be reviewed by those interested in how floating point differs from decimal and currency.
-
Apr 19th, 2007, 12:01 PM
#30
Re: If you could give 1 tip, what would it be?
IEEE floats are approximations at best, due to the way they are stored (mantissa/exponent); decimal/currency types are simply integers with a few bits to denote the decimal place. Floating-point maths is thus inherently imprecise in any language.
-
Apr 19th, 2007, 12:22 PM
#31
Re: If you could give 1 tip, what would it be?
The one tip I would give is not to ask programmers the difference between floating point, decimal and currency types
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 12:28 PM
#32
Re: If you could give 1 tip, what would it be?
 Originally Posted by RobDog888
The one tip I would give is not to ask programmers the difference between floating point, decimal and currency types 
I like it.
-
Apr 19th, 2007, 04:47 PM
#33
Re: If you could give 1 tip, what would it be?
But keeping it serious for a moment - here's a simple example of the difference between DOUBLE and CURRENCY as far as precision.
I cut out some of the output - as it only turns to garbage at the 52nd iteration.
Issues like this are real - from years of interest and pension and payroll calculations - I've got battle scars from debugging and fixing other peoples code.
Code:
Private Sub Form_Load()
Dim SomeValue As Double
Dim OtherValue As Currency
SomeValue = 1
OtherValue = 1
For x = 1 To 60
SomeValue = SomeValue + 0.1
OtherValue = OtherValue + 0.1
Debug.Print x
Debug.Print SomeValue / 10
Debug.Print OtherValue / 10
Next x
End Sub
in the immediate window you get...
Code:
1
0.11
0.11
2
0.12
0.12
3
0.13
0.13
4
0.14
0.14
5
0.15
0.15
.
.
.
50
0.6
0.6
51
0.61
0.61
52
0.619999999999999
0.62
53
0.629999999999999
0.63
54
0.639999999999999
0.64
55
0.649999999999999
0.65
56
0.659999999999999
0.66
57
0.669999999999999
0.67
58
0.679999999999999
0.68
59
0.689999999999999
0.69
60
0.699999999999999
0.7
-
Apr 19th, 2007, 07:00 PM
#34
Re: If you could give 1 tip, what would it be?
So what are you trying to say? I really don't understand.
The fact that double is more presize number than currency which is nothing else but rounded double using Bankers rounding algorithm?
Handle properly your double precision point and you'll be just fine.
But saying that it's "imprecise" isn't quite "presize" definition I'm afraid.
Your decimals and currency could give you incorrect results if not proprly handled.
The bottom line is "learn to handle with the precision you need" rather than complaining about the incorrect output.
I really don't understand the point behind these arguments.
Sorry.
-
Apr 19th, 2007, 07:05 PM
#35
Re: If you could give 1 tip, what would it be?
rb - I showed a double value being divided by 10 that produced this value
0.619999999999999
and that's the problem.
No rounding involved in my example.
No bankers rounding.
Floating point simply cannot represent all values - since it's a binary representation as opposed to a decimal representation.
This isn't a VB6 issue - I've encountered it in all programming languages and platforms.
-
Apr 19th, 2007, 07:21 PM
#36
Re: If you could give 1 tip, what would it be?
Excel also does not handle precise calculations well at all either. But when you really need precision its still the same, use the best tool (data types) for the situation whether its currency, double, integer etc. Just dont try to use String
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 19th, 2007, 07:27 PM
#37
Re: If you could give 1 tip, what would it be?
 Originally Posted by RobDog888
.... Just dont try to use String 
I agree.
-
Apr 19th, 2007, 07:59 PM
#38
Re: If you could give 1 tip, what would it be?
 Originally Posted by szlamany
rb - I showed a double value being divided by 10 that produced this value
0.619999999999999
and that's the problem.
No rounding involved in my example.
No bankers rounding.
Floating point simply cannot represent all values - since it's a binary representation as opposed to a decimal representation.
This isn't a VB6 issue - I've encountered it in all programming languages and platforms.
Yes, I saw that. The "problem" is that "0.1" is already rounded number so is Currency. Double returns "presize" floating number so it needs to be handled.
If Currency works for you then use it - I don't ever as it has a lot more problems (in VB at least) than any other numeric data type. Nor I ever use decimal type.
-
Apr 19th, 2007, 08:08 PM
#39
Re: If you could give 1 tip, what would it be?
 Originally Posted by RhinoBull
Yes, I saw that. The "problem" is that "0.1" is already rounded number so is Currency. Double returns "presize" floating number so it needs to be handled.
If Currency works for you then use it - I don't ever as it has a lot more problems (in VB at least) than any other numeric data type. Nor I ever use decimal type.
Never had a problem with decimal.
My usual boring signature: Nothing
 
-
Apr 19th, 2007, 10:47 PM
#40
Re: If you could give 1 tip, what would it be?
The best programs you'll ever write are the ones you never thought you'd be able to do.
Last edited by sevenhalo; Apr 19th, 2007 at 10:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|