Results 1 to 11 of 11

Thread: [RESOLVED] Why should I use certain data types?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    7

    Resolved [RESOLVED] Why should I use certain data types?

    Hi, I just wanna ask you some quick question: Why should I use string, integer or decimal? What's so good about them?

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Why should I use certain data types?

    Quote Originally Posted by Xardasster View Post
    Hi, I just wanna ask you some quick question: Why should I use string, integer or decimal? What's so good about them?
    In what case are you referring to?
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3
    Fanatic Member
    Join Date
    Sep 2005
    Location
    Toledo, OH
    Posts
    785

    Re: Why should I use certain data types?

    a variable stored as a String datatype will return any character as text

    a variable stored as an integer datatype will return a number positive or negative as high as the bit used. default is 32 bit and returns a number from −2,147,483,648 to +2,147,483,647 signed and 0 to +4,294,967,295 unsigned.

    Double is much like integer accept it allows the use of decimals.

    "Double variables are stored as signed IEEE 64-bit (8-byte) double-precision floating-point numbers ranging in value from -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values and from 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values." -MSDN article on Double Datatypes.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    7

    Re: Why should I use certain data types?

    Well, I'm currently working on a program which needs some bit of text to be outputted in a listbox. Also the program should do any calculations if needed. I have already declared variables for my textboxes and combo boxes to a string but I need a reason why it was the best choice. I have also used integers for counting several items - need reason why it was the best choice. As for the decimals, the program should do calculations for each item I choose from a combo box list or by simply checking the boxes - also need why decimal was the best choice.

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Why should I use certain data types?

    Quote Originally Posted by Xardasster View Post
    Well, I'm currently working on a program which needs some bit of text to be outputted in a listbox. Also the program should do any calculations if needed. I have already declared variables for my textboxes and combo boxes to a string but I need a reason why it was the best choice. I have also used integers for counting several items - need reason why it was the best choice. As for the decimals, the program should do calculations for each item I choose from a combo box list or by simply checking the boxes - also need why decimal was the best choice.
    I'm not sure I understand what you're talking about. You don't have a choice. If you want to store a string, you use a string. If you want to store a whole number, you use an integer, so on and so on.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Why should I use certain data types?

    If the data could contain non-numeric text (or numbers with extra leading 0's), you need to use a String - because numeric data types only hold numbers.

    If the data is purely numeric then using the right data type saves memory, increases speed, and reduces the chances of errors. Which of the numeric data types you should use depends on the data (it is no good using Integer for numbers with decimal places, or Byte for numbers larger than 255).

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    7

    Re: Why should I use certain data types?

    Quote Originally Posted by weirddemon View Post
    I'm not sure I understand what you're talking about. You don't have a choice. If you want to store a string, you use a string. If you want to store a whole number, you use an integer, so on and so on.
    I knew that the question is little awkward... Anyways I just wanted to know why integer is good to store text, why decimal to do calculations and so on. Maybe simple information on these types would help.

    P.S Thanks si_the_geek we're getting there

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Why should I use certain data types?

    Why do you wear pants, or shorts? Couldn't you just use a shirt as well? Would you use a hammer to put in a screw (properly I might add)? While the alternatives work, they are not the best tool for the job.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Why should I use certain data types?

    Quote Originally Posted by Xardasster View Post
    Anyways I just wanted to know why integer is good to store text, why decimal to do calculations and so on
    First, you wouldn't store text in a variable declared as an integer. Text is generally a string, so you'd use a string.

    As for doing calculations, that's not relevant. You'd use a decimal variable to do calculations if there are decimals involved. You'd use integers if integers are involved, etc.
    Last edited by weirddemon; Dec 3rd, 2009 at 02:59 PM.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  10. #10
    Hyperactive Member BadgerBadger's Avatar
    Join Date
    Aug 2009
    Location
    Wales
    Posts
    382

    Re: Why should I use certain data types?

    You can't store text in integers. They are strictly for whole numbers, however you can convert integers to text (strings).
    Decimals can include decimals, which is good when you expect the result to be a non-whole number.
    "The only thing that interferes with my learning is my education."

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    7

    Re: Why should I use certain data types?

    Mmokay... Thanks for your help guys, I can always count on you
    Thread Resolved.

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