|
hi there,
i want to write line in textbox through textwriter but vb giving some errors
the coding is:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click<br />
Dim a As TextWriter = New StreamWriter(lkj.Text)<br />
a.WriteLine("ssss")<br />
End Sub
can some one tell where is the mistake or problem
|
|
|
|
|
xmen_xwk wrote: lkj.Text
I'd guess that your variable names suck.
It's hard to say more, b/c you didn't tell us what the error is, or what line it occurs on.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Why on earth would you post an image to a site that shows it to me resized so I can't read it, instead of pasting the text in here ?
It looks like an argument exception ( hard to read ), what is the value of the text going in ? Did you set a breakpoint ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i post image because in text some important info. might be remain
no i dont use any breakpoint ever
|
|
|
|
|
xmen_xwk wrote: i post image because in text some important info.
Yeah, that makes sense
xmen_xwk wrote: no i dont use any breakpoint ever
Do you mean you don't know how ? F9 gives you a breakpoint, the code will stop when it reaches it, and you can examine the state of variables, etc.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The error says "empty path name is not legal". The text property of lkj is returning an empty string. You need to supply a file to be written too. StreamWriter will not accept an empty string.
|
|
|
|
|
yeah you are right the textbox is empty but man i want to write "ssss" in the textbox
|
|
|
|
|
You don't need a textwriter for that. What you are attempting to do with your code is write the text "sssss" to a file on your harddrive. The file to be written to would be whatever the path is in the textbox. If you want to set the text of the textbox just use:
lkj.text = "ssss"
|
|
|
|
|
yeah buddy, i know this , i want to do this in another way,
my whole problem is that ,i create an application in which Richtextbox contains about 10 lines of numbers
eg.
10
121
153....
and i want to add the textbox`s number which will be enter by user in every line thats why i was asking for textwriter
|
|
|
|
|
It took you 5 and a half hours to FINALLY describe what your trying to do with this instead of insisting that you need a TextWriter. You don't. If all you want to do is add the Text typed in by the user to the RTB, then all you have to do is:
myRTB.AppendText(myTextBox.Text & Environment.NewLine)
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
hehe ,nice and thanks i will check it,
|
|
|
|
|
buddy it adding lines at the end of text
it wont add the given number to line
|
|
|
|
|
The code provided will add whatever text is in the textbox to the end of the RTB. If the textbox is empty it will add a blank line. Just enter your number into the textbox and click the button.
|
|
|
|
|
Then you're going to have to re-explain and draw some text pictures of what you want it to do because as of right now, noone understands what you want it to do. And DON'T use what you've already posted.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
ok listen i want to add (eg.10+1=11) number which will in textbox to rtb lines so i coded it like this:
Dim srr As TextReader = New StringReader(rtb.Text)
Dim lineIn As String = ""
While Not (srr.Peek = -1)
lineIn = srr.ReadLine
lineIn = Val(lineIn) + Val(textbox.Text)
End while
its reading the lines but how to put back the value of "lineIn" in the place of same line where it read
now i think you will understand my problem
|
|
|
|
|
OK. You STILL do not need a StreamReader for this. And I STILL don't understand what you're trying to do. But, to get through the lines of an RTB is very easy using it's Lines property:
Dim newText As New StringBuilder()
For x As Integer = 0 To RichTextBox1.Lines.Length - 1
newText.AppendLine("test " & RichTextBox1.Lines(x))
Next
RichTextBox1.Text = newText.ToString()
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thanks for help but buddy why you use "-1" in this
For x As Integer = 0 To RichTextBox1.Lines.Length - 1
and i hope it will help me by the way my problem is:
i have a textbox and rtb ,rtb contains 10 or more numerical lines
and i want when i click on button then the number in textbox shoud be add in all lines of rtb
[eg:10(rtb line number)+1(textbox number)=11(10 change to 11)]
|
|
|
|
|
Richtextbox1.lines is an array. Richtextbox1.lines.length returns the number of lines in the richtextbox. However arrays start at zero. So to access the first element you would use Richtextbox1.lines(0). If there are 10 lines the 10th line would be Richtextbox1.lines(9). So to iterate over all the lines you go from 0 to 9 or 0 to length -1.
The code provided will do just what you want. All you need to do is make a small modification to add the value in the textbox.
Dim newText As New System.Text.StringBuilder
For x As Integer = 0 To RichTextBox1.Lines.Length - 1
Dim val As Integer = Integer.Parse(RichTextBox1.Lines(x)) + Integer.Parse(TextBox1.Text)
newText.AppendLine(val.ToString)
Next
RichTextBox1.Text = newText.ToString.Trim
|
|
|
|
|
thanks buddy i hope it should be work
thanks again for spend your time on it
|
|
|
|
|
Dear friends, i tried to check textbox
if textbox.text is empty i want to show a message like "Please write your name"
but unfortunately i couldn't check textbox.text is empty or not?
Thank you for your helping
Public Sub Kontrol()
If RdbMale.Checked = False And RdbFemale.Checked = False Then
MsgBox("Please choose Gender")
If TxtName.Text="" Then
MessageBox.Show("Please write your name")
If RdbMale.Checked = True Then
MaleFemale = "Male"
If RdbFemale.Checked = True Then
MaleFemale = "Female"
End If
End If
End If
End If
End Sub
MAGICIANMERLIN
|
|
|
|
|
MAGICIANMERLIN wrote: but unfortunately i couldn't check textbox.text is empty or not?
What do you mean ? Did you step through the code to see what was happening ?
Try this
if string.IsNullOrEmpty(TxtName.Text.Trim()) then
end if
This does two things
1 - it checks properly for an empty string
2 - it removes whitespace, so if the box LOOKS empty, it will be. Otherwise, a box with a space in it, is not empty.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thank you very much
it solved my trouble, thank you Christian
|
|
|
|
|
Glad to help
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I am trying to use a BackgroundWorker to list each file that I am scanning, but I'm not sure where to start. The MSDN examples don't help much. How should I use a BackgroundWorker for something like that?
Thanks!
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|