I have 2 text files named
sQue.txt containing single words in each lines (each word in each line) and
sObj.txt also containing single word in each line (but no. of entries are more in this file than in sQue.txt).
Now, I have a blank form in which I want to read both the above files & display them in a manner such that:<ol><li>
Each entry from sQue.txt file gets displayed in separate labels in the form</li> <li>
All the entries of file sObj.txt are put in a CheckedListBox & this CheckedListBox appears for each label displayed in point 1. above.</li> </ol>
sObj.txt contains 3 entries aaa, bbb & ccc (vertically i.e each in new line).
sQue.txt contains 5 entries p,q,r,s & t (vertically i.e each in new line).
Now, when the form loads, 3 labels are seen with texts aaa, bbb & ccc. Also 3 CheckedListBoxes are seen containg
p,q,r,s & t in each box.
Can it be done? I'm trying to find a solution with no luck yet.
Till now all I have is
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim queue As String() = IO.File.ReadAllLines("C:\temp\sQue.txt") Dim objects As String() = IO.File.ReadAllLines("C:\temp\sObj.txt") For i = 0 To queue.Count - 1 'create labels here For j=0 to objects.Count - 1 'create CheckedListBoxes Next Next End SubAnswer1:
It is easily done:
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim theAppDirectory = IO.Path.GetDirectoryName(Application.ExecutablePath) Dim queue As String() = IO.File.ReadAllLines(theAppDirectory & "\que.txt") Dim objects As String() = IO.File.ReadAllLines(theAppDirectory & "\obj.txt") Dim top As Integer = 10 Dim left As Integer = 10 Dim I As Integer = 0 Dim J As Integer = 0 Dim aLabel As Label Dim aListCheckBox As CheckedListBox Dim aPanel As New Panel aPanel.Dock = DockStyle.Fill aPanel.Top = 0 aPanel.Left = 0 aPanel.AutoScroll = True For I = 0 To queue.Count - 1 aLabel = New Label aLabel.Text = queue(I) aLabel.Top = top aLabel.Left = left aListCheckBox = New CheckedListBox aListCheckBox.Top = top aListCheckBox.Left = left + 100 For J = 0 To objects.Count - 1 aListCheckBox.Items.Add(objects(J), False) top += 20 Next J 'add event handlers here aPanel.Controls.Add(aLabel) aPanel.Controls.Add(aListCheckBox) Next I Me.Controls.Add(aPanel) End Sub
This assumes that you want the files to be in the same directory as the executable.
Also no event handlers are added. You will need to determine what event handlers you want and add them when you create the controls.