|
-
Dec 23rd, 2004, 11:20 PM
#1
Thread Starter
Hyperactive Member
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:
Dim strArr(1 To 10) As Integer
Public Sub Form_Load()
strArr() = Array("404933", "165425", "907356", "992437", "665768", "541879", "509990", "203261", "255631", "108982")
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.
-
Dec 23rd, 2004, 11:33 PM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 23rd, 2004, 11:37 PM
#3
Member
Re: Arrays
Hi ,
Declare the strArr as variant datatype.
Refer the below code
VB Code:
Dim strArr()
strArr() = Array("404933", "165425", "907356", "992437", "665768", "541879", "509990", "203261", "255631", "108982")
MsgBox strArr(0)
-
Dec 23rd, 2004, 11:40 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 23rd, 2004, 11:43 PM
#5
Re: Arrays
... OR ...
VB Code:
Private Sub Command1_Click()
Dim strValues$
Dim arNumbers() As String
strValues = "404933,165425,907356,992437,665768,541879,509990,203261,255631,108982"
arNumbers = Split(strValues, ",")
Debug.Print arNumbers(1)
End Sub
-
Dec 23rd, 2004, 11:53 PM
#6
Thread Starter
Hyperactive Member
Re: Arrays
Thanks for all the help, works perfect.
-
Dec 29th, 2004, 05:24 AM
#7
Member
Re: Arrays
 Originally Posted by RhinoBull
... OR ...
VB Code:
Private Sub Command1_Click()
Dim strValues$
Dim arNumbers() As String
strValues = "404933,165425,907356,992437,665768,541879,509990,203261,255631,108982"
arNumbers = Split(strValues, ",")
Debug.Print arNumbers(1)
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
-
Dec 29th, 2004, 08:34 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|