Truncate The Beginning Of A Log File In .NET?

Feb 24, 2010

I have an VB.NET app that writes the status to a log file in text format. Over time, the file is getting large and I wanted to know if there is an efficient way to truncate the beginning of the file.

To make things easier, I am looking to specify a file size (say 2-3 mb) and I am writing the log using a StreamWriter:

Using strm As New IO.StreamWriter(filelocation.log, True)
strm.WriteLine("msg to write")
strm.Close()
End Using

I thought about using the strm.BaseStream.Length to determine how much of the file to cut off, but by using the .SetLength it would cut from the end - not the desired result.

View 4 Replies


ADVERTISEMENT

VS 2010 Truncate Lines In .txt File?

May 2, 2011

Im trying to truncate lines in a .txt file from 19chars to 13chars. Then copy the .txt file to another location and rename the extension to .lst. As below... Iam having issue with getting it to write the truncated number to the new txt file. Its some how returning a Null referance & i cant work out why??

Imports System.IO
Public Class Form1
Sub ProcessFile(ByVal SourceFile As String, ByVal DestFile As String)

[code].....

View 3 Replies

Creating File At Beginning Of The Month?

Oct 23, 2009

Im trying to create a new file at the begining of each month, and stay active for the rest of the month by adding the textbox info to it every time someone presses the Next or Exit button. Next and Exit button update the files Im not sure would it be easier to get the info across to Excel or sql server, but i woudlnt know how to do that, if that would be easiers.Aim of the what im doing, person logs button presses with the text files logging the number of presses of each of the buttons. then at the end of the session or when the user moves to the next item to be logged the files then save the counted section. need to it log everything for the month. Just trying to get the info into sqlserver 2008 as im logging each job as well.

If Me.DateTimePicker1.Text = "# october 2009" Then
' logging the monthly total
Using SW As New System.IO.StreamWriter(faultsfile)
SW.WriteLine(TextBox10.Text)

[code]....

View 8 Replies

Return To The Beginning Of The File When It Reaches The End?

Mar 15, 2010

I have a file in vb.net that i am using to read records. In the code behind my next button i read the next record in the file.How do i return to the beginning of the file when it reaches the end?Here is my code.

Dim sr As IO.StreamReader = IO.File.OpenText("CorkSouth.txt")
Private Sub Display()
If sr.EndOfStream = True Then

[code]....

View 8 Replies

Move File Pointer Before Beginning Of File

Feb 25, 2012

[code] An attempt was made to move the file pointer before the beginning of the file.

View 1 Replies

Get A SplashScreen To Appear At The Beginning Of Program And Plays A Shockwave .swf File Automatically Without Loop?

Apr 27, 2010

I want a SplashScreen to appear at the beginning of my program and plays a shockwave .swf file automatically without loop, then closes he splashscreen.i want this ALL to happen on load on SplashScreen, i dont want to click a button and search my computer for a flash file. I want my flash to be in my program like so...

i get some "cross-thread" error What do i need for my .swf to run automatically on load? Also woundering if this is the right way to say the file location when the file is located in my solution explorer?

View 4 Replies

Reading Text File Line By Line, With Resetting Position To Beginning Of File

Jun 23, 2011

I'm reading a text file with StreamReader, line by line. If a condition is met, then I do an operation and then start reading the file again from the first line. I realize I could close and then re-open the file, but surely this would be very slow.

I could do this easily in VB6, but pulling my hair out trying to do this in vB.net. It seems that 'Seek' is the function to use, but it doesn't work.

I've seen other examples, where it works, but you must open it a different way -- with a file number.

Imports System.IO
Dim I as Integer
Dim LineText as String

[Code].....

View 2 Replies

How To Implement Truncate To A Row

Jun 22, 2010

[TEX]Hello[/TEX] How do i use truncate in vb 2008?my database its in Access and i want to implement a truncate table in vb but i don't know how to do it.

View 1 Replies

How To Truncate An Array

Sep 3, 2009

is there a simple way to truncate an array ? Something like placing an end characted in the array which would signify its end ?

Basically I have two arrays of slightly different sizes and I want to shorten them so they both have the same size. The end data I am truncating I don't need.

View 4 Replies

Truncate String Value To 17 Characters Only?

