40553

Dynamic reading from file & displaying on form load

Question:

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>

Example:

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.

Please help.

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 Sub

Answer1:

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.

Recommend

  • How to get CheckedListBox.checkedItems as a stringlist
  • update table from another table in db2 9
  • Join two tables with SUM and COUNT
  • Creating multiple XML files & folders with XSLT
  • Iteratively (or recursively?) filter directory and copy results to new directory
  • SAS replace character in ALL columns
  • php array count in with dynamic result
  • Is there a way to decide when a RhinoMocks mock starts recording?
  • MFMailComposer not working in io6 landscape mode
  • Regex: how to get \\b to work with utf-8 charset?
  • Editing PDF from Java Using PDFBox
  • PHP replace preceding substrings of some other substring
  • MongoDb Pipeline Aggregation sorting sub sub documents
  • mysql what is the right syntax for this conditional update statement
  • How to order or choose rows in MySQL GROUP BY clause?
  • Class initialization parens to use
  • Show outbound texts using SMSManager in the default android text application
  • checking file size in a remote server using python, SSH
  • How to execute a shell script through python
  • MongoDB: How to Sort a Query Before Updating
  • QT: set stylesheet for a QMenu object
  • Why does adding overflow: hidden make the child element's margin work?
  • Add custom information to HockeyApp crash report
  • Get row for each user where the count of a value in a column is maximum
  • Color a heatmap in Python/Matplotlib according to requirement
  • Anybody have any idea how the divs are emitted in pinterest.com?
  • Performance difference between accessing local and class member variables
  • Creating a layer of gradient within an SVG path dynamically
  • jParallax trouble
  • CSS how to fix an element to scroll horizontally with the page but not vertically?
  • Ionic Slide Up Slide Down Animation for only one view in sidebar
  • Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no
  • Differences in dis-assembled C code of GCC and Borland?
  • Loading .coffee files via a view in Rails
  • Swift: Switch statement fallthrough behavior
  • Get one-time binding to work for ng-if
  • Is there any way to access browser form field suggestions from JavaScript?
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Controls, properties, events and timers running in design time
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo