DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Book problem.. INT VS. SINGLE

  1. #1
    CodeZombie Guest

    Book problem.. INT VS. SINGLE


    Hi recently after checking my homework I missed one question I thought I was
    gonna get right.. so here it is:
    Private Sub cmdDisplay_Click()
    Rem blah blah blah..
    Call Sentence(168, "hour", "a week")
    Vall Sentence(76, "trombone", "the week big parade")
    End Sub
    Private Sub Sentence(num as single, thing as string, where as string)
    picOutput.Print num; thing; "s in "; where

    I know this program is like for retarted people and I get it and everything
    but I have a question.. why da heck is this working.. and it does I have
    spend my free time hard coding this crap in.. and found out that it does
    work.. but why wouldn't it give you a mismatch error it goes from integer
    to a single.. what I have heard is that VB stores 168 as 168.00000000000000000000
    and thats why its all weird.. and it doesn't give you an error. Then what
    is the point of singles... where you can use doubles and integers, and throw
    singles out..the only thing I can come up with is the memory managment..
    other then that...? I don't know.. I guess somebody was really bored one
    day and came up with this idea.. haha yay!

    Please tell me what you think about it.. all responses are welcome..





  2. #2
    Michael Culley Guest

    Re: Book problem.. INT VS. SINGLE

    what I have heard is that VB stores 168 as 168.00000000000000000000

    No, vb will store 168 as 168 if you define it as integer. In your example
    the 168 isn't defined explicitly so vb can choose how it defines it. I
    believe in this situation it must choose single.

    If you do this

    dim x as long
    Call Sentence (x ....)

    you will get an error

    --
    Michael Culley
    www.vbdotcom.com

    "CodeZombie " <nikhasmessege@yahoo.com> wrote in message
    news:3aa5b34f$1@news.devx.com...
    >
    > Hi recently after checking my homework I missed one question I thought I

    was
    > gonna get right.. so here it is:
    > Private Sub cmdDisplay_Click()
    > Rem blah blah blah..
    > Call Sentence(168, "hour", "a week")
    > Vall Sentence(76, "trombone", "the week big parade")
    > End Sub
    > Private Sub Sentence(num as single, thing as string, where as string)
    > picOutput.Print num; thing; "s in "; where
    >
    > I know this program is like for retarted people and I get it and

    everything
    > but I have a question.. why da heck is this working.. and it does I have
    > spend my free time hard coding this crap in.. and found out that it does
    > work.. but why wouldn't it give you a mismatch error it goes from integer
    > to a single.. what I have heard is that VB stores 168 as

    168.00000000000000000000
    > and thats why its all weird.. and it doesn't give you an error. Then what
    > is the point of singles... where you can use doubles and integers, and

    throw
    > singles out..the only thing I can come up with is the memory managment..
    > other then that...? I don't know.. I guess somebody was really bored one
    > day and came up with this idea.. haha yay!
    >
    > Please tell me what you think about it.. all responses are welcome..
    >
    >
    >
    >




  3. #3
    CodeZombie Guest

    Re: Book problem.. INT VS. SINGLE


    Hey Mike, no you won't you see thats what I thought too... but no..
    you have to assume they put Option Explicit up at the top so they assume
    you know its there.. Question is if you send 168(not a variable), when you
    recieve it x as single.. wouldn't it give you an error cause 168 as I look
    at it is an integer don't you guys see it as an integer too? in that case
    why doesn't it give you an error.


    Private Sub cmdDisplay_Click()
    >> Rem blah blah blah..
    >> Call Sentence(168, "hour", "a week")
    >> Vall Sentence(76, "trombone", "the week big parade")
    >> End Sub
    >> Private Sub Sentence(num as single, thing as string, where as string)
    >> picOutput.Print num; thing; "s in "; where


    see 168 is no variable... I find this stupid.. maybe because I am dumb
    or something.. but I just don't understand why wouldn't it give you an error
    Please tell me what you think
    All responses are welcome











    "Michael Culley" <mike@vbdotcom.com> wrote:
    >what I have heard is that VB stores 168 as 168.00000000000000000000
    >
    >No, vb will store 168 as 168 if you define it as integer. In your example
    >the 168 isn't defined explicitly so vb can choose how it defines it. I
    >believe in this situation it must choose single.
    >
    >If you do this
    >
    >dim x as long
    >Call Sentence (x ....)
    >
    >you will get an error
    >
    >--
    >Michael Culley
    >www.vbdotcom.com
    >
    >"CodeZombie " <nikhasmessege@yahoo.com> wrote in message
    >news:3aa5b34f$1@news.devx.com...
    >>
    >> Hi recently after checking my homework I missed one question I thought

    I
    >was
    >> gonna get right.. so here it is:
    >>
    >> I know this program is like for retarted people and I get it and

    >everything
    >> but I have a question.. why da heck is this working.. and it does I have
    >> spend my free time hard coding this crap in.. and found out that it does
    >> work.. but why wouldn't it give you a mismatch error it goes from integer
    >> to a single.. what I have heard is that VB stores 168 as

    >168.00000000000000000000
    >> and thats why its all weird.. and it doesn't give you an error. Then what
    >> is the point of singles... where you can use doubles and integers, and

    >throw
    >> singles out..the only thing I can come up with is the memory managment..
    >> other then that...? I don't know.. I guess somebody was really bored one
    >> day and came up with this idea.. haha yay!
    >>
    >> Please tell me what you think about it.. all responses are welcome..
    >>
    >>
    >>
    >>

    >
    >



  4. #4
    Arthur Wood Guest

    Re: Book problem.. INT VS. SINGLE


    CodeZombie --In the future, please use your real name, as stupid "handles"
    are considered very Rude, and many of us are seriously considereing NOT responding
    to a question from a Cute Handle.

    Option Explicit has ABSOLUTELY NOTHING to do with your question. Option
    Explicit ONLY requires the VARIABLES must be declared before they are used.
    In the line you showed, you are passing a VALUE (not a VARIABLE), and the
    type of that VALUE is not specified.

    However, since VB passes arguments ByRef ( by reference), when you supply
    a VALUE (168 or 17), VB will do an IMPLICIT type-cast of the value provided
    to the Type of the argument in the Procedure Declaration. In this case,
    VB will convert the 168 to a Single. If you had declared a VARIABLE of type
    Integer, assigned it the value 168 and called the Procedure with THAT VARAIBLE,
    you would have gotten an error.


    Arthur Wood

    "CodeZombie" <nikhasmessege@yahoo.com> wrote:
    >
    >Hey Mike, no you won't you see thats what I thought too... but no..
    >you have to assume they put Option Explicit up at the top so they assume
    >you know its there.. Question is if you send 168(not a variable), when you
    >recieve it x as single.. wouldn't it give you an error cause 168 as I look
    >at it is an integer don't you guys see it as an integer too? in that case
    >why doesn't it give you an error.
    >
    >
    >Private Sub cmdDisplay_Click()
    >>> Rem blah blah blah..
    >>> Call Sentence(168, "hour", "a week")
    >>> Vall Sentence(76, "trombone", "the week big parade")
    >>> End Sub
    >>> Private Sub Sentence(num as single, thing as string, where as string)
    >>> picOutput.Print num; thing; "s in "; where

    >
    >see 168 is no variable... I find this stupid.. maybe because I am dumb
    >or something.. but I just don't understand why wouldn't it give you an error
    >Please tell me what you think
    >All responses are welcome
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >"Michael Culley" <mike@vbdotcom.com> wrote:
    >>what I have heard is that VB stores 168 as 168.00000000000000000000
    >>
    >>No, vb will store 168 as 168 if you define it as integer. In your example
    >>the 168 isn't defined explicitly so vb can choose how it defines it. I
    >>believe in this situation it must choose single.
    >>
    >>If you do this
    >>
    >>dim x as long
    >>Call Sentence (x ....)
    >>
    >>you will get an error
    >>
    >>--
    >>Michael Culley
    >>www.vbdotcom.com
    >>
    >>"CodeZombie " <nikhasmessege@yahoo.com> wrote in message
    >>news:3aa5b34f$1@news.devx.com...
    >>>
    >>> Hi recently after checking my homework I missed one question I thought

    >I
    >>was
    >>> gonna get right.. so here it is:
    >>>
    >>> I know this program is like for retarted people and I get it and

    >>everything
    >>> but I have a question.. why da heck is this working.. and it does I

    have
    >>> spend my free time hard coding this crap in.. and found out that it does
    >>> work.. but why wouldn't it give you a mismatch error it goes from integer
    >>> to a single.. what I have heard is that VB stores 168 as

    >>168.00000000000000000000
    >>> and thats why its all weird.. and it doesn't give you an error. Then

    what
    >>> is the point of singles... where you can use doubles and integers, and

    >>throw
    >>> singles out..the only thing I can come up with is the memory managment..
    >>> other then that...? I don't know.. I guess somebody was really bored

    one
    >>> day and came up with this idea.. haha yay!
    >>>
    >>> Please tell me what you think about it.. all responses are welcome..
    >>>
    >>>
    >>>
    >>>

    >>
    >>

    >



  5. #5
    mrfelis Guest

    Re: Book problem.. INT VS. SINGLE

    CodeZombie <nikhasmessege@yahoo.com> wrote in message
    news:3aa62c4e$1@news.devx.com
    > you know its there.. Question is if you send 168(not a variable), when you
    > recieve it x as single.. wouldn't it give you an error cause 168 as I look


    168 is a constant. When it is passed to a function VB is free to convert the
    constant as seen fit. It can be any data type other than an object.

    The following code will also work without error:

    Option Explicit

    Private Sub test(i As Integer)
    Print i
    End Sub

    Private Sub Form_Click()
    test 123.456
    test 123.9
    End Sub


    --
    ~~~
    !ti timda I ,KO
    ..em deppals nocaeB sivaM
    !draH
    ~~
    C'Ya,
    mrfelis@yahoo!com




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center