Results 1 to 8 of 8

Thread: Arrays

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397

    Resolved Arrays

    I get an error "Cant assign to array" with the following code, ive never used arrays before, and this is one of my first attempts to

    VB Code:
    1. Dim strArr(1 To 10) As Integer
    2.  
    3. Public Sub Form_Load()
    4. strArr() = Array("404933", "165425", "907356", "992437", "665768", "541879", "509990", "203261", "255631", "108982")
    5. End Sub

    But it get that one error as mentioned above, what is the problem?
    Last edited by Narfy; Dec 23rd, 2004 at 11:53 PM.

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

    Re: Arrays

    Array: Returns a Variant containing an array.
    Declare a variant and then assign the elements.

    Code:
    Option Explicit
    
    Dim strArr As Variant
    
    Public Sub Form_Load()
        strArr = Array("404933", "165425", "907356", "992437", "665768", "541879", "509990", "203261", "255631", "108982")
        MsgBox strArr(3)
    End Sub
    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

  3. #3
    Member
    Join Date
    Apr 2004
    Location
    Chennai,India
    Posts
    40

    Re: Arrays

    Hi ,
    Declare the strArr as variant datatype.
    Refer the below code

    VB Code:
    1. Dim strArr()
    2. strArr() = Array("404933", "165425", "907356", "992437", "665768", "541879", "509990", "203261", "255631", "108982")
    3. MsgBox strArr(0)

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

    Re: Arrays

    rameshk, you need to type faster.
    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
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Arrays

    ... OR ...
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strValues$
    3. Dim arNumbers() As String
    4.  
    5.     strValues = "404933,165425,907356,992437,665768,541879,509990,203261,255631,108982"
    6.     arNumbers = Split(strValues, ",")
    7.     Debug.Print arNumbers(1)
    8.  
    9. End Sub

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397

    Re: Arrays

    Thanks for all the help, works perfect.

  7. #7
    Member
    Join Date
    May 2003
    Posts
    53

    Re: Arrays

    Quote Originally Posted by RhinoBull
    ... OR ...
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim strValues$
    3. Dim arNumbers() As String
    4.  
    5.     strValues = "404933,165425,907356,992437,665768,541879,509990,203261,255631,108982"
    6.     arNumbers = Split(strValues, ",")
    7.     Debug.Print arNumbers(1)
    8.  
    9. End Sub

    The above example works perfect for single dimensional array , How is it possible to do the same example for array (2,12) etc.
    Syed Nadeemulla Hussaini
    # I-2,C & FM Quater
    Hutti Gold Mines Co Ltd.
    Raichur Karnataka
    INDIA

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Arrays

    Sorry for late reply.
    See my sample in this thread .

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