none
visual studio 2017 RRS feed

  • Question

  • I am getting an error can someone help me

    Public Class frmHTMLReader
        Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
            WebBrowser.Navigate(txtURL.Text)
        End Sub
        Private Sub btnHtml_Click(sender As Object, e As EventArgs) Handles btnHtml.Click
            txtHTML.Clear()
            txtHTML.Text = WebBrowser.DocumentText
        End Sub
        Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
            Dim fileNum As Integer = FreeFile()
            Dim TempS As String = ""
            Dim TempL As String
            FileOpen(fileNum, "MovieList.txt", OpenMode.Input)
            Do Until EOF(fileNum)
                TempL = LineInput(fileNum)
                TempS = +-TempL + vbCrLf  right here is where the error is.  Cant put string to a double
            Loop
            FileClose()
            txtHTML.Text = TempS
        End Sub
    End Class

    Wednesday, November 13, 2019 1:14 AM

All replies

  • Hello,

    If the file MovieList.txt is a text file where you want lines then use 

    txtHTML.Text = File.ReadAllText("MovieList.txt")

    This is the .NET way while what you have is old Visual Basic 6 way to read a file and in .NET you can't "put a string into a double" Also when appending string it's best to use StringBuilder.

    If you want to perform a read via a loop then this will work.

    Imports for the following code

    Imports System.IO
    Imports System.Text

    Dim sb As New StringBuilder
    Using sr As StreamReader = New System.IO.StreamReader("MovieList.txt")
        While Not sr.EndOfStream
            sb.AppendLine(sr.ReadLine())
        End While
    End Using
    
    txtHTML.Text = sb.ToString()


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, November 13, 2019 2:10 AM
    Moderator
  • Hi,

    Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
            Dim fileNum As Integer = FreeFile()
            Dim TempS As String = ""
            Dim TempL As String
            FileOpen(fileNum, "MovieList.txt", OpenMode.Input)
            Do Until EOF(fileNum)
                TempL = LineInput(fileNum)
                TempS &= TempL & vbCrLf
            Loop
            FileClose()
            txtHTML.Text = TempS
        End Sub

    Using "+" to converse type string to type double is not valid. You can use "&" instead.

    In addition, in another thread, I have provided you with several conversion methods, but you have not responded. If that problem has been solved, I hope you will mark the helpful reply as answer. It will be beneficial to other community.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/39822d54-f377-4fc4-9cce-d12ab29b9965/throwing-an-exception-error?forum=vbgeneral

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 13, 2019 6:28 AM
    Moderator