Posted By

alexishawn on 02/16/12


Tagged


Versions (?)

Open and Read File


 / Published in: Visual Basic
 

  1. OpenFileDialog:
  2. 'will return the absolute path of the file to upload
  3. FileToRead = Application.GetOpenFilename(, , "Find File", , False)
  4.  
  5. If Not ((FileToRead = "False") Or (FileToRead = "")) Then
  6.  
  7. '================ On first loop through file, check water controls ===================
  8.  
  9. Open FileToRead For Input As #1
  10. Do While Not EOF(1)
  11.  
  12. ReadALine:
  13. Line Input #1, LineRead
  14.  
  15. If LineRead = "" Then
  16. GoTo ReadALine
  17. Else
  18. 'Put in stuff to do to the line of data here
  19. End If
  20.  
  21. Loop
  22.  
  23. close #1
  24. 'This happens if the user presses Cancel when they are trying to open a file to read
  25. Else
  26. ans = MsgBox("You must select a file to read for the program to continue." & VbCrLf & VbCrLf & _
  27. "Please select a file an try again.", vbOKCancel + vbInformation, "No File Selected")
  28. If ans = vbCancel Then
  29. MsgBox "The program is stopped."
  30. Exit Sub
  31. Else
  32. GoTo OpenFileDialog
  33. End If
  34.  
  35. End If

Report this snippet  

You need to login to post a comment.