Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: If you could give 1 tip, what would it be?

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    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.
    Kanna

  2. #2
    Fanatic Member
    Join Date
    Jun 2001
    Location
    Oregon
    Posts
    643

    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

  3. #3
    Lively Member
    Join Date
    Apr 2007
    Posts
    122

    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.

  4. #4
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: If you could give 1 tip, what would it be?

    Quote 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:
    1. Option Explicit On 'VB.NET!

  5. #5
    Addicted Member TBeck's Avatar
    Join Date
    Apr 2006
    Location
    Ontario, Canada
    Posts
    254

    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.

  6. #6
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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!)

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: If you could give 1 tip, what would it be?

    Moved

  8. #8

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: If you could give 1 tip, what would it be?

    Always have Option strict on
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: If you could give 1 tip, what would it be?

    Don't re-invent the wheel.
    Martin J Wallace (Slaine)

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: If you could give 1 tip, what would it be?

    Use the right tool for the job.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: If you could give 1 tip, what would it be?

    Always know what you are going to do before you do it.

  13. #13
    Fanatic Member bgmacaw's Avatar
    Join Date
    Mar 2007
    Location
    Atlanta, GA USA
    Posts
    524

    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.

  14. #14
    Addicted Member MasterBlaster's Avatar
    Join Date
    Jul 2002
    Location
    Seattle
    Posts
    196

    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

  15. #15

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Re: If you could give 1 tip, what would it be?

    Quote Originally Posted by penagate
    Use the right tool for the job.
    Can you brief ?
    Kanna

  16. #16
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  17. #17
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  18. #18
    Lively Member Arty2000's Avatar
    Join Date
    Nov 2006
    Location
    Australia
    Posts
    100

    Re: If you could give 1 tip, what would it be?

    The old classic... Do a regular back up of your files.

  19. #19
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: If you could give 1 tip, what would it be?

    Quote 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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  21. #21
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: If you could give 1 tip, what would it be?

    Don't use floating point variable for storing money related data.

  22. #22
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: If you could give 1 tip, what would it be?

    Quote Originally Posted by Merrion
    Don't use floating point variable for storing money related data.
    Bad experience?

  23. #23

  24. #24
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  25. #25
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: If you could give 1 tip, what would it be?

    How do you feel about decimal types?
    My usual boring signature: Nothing

  26. #26
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: If you could give 1 tip, what would it be?

    Quote 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.

  27. #27
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  28. #28
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: If you could give 1 tip, what would it be?

    Quote 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.

  29. #29
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: If you could give 1 tip, what would it be?

    Quote 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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  30. #30
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  31. #31
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  32. #32

  33. #33
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  34. #34
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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.

  35. #35
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  36. #36
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  37. #37

  38. #38
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: If you could give 1 tip, what would it be?

    Quote 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.

  39. #39
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: If you could give 1 tip, what would it be?

    Quote 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

  40. #40
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    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.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width