May 19, 2010

how to truncate my string value to 17 characters only.

in my program, the acceptable number of characters for First Name is 17. Characters more than 17 should be truncated but it may cut words in the middle. I need to make the length max 17 characters, but, if it cuts a word, it should also remove this half-word completely.

View 7 Replies

VS 2008 : Don't Use Int() To Truncate Numbers

Oct 4, 2009

I've been using it and even saw a method in a MSDN search given that suggests that it should be used but have found that there are defects using it. An example of problem occurring.

Dim db As Double
db = Int(10.12 * 100) / 100

db should be equal to 10.12 but the result you get will be 10.11. In the above example nothing is being truncated. If you added some digits right of the 2 it would give a good result. But if you're using a variable and it sometimes is equal to 10.12 or 9.12 etc. then a problem would occur. Also if 10.12 was replaced with 10.03 you'd get a result of 10.02. 10.04 gives a result of 10.03. 10.2 gives a result of 10.19. I'm now using code such as what is seen below instead of using Int() :

bd = Decimal.Truncate(CDec(10.12 * 100)) / 100

You could declare bd as a Decimal and then you wouldn't have to use CDec(). If I try Int(1012) the result is 1012 but Int(10.12 * 100) will give 1011. Pretty weird in my opinion.

View 5 Replies

Truncate DateTime Variable E.g. To Minutes

May 3, 2009

How can I "truncate" a DateTime variable so that only e.g. the current minute remains?

Like in:

Dim myDateTime As DateTime
myDateTime = Now
.... (what would have to come here)

If Now is e.g. 15:43:21 then leave only 15:43:00 in the variable?

View 3 Replies

Truncate SelectedItem Text In ComboBox

Feb 25, 2008

I've been trying to find a solution to this problem all morning.This is what I have: 1 comboBox control,autofilled from SQL table [code]...

View 6 Replies

Truncate Table In Sql 2005 By .net Code?

Jun 2, 2009

well i am truing 2 make a button when i click it would truncate the data in table , i am trying 2 do this by vb.net 2005.

View 5 Replies

Use Truncate Function In Column Expression?

Jan 13, 2010

i want to set a complex column expression truncate(cdbl(Today()-date2)/30)*(parent(parentchild).field1/parent(parentchild(filed2)))but truncate function is not available !

View 12 Replies

[2008] Truncate Tabs Text?

Mar 5, 2009

Using tabs for my web browser, I noticed (since im using documenttitle to populate the tab text) if a site has a long title, it will extend my tab var far, how can i limit this to a certain amount of text?

tab text code it:

TabControl1.SelectedTab.Text = CType(TabControl1.SelectedTab.Controls.Item(0), WebBrowser).DocumentTitle

View 1 Replies

Loop Does Not Truncate Into A Two Decimal Place Holder

Feb 14, 2012

I wrote a loop that posted an accrued principal cycle to a listbox for a period of 10 years (10 loop cycles). The problem is: not only does the amount of the principal reconfigure for each loop cycle, but it does not truncate into a two decimal place holder as it should. I would like to use the ("F2") but I am not sure where to put it within the code. Here is what I have for the Calculate button event handler.

[Code]...

View 2 Replies

VS 2010 Truncate Charachters HEX Data Stream (Serial)?

Sep 4, 2010

The RX data from the serial port is as follows:

FE FE FA E0 00 23 45 FD

I need to truncate everything else and just have positions 5, 6 and 7 output in the hex in a TEXTBOX. See below:

452300

Instead it will put the the whole steam in the textbox and it will be in decimal format, not hex.

View 3 Replies

Append At Beginning Not In End?

Apr 1, 2010

I have this code that writes text on an existing text file[code]...

I know it appends at the end of the file but how will you append at the beginning of the file? Is it possible?

View 1 Replies

Checkbox Selection At The Beginning?

Feb 27, 2011

When I exit the programme and start it again the checkbox selection from the previously job gets lost. After starting there is not a problem until I exit and start the programme again.

View 1 Replies

Remove Whatever Is At Beginning Of String?

Dec 7, 2010

DnsGetHostEntry takes an IPaddress as an argument but the one I'm supplying it while debugging is throwing an exception of "No such host is known" when I know that this is a perfectly valid host.

