Results 1 to 12 of 12

Thread: A Dim Question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Question

    Hi all.

    Wouldn't this code Dim strIn as a variant?
    Code:
    Dim strIn, strOut As String
    Thanks.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    Yes, it will.
    -Shickadance

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    ///

    NO

    Simply because it is contained in the one dim statement

    Dim strIn
    that makes it a variant
    Dim strIn,strOut as string
    that makes it a string
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yes, it will
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Unhappy Still Unsure

    So,

    I've received 2 yes's and 1 no! Will someone please give a definitive answer?

    Thanks.

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    YES!!!

    *** comment about posting incorrect replies removed by seaweed because it just seemed too harsh! ***

    If you dim variables with one dim statement, you still must explicitly define the type of each variable in the list. Those that are not explicitly defined will be Variants.

    Here's an easy way to test it. Dim two variables, but only declare the type of the last one. Then try to set each variable to data of another type.

    Guess which variable causes the type mismatch error when you run this:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim var1, var2 As Integer
        
        var1 = "Hello"
        var2 = "Hello"
        
        Unload Me
    End Sub
    Of course it's the second variable, because the first one was automatically typed as a Variant by VB.



    [Edited by seaweed on 07-01-2000 at 03:36 AM]
    ~seaweed

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    SORRY

    seaweed:

    I actually thought I was right!!!!
    If I though I was wrong I wouldn't have posted it.

    I was wrong..I was mistaken... I accept that...I am sorry!

    Life goes on!
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Talking No big deal

    I've done it before too.
    ~seaweed

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    HeSaidJoe, don't worry, we all do that sometimes
    I've seen your posts lately very helpful to people, good work! You might get guru one day
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    thanks.

    thank you...guru isn't the reason I play here..
    I learn more by trying to help others that I did
    in 8 night semesters of VB4,5,6

    Actually, it was one of the teachers as night school
    who said that if you wanted to declare 6 variables
    as string just do Dim 1,2,3,4,5,6 as string..
    obviously....she was wrong.

    All the best,
    Wayne
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  11. #11
    Lively Member
    Join Date
    Jul 2000
    Posts
    72
    Until today I thought that putting multiple variables on one dim line meant that they were all the same also. I tested it and found out that it was not so.

    One of my professors was wrong also it seems

    VB 6 Professional Edition

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Cool Thanks.

    To everyone for your input.

    It seems that VB teachers can't be trusted! Except the "teachers" who frequent this Forum of course.

    All the best.

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