Results 1 to 5 of 5

Thread: help converting variable declaration (VB2005)

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Question help converting variable declaration (VB2005)

    Hail to All,

    I need help is converting a variable declaration. In VB 6 I used to be able to create a variable like the following.

    Private WatchingKey(1 to 26) as Boolean

    How do I do this now in 2005 as this no longer works.

    Thanks for all your help.

  2. #2
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: help converting variable declaration (VB2005)

    I am not sure what is that supposed to do. Is it an array? of 26 elements starting with 1 instead of zero?

    The simplest thing would be

    vb Code:
    1. Private WatchingKey(25) As Boolean

    which will give you 0 - 25 (or 26 elements)

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2007
    Posts
    63

    Re: help converting variable declaration (VB2005)

    Thanks. Just wanted it to start at 1 not 0 but just have to add an extra elemlnt.

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

    Re: help converting variable declaration (VB2005)

    Arrays all start with 0 in .NET. Just add a +1 to the variable you are using as such.

    Private WatchingKey(25) As Boolean
    Dim i as integer = 0
    '...

    WatchingKey(i + 1) = "Blah"
    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help converting variable declaration (VB2005)

    Quote Originally Posted by Mythos44
    Thanks. Just wanted it to start at 1 not 0 but just have to add an extra elemlnt.
    Don't ever add an extra element to arrays like that. As Rob suggests, arrays are zero-based and you should use them as such. There's never a need for a hack like that. It's all handled smoothly with properly written code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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