loading html or txt file to visual basic program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mhie
    New Member
    • Jul 2012
    • 1

    loading html or txt file to visual basic program

    hello! i just wanna ask on how to load an html or txt file from a certain monitoring software(specif ically commView for WiFi) to VB programming language?

    TnX a lot:)
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    these are some examples how you can load a file:
    1) IF you want to select a file:

    Code:
    Private Function Open_File()
    Dim STRTEMP As String
       TextBox.Text = ""
       On Error GoTo Cancel_Function
       With CommonDialog
          .CancelError = True
          .Filter = "Text (.txt)|*.txt"
          .InitDir = Environ$("USERPROFILE") & "\My Documents"
          .DialogTitle = "Open a file..."
          .ShowOpen
          On Error GoTo Error_Open_File
          Open .FileName For Input As #1
             Do Until EOF(1)
                Input #1, STRTEMP
                TextBox.Text = TextBox.Text & STRTEMP
             Loop
          Close #1
          Caption = Left(Caption, 26) & ": " & .FileName
       End With
       CMDunix2dos.Enabled = True
       TEXTCHANGED = False
       CMDsave.Enabled = True
       CMDsaveAs.Enabled = True
       MnuFile(2).Enabled = True
       MnuFile(3).Enabled = True
    Exit Function
    Error_Open_File:
       Close #1
       MsgBox "There is an error opening the file"
    Exit Function
    Cancel_Function:
    End Function
    2) directly:

    Code:
    Dim FF As Long
    Dim TotalFile As String
        CommonDialog1.ShowOpen
         FF = FreeFile
        Open CommonDialog1.FileName For Binary As #FF
        '  Allocate a buffer equal in size to the file
        '  (see LOF function) so that the Get statement
        '  can stuff text from the file into it.
        TotalFile = Space(LOF(FF))
        Get #FF, , TotalFile
        Close #FF
        Text1.Text = TotalFile
    3) If the file is always on the same place

    Code:
    Private Sub Form_Load()
    Dim FileIn As Integer
       FileIn = FreeFile
       On Error GoTo Error_Laden
       Open App.Path & "\document.txt" For Input As #FileIn
          Do While Not EOF(FileIn)
             Input #FileIn, inputdata
             TEXTBLOCK = TEXTBLOCK & inputdata & vbCrLf
          Loop
       Close #FileIn
          Text2.Text = TEXTBLOCK
    Exit Sub
    Error_Laden:
       Close #FileIn
       MsgBox ("Error loading !")
    End Sub
    Or binary

    Code:
    Private Sub Command1_Click()
       Dim Fle$, L&, Channel%, S$
    
       Fle$ = "c:\t\test.txt"
       L = FileLen(Fle$)
    
       S$ = Space$(L)
    
       Channel = FreeFile
       Open Fle$ For Binary Access Read As #Channel
       Get #Channel, 1, S$
       Close #Channel
    
    End Sub

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Can you be more specific about what you want to do with the file? For example, do you simply want to copy the contents of the file into a text box?

      Comment

      Working...