Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42412

[RESOLVED] Open a common dialog box to choose a txt file to load to a listbox

$
0
0
Hello everyone. I am updating a web scrapper and right now I keep all the links I scrap in a txt file, but for various websites I have various txt files, so I would like to modify if possible, a block of code from an earlier project where a common dialog box is opened and the user picks a txt file and the txt file is loaded into an array of textboxes. I would like to modify it so instead of being loaded into text boxes, it is loaded into a listbox.

Here is the old code.

VB Code:
  1. Private Sub Open_Click()
  2. '
  3. ' Requires a Microsoft Common Dialog Control drawn on the form
  4. ' Named cd
  5. '
  6. Dim strData As String
  7. Dim strQ() As String
  8. Dim intI As Integer
  9. Dim intFile As Integer
  10. '
  11. ' Set up the Common Dialog initial Directory
  12. ' to the application path. Filter for Text and All files
  13. ' Prompt the user to select a file
  14. '
  15. cd.InitDir = App.Path
  16. cd.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
  17. cd.DialogTitle = "Select Question File"
  18. cd.ShowOpen
  19. If cd.FileName <> "" Then
  20.     '
  21.     ' If the user selected a file
  22.     ' open and read the entire contents
  23.     ' then split it into records
  24.     '
  25.     intFile = FreeFile
  26.     Open cd.FileName For Input As intFile
  27.     strData = Input(LOF(intFile), intFile)
  28.     Close intFile
  29.     strQ = Split(strData, vbNewLine)
  30.     '
  31.     ' Populate the texbox array with the questions
  32.     ' (either the number of textboxes in the control array or
  33.     ' number of questions, which ever is the smaller)
  34.     '
  35.     Do
  36.         CustomQ(intI).Text = strQ(intI)
  37.         intI = intI + 1
  38.     Loop Until intI > CustomQ.UBound Or intI > UBound(strQ)
  39. End If
  40. End Sub

As you can see the CustomQ is the name of the boxes, but the name of the list is called WebsiteList. Would this just be a matter of loading a textfile to a listbox where the Do Loop begins? or would it end up loading it over and over in the same listbox? I don't need it to load more than once. lol :) Thanks!

Viewing all articles
Browse latest Browse all 42412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>