Results 1 to 5 of 5

Thread: declaration of variable problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    declaration of variable problem

    Hello

    I am having a problem with the following code
    VB Code:
    1. Dim numAvailableSlotsDL,numslotsDLTx As Integer

    the code throws up an error saying that
    Compiel error:
    byref argument type mismatch


    and the only way to correct it is by writing the definitions as

    VB Code:
    1. Dim numAvailableSlotsDL As Integer
    2. Dim numslotsDLTx As Integer

    what is the wrong with the first version of my code, i.e.

    VB Code:
    1. Dim numAvailableSlotsDL,numslotsDLTx As Integer

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

    Re: declaration of variable problem

    First off, the second way is always prefereble IMO. It is much clearer.

    However, if you really really want to declare more than one variable on a single line (which drives me buggy ), then do
    VB Code:
    1. Dim intVar As Integer, intVar1 As Integer, intVar2 As Integer
    Etcetera

  3. #3
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: declaration of variable problem

    Quote Originally Posted by vb_student
    VB Code:
    1. Dim numAvailableSlotsDL, numslotsDLTx As Integer
    If I remember correctly, VB interprets the first variable as a variant because the type isn't specified.

  4. #4
    PowerPoster Simply Me's Avatar
    Join Date
    Aug 2003
    Posts
    2,748

    Re: declaration of variable problem

    Your memory serves you well schoolbusdriver
    To give is always to be NOBLE...
    To received is always to be BLESSED....
    Each day strive to be NOBLE
    Each day strive to be BLESSED

    If this post has helped you. Please take time to rate it.

    >=|+|=< Simply Me >=|+|=<

    ----------------------------------------
    Connection Strings | Number Only in Textbox | Splash Screen with Progress Bar | Printing to 1/2 of perforated bond paper |
    Freeze 2005 DataGridView Column

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

    Re: declaration of variable problem

    Quote Originally Posted by schoolbusdriver
    If I remember correctly, VB interprets the first variable as a variant because the type isn't specified.
    Aside from the fact that I think declaring each variable individually, on a separate line, makes for far more clarity, this is another reason why I don't line mulitple variables declarations stretched out across one, single, line.

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