Somehow a space or character has been introduced at the beginning of the strong as per the text in quotes below. I tried a Trim(" ",

" 10.0.110.37"
"" & vbLf & "10.0.110.37" this is what I see when clicking on Edit Value in Quickwatch

[Code].....

View 3 Replies

Zip Code (Numbers Beginning With 0)?

Jun 7, 2011

All appears well, except for the zip codes that begin with a zero. I'm using a case statement to verify the zone, but VS2010, helpful as it is, removes the the lead zeros, after which said zip codes won't verify.strZip is put in through a text box, and a debug.writeline will tell me that VS stores it correctly, with the leading zeros. But when I get to the Case statement, it just will not let me look for a zero initiated number. I felt I was doing well by going with a string rather than something more numerical, but that apparently isn't enough.

Excerpt:
dim strZip as string
Select Case strZip[code]....

View 2 Replies

"truncate" Command - Databse Manipulation - Delete Multiple Rows In A Single Table

Jun 2, 2011

How to delete multiple rows in a single table i used "truncate" command.

This is my code for deleting:

Private Sub tranc()
Try
Dim dbconn As OleDbConnection
Dim dbcom As New OleDbCommand
dbconn = New OleDbConnection(cnnstring())

[CODE]...

I used access database on it. when i run my prog. i got this error "Invalid SQL statement; expected 'delete','insert.... or 'update'.

View 1 Replies

Determine Spaces At The Beginning Of Each Line?

Jul 8, 2011

how can i get the number of spaces in the beginning of each line before a word..following code is just for example reasons, not to be misunderstood for code that needs to be fixed.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Clipboard.GetDataObject.GetDataPresent(DataFormats.Text) Then
RichTextBox1.Paste()
RichTextBox2.Paste()
End If
End Sub

[Code]...

View 2 Replies

Find Customer With A Beginning Letter?

Sep 10, 2009

I've done a customer register in a win form app. and I need to be able to search for a customer fast. If I have more than 100 customers I'd be spending all day to find the right customer by using the previous and next buttons, so I want to have a textbox and a search button. If I write for example just an "A", I want my program to show all customers beginning with an "A". If I write "AN" I want my program to show all customers beginning with "AN".

View 6 Replies

Inserting Text At Beginning Of Textbox?

Dec 24, 2010

I tried using Insert to insert text to the beginning of a textbox in Visual Basic 2010 Express Edition, but it isn't working, using code like below.

TextBox1.Text.Insert(0, "text")

View 1 Replies

Remove From Beginning Of Line In Richtextbox?

Jan 31, 2011

you have a richtextbox filled with alot of different things, nthing specific

how would you go about deleteing the first 2 items of all the lines if the line has 2 or more items?

View 6 Replies

Removing Part Of A String At Beginning?

Jun 25, 2010

program makes strings from webbrowser documenttext.For example

String1 = "<span class""long-title"" title"" Informations here"

Im trying to remove all text before "Informations here" this is what i currently have.

dim mychar as char () = {"<"c, "s"c, "p"c, "a"c, '....thatandlike20moretill.... "e"c, """"c}
string1 = string1.TrimStart(mychar)

(Note that each letter or symbol inbetween the quotations is a part of the string (span = "s" "p"...)Now this works. Not all the time though and its a pain in the .. having to do "letter"c, all the time.. (I got over 10 strings lol) Im wondering if theres a way easier method to remove part of string from the beginning, maybe like still a certen part of the length..

View 6 Replies

Rest The Caret Position At The Beginning?

May 10, 2010

This is what I am trying but it doesn't work. The idea is to rest the caret position at the beginning after I hit enter and the conents od Textbox1 are deleted

Private Sub TextBox1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then

[Code].....

View 9 Replies

VS 2008 - Add 5 Bytes Of Data At The Beginning?

Oct 21, 2009

I have some questions about arrays.

1) Lets say I open a file in a byte array and I need to add 5 bytes of data at the beginning. How would I go in doing that? ex: attaching to arrays together.

2) How would I go in adding 1 byte of data in a bye array?

All i need to do is open part of a file in bytes. Add a letter and 2 numbers to it at the begging and a number at the end.All i need to know is how to attach 2 byte arrays together and how can u add a byte of data to an array.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved