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
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.
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? :D
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
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!
Re: From text file to array?
Change the line
to
it will work
Re: From text file to array?
More errors. End If without If. For without Next, mismatch... list goes on :/
Re: From text file to array?
I have edited my previous post.Pls check it