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:
Dim readFile As New StreamReader(variable.dataPath & "\" & variable.monthView & variable.yearView & variable.MST & variable.Loai & variable.Method & ".txt")
Dim temp As String
Try
temp = readFile.ReadLine
RefFrm.frmDoanhThuVATTNDN.txtDT11.Text = temp
Catch ex As Exception
MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
readFile.Close()
VB Code:
'this is a class, to make form DoanhThuVATTNDN globally
Private Shared p_frmDoanhThuVATTNDN As frmDoanhThuVATTNDN
Public Shared Property frmDoanhThuVATTNDN() As frmDoanhThuVATTNDN
Get
Return p_frmDoanhThuVATTNDN
End Get
Set(ByVal Value As frmDoanhThuVATTNDN)
p_frmDoanhThuVATTNDN = Value
End Set
End Property
Or
VB Code:
Dim readFile As New StreamReader(variable.dataPath & "\" & variable.monthView & variable.yearView & variable.MST & variable.Loai & variable.Method & ".txt")
Dim temp As String
dim form as new frmDoanhThuVATTNDN
Try
temp = readFile.ReadLine
form.txtDT11.Text = temp
Catch ex As Exception
MessageBox.Show(ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
readFile.Close()
Although it could load textfile content into the variable "temp" but I did not load into texbox.
Re: TextBox again. I have no way out!!!
Try this.... replace the text file with your text file path....
VB Code:
Dim sr As System.IO.StreamReader = System.IO.File.OpenText("mytext.txt") 'opens file
Dim MyString as String
Mystring = sr.ReadLine() 'readds line in
sr.close() 'closes the file
MyTextBox.Text = Mystring 'replace with your textbox