none
I can't convert String to Textbox. RRS feed

  • Question

  • I'm new here so please give your permission to ask so easy question.

    I tried to Read Text file eace one line,and Show on textbox.

    But, there was an coading error.I couldn't find good information myself so can you give me an ancer to me?

    There's a source code below.

    Public Class Form2
        Public Srtext As New System.IO.StreamReader("Y:\clubs\ルータシミュレータ\minigame_quiz\basical datas\word_list" & Form1.lstflag & ".txt")
        Private Sub Form2_Activated(sender As Object, e As EventArgs) Handles Me.Activated
    
            Label1.Text = "Dificulty:" & Form1.stgflag
            While srtext.peek() > -1
                Me.TextBox1 = srtext.readline()
            End While
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Form1.stgflag = ""
            Hide()
            Form1.Show()
        End Sub
    End Class


    • Edited by SeraphG9 Saturday, May 20, 2017 1:11 AM
    Saturday, May 20, 2017 1:00 AM

Answers

  • But, there was an coading error.I couldn't find good information myself so can you give me an ancer to me?

    The message is literally correct - you can't assign a string to a textbox.  You need to assign the string to the Text property of the textbox

                Me.TextBox1.Text = srtext.readline()

    • Proposed as answer by Devon_Nullman Saturday, May 20, 2017 1:51 AM
    • Marked as answer by SeraphG9 Saturday, May 20, 2017 2:43 AM
    Saturday, May 20, 2017 1:34 AM

All replies

  • I'll show the error below,too.

    I'm using Visual Studio 2013 for Desktop Japanese.

    エラー 1 型 'String' の値を 'System.Windows.Forms.TextBox' に変換できません。 Y:\clubs\ルータシミュレータ\minigame_quiz\WindowsApplication1\WindowsApplication1\Form2.vb 7 27 WindowsApplication1



    • Edited by SeraphG9 Saturday, May 20, 2017 1:07 AM
    Saturday, May 20, 2017 1:06 AM
  • But, there was an coading error.I couldn't find good information myself so can you give me an ancer to me?

    The message is literally correct - you can't assign a string to a textbox.  You need to assign the string to the Text property of the textbox

                Me.TextBox1.Text = srtext.readline()

    • Proposed as answer by Devon_Nullman Saturday, May 20, 2017 1:51 AM
    • Marked as answer by SeraphG9 Saturday, May 20, 2017 2:43 AM
    Saturday, May 20, 2017 1:34 AM
  • I'm new here so please give your permission to ask so easy question.

    I tried to Read Text file eace one line,and Show on textbox.

    But, there was an coading error.I couldn't find good information myself so can you give me an ancer to me?

    There's a source code below.

    Public Class Form2
        Public Srtext As New System.IO.StreamReader("Y:\clubs\ルータシミュレータ\minigame_quiz\basical datas\word_list" & Form1.lstflag & ".txt")
        Private Sub Form2_Activated(sender As Object, e As EventArgs) Handles Me.Activated
    
            Label1.Text = "Dificulty:" & Form1.stgflag
            While srtext.peek() > -1
                Me.TextBox1 = srtext.readline()
            End While
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Form1.stgflag = ""
            Hide()
            Form1.Show()
        End Sub
    End Class


    Hi

    Perhaps I do not understand your question completely.

    Here is some code that will read all the lines of a text file and display in a TextBox.

    ' Form1 with TextBox1
    Option Strict On
    Option Explicit On
    Public Class Form1
    
        ' change this to the path to your file
        Dim myPath As String = "C:\Users\Les\Desktop\Plans\Switch Cortana OFF.txt"
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            With TextBox1
                .Size = New Size(400, 500)
                .Multiline = True
                .ScrollBars = ScrollBars.Vertical
                .Lines = IO.File.ReadAllLines(myPath)
                .SelectionStart = .TextLength
                .SelectionLength = 0
            End With
        End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    Saturday, May 20, 2017 1:36 AM
  • It went well.Thank you a lot!

    Saturday, May 20, 2017 2:44 AM