-
Oct 3rd, 2014, 10:48 PM
#1
Thread Starter
Junior Member
Accessing Array Elements
I don't know why, but I can't seem to figure this out, it doesn't make any sense to me.
I create an array like this...
Code:
Dim strArray() as String
Dim strContents as String
strContents = joe,john,jimmy
strArray = Split(strContents, ",")
How do I access each element in the array I try this...
txtName.Text = strArray(0)
and I get script out of range or something. I tried strArray(1) and I get the same thing. Can vb6 not directly access the elements? Every tutorial I see online only teaches how to display the elements with a for loop. I can't find a single tutorial that teaches how to just access one element when needed.
What am I doing wrong here?
-
Oct 3rd, 2014, 11:27 PM
#2
Re: Accessing Array Elements
You have to use "s to assign the data to the string
Code:
Dim strArray() as String
Dim strContents as String
strContents = "joe,john,jimmy"
strArray = Split(strContents, ",")
Text1.Text=strArray(1)
-
Oct 3rd, 2014, 11:51 PM
#3
Thread Starter
Junior Member
Re: Accessing Array Elements
I figured it out, sorry for the thread. I first was using the wrong array I had another array with almost the same name. Stupid me for not making my arrays way different in name. The second thing I was doing wrong was using commas since when reading from a text file it will only read till the first comma. I am using : instead and it works great even reading the contents from a file.
-
Oct 4th, 2014, 12:45 AM
#4
Re: Accessing Array Elements
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 4th, 2014, 01:34 AM
#5
Re: Accessing Array Elements
You can read commas from a text file just fine, you just need to do it differently.
Input # will read up to a comma or a line break assuming of course that the comma is not contained within "s in which case it is considered part of the data and will be read.
Line Input # reads a full line up to a line break, commas included.
There are other methods that can read any number of bytes up to the entire file at once.
You just need to use the right method for the job at hand.
-
Oct 4th, 2014, 06:45 AM
#6
Frenzied Member
Re: Accessing Array Elements
How do I access each element in the array I try this...
txtName.Text = strArray(0)
following way you can access each of the element
Code:
Private Sub Form_Load()
Dim strArray() As String
Dim strContents As String
strContents = "joe,john,jimmy" 'it is string so it needs to be in ""
strArray = Split(strContents, ",")
Text1 = strArray(0)
Text2 = strArray(1)
Text3 = strArray(2)
End Sub
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
|