|
You can't replace just the one line without rewriting the entire text file. The reason for this is text files have records of varying lengths.
Imports System.IO
Imports System.Text
Dim srcFile As New StreamReader("SourceFile.txt")
Dim newFile As New StreamWriter("NewFile.txt")
Dim inText As String
Dim intLineCount As Integer = 1
inText = srcFile.ReadLine()
While Not inText Is Nothing
If intLineCount <> 2 Then
newFile.WriteLine(inText)
Else
newFile.WriteLine("New Text To Replace Line 2")
End If
End While
srcFile.Close()
newFile.Close()
File.Delete("SourceFile.txt")
File.Move("NewFile.txt", "SourceFile.txt")
RageInTheMachine9532
|
|
|
|
|
i dont think u can seek to a specific spot in the file to replace just that line, however, someone else should reaffirm this, or otherwise disprove it.
here, i took a little time just now and wrote a sub which will replace any line # in a file, with the string you desire:
<br />
Private Sub TextLineWriter(ByVal fileName As String, ByVal lineNumberToReplace As Integer, ByVal textToWrite As String)<br />
Dim inFile As IO.StreamReader = IO.File.OpenText(fileName)<br />
Dim tempString(-1) As String<br />
Dim i As Byte<br />
<br />
'read the file given and save each line into a new array element string<br />
Do Until inFile.Peek = -1<br />
ReDim Preserve tempString(tempString.Length)<br />
tempString(tempString.Length - 1) = inFile.ReadLine<br />
Loop<br />
inFile.Close()<br />
<br />
'determine if supplied 'numberToReplace' is valid with the current file,<br />
'and correct the problem if so<br />
If lineNumberToReplace - 1 > tempString.Length - 1 Then<br />
lineNumberToReplace = tempString.Length<br />
ElseIf lineNumberToReplace - 1 < 1 Then<br />
lineNumberToReplace = 1<br />
End If<br />
<br />
'write the 'textToWrite' at the line number given<br />
tempString(lineNumberToReplace - 1) = textToWrite<br />
<br />
'create same file as given (overwriting it) and rewrite the entire file<br />
Dim outFile As IO.StreamWriter = IO.File.CreateText(fileName)<br />
For i = 0 To tempString.Length - 1<br />
outFile.WriteLine(tempString(i))<br />
Next<br />
outFile.Close()<br />
End Sub<br />
use it like this: TextLineWriter("C:\myFile.txt", 3, "Here is my newly put text.")
no need to use Imports system.io for it, it is already specified in the sub.
just copy and paste this exact, as is sub and test it out. please lemme know if this helps.
------------------------
Jordan.
III
|
|
|
|
|
i wish to create a simple print function to print the content of picturebox or richtextbox through my printer... anyone can provide some simple codes?? i found codes from vb.net documentation but i really cant understand wat is that... any help is greatly appreciated...
|
|
|
|
|
I have 2 projects in my solution as seen in Solution explorer (VB.NET) - One is a windows app the other is a controls library used by the windows app. How do I get the windows app code to acknowledge changes in the controls library? If I add a new property to the controls library the windows app refuses to see it.
Rugby League: The Greatest Game Of All.
|
|
|
|
|
1) Did you rebuild the control library? References and intellisense won't work properly until you do.
2) Check the properties of the windows app to make sure the reference to controls refers to the proper place. When you move projects around, you can accidentally refer to an old version.
I hope this is of some help to you.
|
|
|
|
|
Thanks, it was caused by it copying the dll locally.
Rugby League: The Greatest Game Of All.
|
|
|
|
|
Hmm, now the control has disappeared from the form it was on and the compiler says "Could not copy temporary files to the output directory." and "The file 'xxx.dll' cannot be copied to the run directory. The process cannot access the file because it is being used by another process." This even happens if I quit Visual Studio and then run it again.
Any ideas?
Rugby League: The Greatest Game Of All.
|
|
|
|
|
I can't get this to work at all, on the reference to the controls in my main project if i say Copy Local = true then it won't compile because it says "Could not copy temporary files to the output directory." and if I set Copy Local = false then the main project doesn't pick up any updates I make in the controls project because it copies the dll into the "bin" directory of the main project once then doesn't update it if I make changes to the controls project.
Does anybody have a solution to this please? I am sure multiple projects in a solution are a good idea but I just can't get it to work at all.
Rugby League: The Greatest Game Of All.
|
|
|
|
|
In your Main project references, did you use a reference to the .DLL of your control project? Or did you set the reference using the 'Projects' tab? If you used a .DLL reference, go into the references folder of your main project and remove the reference.
In order for this to work, you will have to use 'Project' references. This requires that botyh projects are part of the same solution. This, also, will ensure that your dependent control projects are built up-to-date and will allow you to modify the control project, rebuild the solution, and see the changes in the main project.
RageInTheMachine9532
|
|
|
|
|
Excellent, thank you/
Rugby League: The Greatest Game Of All.
|
|
|
|
|
You might be referencing "controls library" assembly instead of its project
Regards,
Serge (Logic Software)
|
|
|
|
|
I am wanting to create a nice all in one program dealing with services. Basically what I want to do i enumerate all of the services on a given machine and be able to start, stop, restart or remove a service (in the instance that a past program didn't do it). I can do everything but remove the service. I know i can remove a service with installutil /u, but I'd rather do it programmatically as I'd rather just have one .exe file if possible for portability. Anyway, can this be done, and if so, how could i do it with vb.net?
Thanks for any help.
|
|
|
|
|
Hello,
How do I make the Hourglass show up in VB.NET while the code is executing? I am querying a database and it takes a while and i would like to have the hourglass show until the query is done.
Thank you,
Santana
|
|
|
|
|
Check out the Cursor property of your Form. You can change it to WaitCursor to get the effect you want.
RageInTheMachine9532
|
|
|
|
|
hello
im currently using VB 6
i need help cause i forgot how the code should be
i want to delete a name for a combo or list box
example
the box have
aaaa
bbbb
cccc
if bbbb is selected then the box will remain(after a button been press)
aaaa
cccc
can this be done??
please help me
thank you in advance
Gary
|
|
|
|
|
hi ..
i am not properly able to understand what u mean .. here is the code to delete the selected item in the list ..
..... Private Sub List1_Click()
..... List1.RemoveItem (List1.ListIndex)
..... End Sub
This code will delete the selected item in listbox while cliking it .. bye
|
|
|
|
|
hello
thank you for this code
but what if i try to use a combo box?
is it the same type of coding or it need something different?
thank you for your help
Gary
|
|
|
|
|
hi
same code will work perfectly for combobox ...
bye
" The Thought that guides ur intelligent is more important than how intelligent u r "
|
|
|
|
|
|
Hello...
I try writing a socket programming (server & client program) but now I am stuck because I had mix up code of UNIX & WINDOWS. Further more, i get lost totaly now as my code run properly. Suddenly i can't understand what am I writting.
Anybody can help me? Appreciated if you can provide me a complete sample of server / client program codes.
Please advise between TCP & UDP, which one is better for socket programming?
Thank you very much!
Regards,
libra
|
|
|
|
|
programmingcodes@hotmail.com wrote:
Please advise between TCP & UDP, which one is better for socket programming?
Depends on the application. TCP is a connection based protocol that ensures all packets get to their destination and in the correct order, while UDP doesn't guarantee anything. If your doing file transfers use TCP. If your streaming audio/video use UDP.
Can't help you if you don't ask a specific question with the problem your having. And what do you mean by "I had mix up code of UNIX & WINDOWS"??????
RageInTheMachine9532
|
|
|
|
|
Hello,
But, am I right to say that if someone would like to drop out from the connection or join the connection, it is better for me to select UDP?
However, I am writting by using on a single PC, all client & server are same pc. TCP should not be a problem, am I right?
From your experience, which one is more easier, TCP or UDP?
I use UNIX header file into my Windows. Hence, a lot problem come out. Please advise what .h file should I include. My code now using sys/types.h, sys/socket.h, netinet/in.h, arpa/inet.h & unistd.h. As I know, I should use Winsock.h to replace sys/socket.h. But, between Winsock & Winsock2, which more suitable?
Thank you.
|
|
|
|
|
...here we go...
Anonymous wrote:
if someone would like to drop out from the connection or join the connection, it is better for me to select UDP?
Does not matter. The connection type is dictated by what your sending back and forth, not the number of connections...
Anonymous wrote:
I am writting by using on a single PC, all client & server are same pc. TCP should not be a problem, am I right?
Nope. It won't be a problem at all.
Anonymous wrote:
From your experience, which one is more easier, TCP or UDP?
They both work about the same. Neither one is easier than the other. Like I said, the choice is determined by WHAT your transferring, not how...
Anonymous wrote:
use UNIX header file into my Windows. Hence, a lot problem come out. Please advise what .h file should I include.
None! The .h header files are C++ headers, not Visual Basic.NET. VB doesn't know what to do with C++ syntax. You'll have to rewrite the header files with the stuff you need and convert the code from C++ to Visual Basic, by hand!
Besides, you don't need the header files anyway. All the socket programming API's have been wrapped in the System.Net.Sockets classes in the .NET Framework. The top of the .Sockets classes starts here[^]. You can search CodeProject for articles on 'sockets' as well as searching the rest of the web for examples.
RageInTheMachine9532
|
|
|
|
|
Hello friends!!
i am newbie in GSM programming , i don't know where to start.. if anybody is having sample vb code about sending
and receiving sms pls send me.. or atleast tell me where can i get information regarding that ..
thanks in advance ....
|
|
|
|
|
Search the web for 'GSM' using Google[^]. There are TONS of references to GSM programming.
RageInTheMachine9532
|
|
|
|