|
How about this:
- forget the multiline TextBox, use a single-line TextBox instead;
- use File.ReadAllLines to get a string array;
- set an integer variable "index" equal to the array length minus 3;
- show the relevant line in the TextBox by setting its Text property;
- have the user edit it and indicate he is done somehow (a "Save" Button would be fine)
- store the TextBox.Text into the same array position you used before;
- and now call the right File method.
Of course if you know exactly what modification has to be applied, you don't need the TextBox at all and you can have your code do it for you.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc, thank you for your suggestion. I think I am going to run with it and then repost the solution here. Gracias.
modified on Wednesday, November 25, 2009 12:24 PM
|
|
|
|
|
Still need some help here ..
As Luc suggested, I am using the code below to read a single line to my Textbox. That is working fine. My issue is that I get the last line in the textfile; my solution is to get the 3rd line from the bottom. How do I modify my code to achieve that? Thanks
Dim myFile As New System.IO.StreamReader(frmMain.lblClaimsFile.Text)<br />
Dim strTextArray() As String = {}<br />
Dim intIndex As Integer = 0<br />
<br />
Do Until myFile.EndOfStream = True<br />
ReDim Preserve strTextArray(intIndex)<br />
strTextArray(intIndex) = myFile.ReadLine()<br />
intIndex += 1<br />
Loop<br />
<br />
For i As Integer = 0 To UBound(strTextArray)<br />
txtSEloop.Text = strTextArray(i)<br />
'how do i read the 3rd line from bottom of file?<br />
Next
|
|
|
|
|
Then I suggest you read my earlier message again, up to and including my sig.
Luc Pattyn [Forum Guidelines] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc, I am a little slow, but I am getting there! lol! the code below gives desired result.
lblNumTrans.Text = frmMain.transLoop<br />
<br />
Dim myFile As New System.IO.StreamReader(frmMain.lblClaimsFile.Text)<br />
Dim strTextArray() As String = {}<br />
Dim intIndex As Integer = 0<br />
<br />
Do Until myFile.EndOfStream = True<br />
ReDim Preserve strTextArray(intIndex)<br />
strTextArray(intIndex) = myFile.ReadLine()<br />
intIndex += 1<br />
Loop<br />
<br />
'read the 3rd line from bottom of file?<br />
For i As Integer = 0 To strTextArray.Length - 3<br />
<br />
txtSEloop.Text = strTextArray(i)<br />
<br />
Next
The last piece I have not yet figured out is how to save what is displayed in my textbox back to the original text file. My issue is that I have the file open for reading. Any help? thanks
|
|
|
|
|
If you were to take my initial advice a quarter of the amount of code shown would have solved it all.
The code you currently have is lacking error handling, it doesn't close files and streams, has two loops it doesn't need, and is not complete. I would waste it.
|
|
|
|
|
Hi everybody
I'm currently developing a 2D RPG game like diablo 2. And this year I finally finished the physics engine .
For drawing the objects I use GDI+. Now I'm working on the level editor and I want to give more freedom for the level designers like giving them the option to decide by their own which regions of the map shall be impassable. The point is to give them a pen tool which they can use to freehand draw the impassable regions - something like Microsoft inkball game(http://www.windowsvistauserguide.com/vista2/games/inkball3.JPG) where you draw a line and when the ball touches the line it bouns from it. For that pen tool I use System.Drawing.Drawing2D.GraphicsPath function - the problem I have is that I don't know how to provide to the level designer a tool for erasing the created impassable regions - do you know a way to erase part of graphic created with System.Drawing.Drawing2D.GraphicsPath function? I've read an article where you can "erase" the created line by drawing another one with the same background color as the containing control but it just didn't work in my case because for background I don't have a solid color but a complex bitmap texture and objects like units and buildings.
Please help, thank you in advance and sorry for my bad english.
|
|
|
|
|
It doesn't sound like you have much of a choice but to repaint everything except the portions you're removing.
|
|
|
|
|
I have a block of code like so; I use to get the number of lines in a text file once I load it in a multiline textbox on my Form1.
Private Sub countLinesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles countLinesToolStripMenuItem.Click<br />
''count claims between ST & SE segments<br />
Dim totLines As String() = IO.File.ReadAllLines(Me.lblClaimsFile.Text)<br />
<br />
MessageBox.Show("The file had " & totLines.Length & " lines before processing.")<br />
End Sub
Once this file is loaded, I do some manipulations, including inserting additional lines. I would like some codes to determine the total number of lines in the textfile after the manipulation.
I am using stringbuilder to load file contents.
Dim newString As New StringBuilder<br />
newString.Append(My.Computer.FileSystem.ReadAllText(FileName))
TIA.
|
|
|
|
|
As you said, you have a multiline text box to load the file. I assume you are editing the file text there itself. Hene if you get the lines count in the multiline text box, I suppose it will be same as that in the file.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
The line count I get on load is static. After inserting additional lines in the file, I need a way to get a dynamic update of the number of lines in the "modified" file. Sorry if this was not clear. thanks
|
|
|
|
|
Have you looked at the Lines property of the TextBox control?
|
|
|
|
|
Thanks Dave. I will give it a whirl.
|
|
|
|
|
If you want to find out the number of lines in the textbox, use:
int lineCount = textBox1.Lines.Count;
|
|
|
|
|
Thanks Shameel .. it worked great; I just had to use Length instead of Count (since I got a message that count was not in the array).
Dim lineCount As String<br />
lineCount = txtClaimsDetail.Lines.Length<br />
MessageBox.Show("You have " & lineCount & " in your batch")
|
|
|
|
|
yep, I forgot. Arrays have a Length property and Collections have a Count property.
|
|
|
|
|
Hi All,
I want to get the data coming from a weighing scale (rs232 signal) to a vb.net prgram, to a text box, how i get this? can any one give the code,
Kind Regards
Jamith
|
|
|
|
|
Check out Coad's Code[^]. I know it is C# but it easy enough to translate. Plenty of tools available on the web to translate code.
|
|
|
|
|
Hi All,
I have two forms, Form1 and Form2.
Form1 has a tab control with tab name "A". I want to enable/disable this tab from Form2.
How to do this?
|
|
|
|
|
A reasonably simple solution is to put a public boolean variable somewhere, and changing it in form2. Then choose a suitable event (for example GotFocus ) in Form1 and based on the variable enable or disable your tab.
My advice is free, and you may get what you paid for.
|
|
|
|
|
My implelentation is like this:
In Form1, Code is:
Sub Functioname()
{
GroupbBox1.Enabled = False
}
Now I want to enable this GroupBox1 through Form2 in following function:
Sub FunctionEnable()
{
''''' Code will come here
}
Please let me know how to call that GroupBox1 control so that I can use its properties in Form2.
Regards
R.S.
|
|
|
|
|
See the other reply to your question.
P.S. Besides that it seems you are on the wrong forum.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Do you have a reference to form1 in form2? If you do then just call the Functioname method directly. If not then change your structure to have a reference. If the forms are intrinsically linked like this then there is no point doing this with events.
|
|
|
|
|
Please see my requirement below carefully: need immediate help.
I have 2 forms, main Form1 and a loginform. When I start the application, first "Form1" is loaded and then with a button click, user can load "loginform" if required to enable/disable some features/controls on Form1.
The sequence is like this:
1) Load main form Form1
2) click a button on Form1
3) Load the loginform.
4) enter user/pwd and click OK button
5) enable/disable "GroupBox" control on Form1 if login sucessful.
For this,
I made a click event for OK button in loginform, so once user clicks the OK button, I want to call one function which is defined in Form1 as a Public, which enables/disables the "GroupBox" control on Form1. The code structure is like this:
in main Form1, i created a function like this:
Class Form1()
Public Function DoThis() ' Function to enable/disable GroupBox control
....some task...
End Function
End
now in loginform, in the click event for OK button:
Class loginform()
Click_OK()
{
DoThis().... 'call function DoThis() of Form1
}
End
I am not able to call the DoThis() function in loginform. Please suggest me with a piece of code how to do this??
Please remember that Form1 is my main form which is loading first. If anyother way is there to make a password protected feature for GroupBox control in Form1, it will be highly appriciated.
Hope my problem is clear..Thanks.
|
|
|
|
|
You cannot Enable / Disbale a tab directly. It does not have a property for this.
The recommended method on MSDN is to handle the TabControl SelectedIndexChanged event. you will need to have a flag somewhere that you can set to reflect the state of the tab (enabled/Disabled) and then check in this event which tab you are on and then move to another tab if you try to select it when it is disabled.
Search google for "How to: Disable Tab Pages" and you will find the article at MSDN.
Dave
|
|
|
|