Results 1 to 2 of 2

Thread: TextBox again. I have no way out!!!

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    49

    Question TextBox again. I have no way out!!!

    Dear friends,
    I have a problem that I don't know how to solve it. I want to load a text file's content (just one line) in to a textbox. I tried to do it many times with many ways, but I failed. This is my code:

    VB Code:
    1. Dim readFile As New StreamReader(variable.dataPath & "\" & variable.monthView & variable.yearView & variable.MST & variable.Loai & variable.Method & ".txt")
    2.  
    3.  Dim temp As String
    4.         Try
    5.             temp = readFile.ReadLine
    6.             RefFrm.frmDoanhThuVATTNDN.txtDT11.Text = temp
    7.         Catch ex As Exception
    8.             MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    9.         End Try
    10.  
    11.         readFile.Close()


    VB Code:
    1. 'this is a class, to make form DoanhThuVATTNDN globally
    2. Private Shared p_frmDoanhThuVATTNDN As frmDoanhThuVATTNDN
    3. Public Shared Property frmDoanhThuVATTNDN() As frmDoanhThuVATTNDN
    4.         Get
    5.             Return p_frmDoanhThuVATTNDN
    6.         End Get
    7.  
    8.         Set(ByVal Value As frmDoanhThuVATTNDN)
    9.             p_frmDoanhThuVATTNDN = Value
    10.         End Set
    11.  
    12.     End Property

    Or

    VB Code:
    1. Dim readFile As New StreamReader(variable.dataPath & "\" & variable.monthView & variable.yearView & variable.MST & variable.Loai & variable.Method & ".txt")
    2.  
    3.  Dim temp As String
    4. dim form as new frmDoanhThuVATTNDN
    5.         Try
    6.             temp = readFile.ReadLine
    7.             form.txtDT11.Text = temp
    8.         Catch ex As Exception
    9.             MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    10.         End Try
    11.  
    12.         readFile.Close()

    Although it could load textfile content into the variable "temp" but I did not load into texbox.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: TextBox again. I have no way out!!!

    Try this.... replace the text file with your text file path....
    VB Code:
    1. Dim sr As System.IO.StreamReader = System.IO.File.OpenText("mytext.txt") 'opens file
    2. Dim MyString as String
    3. Mystring = sr.ReadLine() 'readds line in
    4. sr.close() 'closes the file
    5. MyTextBox.Text = Mystring 'replace with your textbox

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width