Solved

Separate strings from a file

Posted on 2000-05-14
9
122 Views
Last Modified: 2010-05-02
I need to read in a text file
containing 4 strings,
each of those strings need to be placed
in 4 separate labels, how do i do that?
0
Comment
Question by:Mean
9 Comments
 

Author Comment

by:Mean
ID: 2808692
Adjusted points from 50 to 70
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2808702
how are the string separated in your text file?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2808713
with a file that looked like this i wrote this up

File ->  
string1 string2 string3 string4

Code ->
1) Add a label to the form and make its index property 0, then paste this code:


Option Explicit

Private Sub Form_Load()
    Const ForReading = 1
    Dim filesys, txtStream As Object
    Dim fileStr As String
    Dim arr As Variant
    Dim i As Integer
    For i = 1 To 3
        Load Label1(i)
        Label1(i).Left = Label1(i - 1).Left
        Label1(i).Top = Label1(i - 1).Top + Label1(i).Height
        Label1(i).Visible = True
    Next
    Set filesys = CreateObject("Scripting.FileSystemObject")
    Set txtStream = filesys.OpenTextFile("C:\mypath\myfile.txt", _
        ForReading)
    fileStr = txtStream.ReadAll
    arr = Split(fileStr)
    For i = 0 To Label1.ubound
        Label1(i).Caption = arr(i)
    Next
End Sub


0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 2808736
Open "Z:\read.txt" For Input As #1
Dim line(5)
For x = 1 To 5
 Line Input #1, line(x)
 Next
Label1.Caption = line(1)
Label2.Caption = line(2)
Label3.Caption = line(3)
Label4.Caption = line(4)
Close
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Expert Comment

by:dreamvb
ID: 2808960
Here hope this might help you out I used an Array of Five Labels

Dim FileNum As Integer
Dim Counter As Integer
Dim StrBuffer As String
On Error Resume Next
FileNum = FreeFile
 Counter = 0
Open "C:\test.txt" For Input As FileNum
 Do While Not EOF(FileNum)
 Input #FileNum, StrBuffer
 Counter = Counter + 1
 Label1(Counter).Caption = StrBuffer
  Loop
  Close #FileNum
0
 

Author Comment

by:Mean
ID: 2808970
Its part of a quiz game,
containing 4 questions
The file would look like this:
Q#3,Text1,Text2,Text3,Text4
or something similar..

Where number 3 is the right question
in the row

Still figuring out a way how
to give the questions a number
so i can use 1 textfile
and doing a random choice
of all the question's in the file

sorry for any spelling mistakes (if any)
i'm dutch..

Thanks for your comments..
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2808973
use the exact same code i posted above except change these lines:


arr = Split(fileStr, ",")
For i = 0 To Label1.ubound
    Label1(i).Caption = arr(i + 1)
Next
0
 

Author Comment

by:Mean
ID: 2809010
Thanks you very much it helped me a lot,
just what it needs to do, nothing more.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 70 total points
ID: 2809030
there is an "Accept comment as Answer" button you can click to accept an answer to this question to move it out of the "Questions waiting to be Answered" area
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now