|
-
Feb 17th, 2007, 05:51 AM
#1
Thread Starter
New Member
From text file to array?
When I write to a text file, it looks like this:
Code:
"45674576","45674567","thedate","testing"
When reading the text file, how am I able to make what's between the first "" in a variable, second "" and so on? (I want to load one into a text box, one into a label, drop down menu etc).
Thanks guys.
-
Feb 17th, 2007, 06:07 AM
#2
Re: From text file to array?
VB Code:
Option Explicit
Private Sub Command1_Click()
Dim sFileText As String
Dim sArray() As String
'Assign the fileText context to SFileText
sArray = Split(sFileText, ",") 'split the content of the file with
'Respect to '
'Add the splited text to combo box
Combo1.AddItem Mid(sArray(0), 2, length(sArray(0).Text) - 1)
'Mid(sArray(0), 2, length(sArray(0).Text) - 1= will get the text between " "
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Feb 17th, 2007, 06:12 AM
#3
Thread Starter
New Member
Re: From text file to array?
Forgive my n00bness here.
Code:
Dim sFileText As String
Dim sArray() As String
Open FileLoc & jobNum & ext For Input As #1
'Assign the fileText context to SFileText
sArray = Split(sFileText, ",") 'split the content of the file with
'Respect to '
'Add the splited text to combo box
Combo1.AddItem Mid(sArray(0), 2, length(sArray(0).Text) - 1)
'Mid(sArray(0), 2, length(sArray(0).Text) - 1= will get the text between " "
Close #1
End Sub
I am getting sarray as invalid qualifier.
-
Feb 17th, 2007, 06:20 AM
#4
Re: From text file to array?
Replace length with Len and remove .Text:
VB Code:
Combo1.AddItem Mid(sArray(0), 2, [B]Len[/B](sArray(0)) - 1)
@danasegarane: are you drunk from Java or something?
-
Feb 17th, 2007, 06:25 AM
#5
Re: From text file to array?
Try this
VB Code:
Private Sub Command1_Click()
Dim sFileText As String
Dim i As Long
Dim sArray()
sFileText = FileText("Filename with path") 'Get the file text
'Assign the fileText context to SFileText
sArray = Split(sFileText, ",") 'split the content of the file with
'Respect to '
'Add the splited text to combo box
If UBound(sArray) > 0 Then 'If anything found in the array
For i = LBound(sArray) To UBound(sArray) 'Loop through the array and add the text
Combo1.AddItem Mid(sArray(i), 2,[B] Len[/B](sArray(i).Text) - 1)
'Mid(sArray(0), 2, length(sArray(0).Text) - 1= will get the text between " "
Next
End If
End Sub
Function FileText(ByVal filename As String) As String
'Function to get the filecontents into a string
Dim handle As Integer
' ensure that the file exists
If Len(Dir$(filename)) = 0 Then
Err.Raise 53 ' File not found
End If
' open in binary mode
handle = FreeFile
Open filename$ For Binary As #handle
' read the string and close the file
FileText = Space$(LOF(handle))
Get #handle, , FileText
Close #handle
End Function
Edit:Sorry Gavio.It is mistake only
Last edited by danasegarane; Feb 17th, 2007 at 06:53 AM.
Please mark you thread resolved using the Thread Tools as shown
-
Feb 17th, 2007, 06:33 AM
#6
Thread Starter
New Member
Re: From text file to array?
I am still getting the same error. I think you're over complicating this (no offense I appreciate the help!).
Basically I don't want to worry about what's being done with the text just yet. What I want to do is:
open text file.
read data into array.
array[0] = first part of text.
array[1] = second.
array[2] = third.
array[2] = forth.
labelone.caption = array[1]
etc.
From there I can do whatever I want with them, print etc.
Sorry to be a pain, but your code is just frustrating me, you're obviously at a lot higher level than I am!
-
Feb 17th, 2007, 06:38 AM
#7
Re: From text file to array?
Change the line
to
it will work
Please mark you thread resolved using the Thread Tools as shown
-
Feb 17th, 2007, 06:43 AM
#8
Thread Starter
New Member
Re: From text file to array?
More errors. End If without If. For without Next, mismatch... list goes on :/
-
Feb 17th, 2007, 06:53 AM
#9
Re: From text file to array?
I have edited my previous post.Pls check it
Please mark you thread resolved using the Thread Tools as shown
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
|