Easy if you've worked with text alot - Deleting first part of a text file.

If I have a text file that is over 70,000 characters long (to long for a variable to hold) and I want to delete the first portion of it (which will vary) and resave it with the same path and filename, how would I go about doing that?

Example:
Lets say "c:\TestFile.txt"  is 70,000 characters long,
and I have found that I want to delete the first 100 characters (which must be defined in a variable..ie.. CharsToDelete = 100)

So CharsToDelete = 100
and I want to delete CharsToDelete characters from the first part of the file and save it with the same path and filename.

Any ideas?

If this does turn out to be hard, I will happily give more points...:-)

Thank you much!!

Cheers!
ahammar
LVL 23
ahammarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
A string variable can hold a string up to 2Gb, so 70kb shouldn't be any problem at all.


This is a cheesy solution but it will work...

Dim Filenr as Integer
Dim sValue as String
Dim CharsToDelete as Integer

CharsToDelete = 100   'or whatever

Filenr = FreeFile
Open "c:\TestFile.txt" For Input As #Filenr
sValue = Input$(LOF(Filenr), Filenr)
Close #Filenr

Open "c:\TestFile.txt" For Output Lock Read As #Filenr
Print #Filenr, Mid$(sValue, CharsToDelete+1)
Close #Filenr
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SiM99Commented:
String definition from MSDN:

A variable-length string can contain up to approximately 2 billion (2^31) characters.

A fixed-length string can contain 1 to approximately 64K (2^16) characters.

a textbox can also hold only 64k, maybe you meant this ahammer ?

You say the amount of characters to remove will be variable ?
then the only way you'll be able to do it (as fas as i know :) will be to read in the text, line by line or character by character and if the line/character matches the first line/character you want to keep, then start outputting th input you have into another file, and thn delete (kill) the origional file and move the new one to wherever you want it...

using a seperate file is not essential.. but you could not write it to the same file that you're reading it from...

sorry if this has been unexplanitory ... ill re-word it if you want ?? :)

SiM99
0
KDivadCommented:
My two cents:

They are right about the string length, but this will do what you want to the file.
Note: "Print #" has the disadvantage of adding a vbCrLf to the end of whatever is being printed into the file.

Dim FFile As Integer
Dim FText As String
FFile = FreeFile
Open "MyFile.txt" For Binary As FFile
FText = String$(LOF(1), 0)
Get #1, , FText
FText = Right$(FText, Len(FText) - CharsToDelete)
'Next four lines used to "erase" and reopen the file before writing it
Close
Open "MyFile.txt" For OutPut As FFile
Close
Open "MyFile.txt" For Binary As FFile
Put #1, , FText
Close
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

SiM99Commented:
KDivad:
Print can be used just as easily... if you use:
Print #1, , Text;
or:
Print #1, , Text,

putting a semi-colon at the end of the line just leaves the cursor where it is when at the end of the text you have just printed, the colon will add a space.... just like when you're printing to the printer
0
ahammarAuthor Commented:
Hi all,
Thank you all for your comments. Actually, I did think that a variable was limited to 64k like a text box, (and I could of swore that I read that more than once), but from the looks of it, it is not. I already figured a way to write it to another file and then save that one over the old one, but I thought the 64k variable length limit would be a problem, but apparently not.
Thank you for you comments, and I will be back later to give points. I want to give you all points since I learned something  from each of you, but VBMaster was first but I feel you all deserve some since I like what I learned from each of you so I will either keep this question in my e-mail so I can give some more points when I get them (although I've never done it, I just might buy some since I hate to be out), or figure out a fair way to do it now, but either way, you will each get rewarded. I didn't know about the # sign doing that, or the semicolan and colan thing, so I am glad to have learned that.

Thank you!!

Be back soon.....:-)

Cheers!
ahammar
0
SiM99Commented:
ok, just tell us what we need to do :)

there's not many people who'd go to all that trouble to give points... thanx :)
0
bruintjeCommented:
as bystander.....i picked up some things too....

ahammar > as an MSOffice compagnon I could share the reward load.....got to many points just adding up day-by-day......

so spending them on something useful here shouldn't hurt :O) jsut see it as buying the Q instead of the PAQ

just let me know....

:O)Bruintje
0
SiM99Commented:
wow, there's someone just as kind....

I would offer the same ort of thing, but im just starting and only have like 100 points...
0
KDivadCommented:
Sim99, thanks. I didn't know about the ; at the end of Print (to a file) to prevent the extra CRLF. I still prefer binary access with Get and Put, but it's nice to know that it is possible to stop that when I want to.
Learn something new everyday, eh?
0
ahammarAuthor Commented:
Bruintje:
I noticed you were making more appearances again in the MsOffice area and I am glad. You are about the only one left that was there when I started, except for maybe vboukhar I think. (there might be another one or two, but I'm not sure.)
I have slowed down alot too though. Just to many other things to do, like working on this one here. I hope soon you will see a new program published because this is part of one I've been working on for almost a year. It does things that I think (I could never be sure though) no one has ever thought of yet.
That gives me another idea. I am going to keep the names of the people that helped me out here, and mention them somewhere if it goes that far.
Actually, to give KDavid some due credit, he has already contributed about 4-5 months ago, so he probably knows part of what I am talking about, although It has exanded greatly since then, and does alot more now. Boy has it ever been a struggle! I can't really say to much about it, but if you ever see anything out there that is called "Catch Input", check it out. I use it all the time now and would be lost without it. Now I'm just trying to touch up the parts that I slacked off on.

That gives me an even better idea. I will send anyone here a copy of it when I'm done if they are interested. I know that's probably a rough one since you know nothing about what it does, but I'll tell you this much - it is not a text editor, it does much much more than that, and works with any program that runs under windows, (except for whatever I don't know about yet that might conflict with it....:-(  ). I'm not trying to brag, (although I will admit I am a little excited) I just want you guys to see how handy it is...., plus your input here helps me out a lot......:)


Anyway Bruintje, you are very generous in your offer (you to SiM99 for the thought). That is very kind. I'm not 100% sure how you mean though. If I give you the points from this question (which you can take in the MsOffice area if you want), then you'll distribute some points to everyone?? I think I remeber you doing something like that before. Tell me if that is right??

I want to be as fair as I possibly can be, and I did learn from every comment here (and from the way it looks right now, I will probably use a little of each), and my question is answered, so I want you to know that I appreciate all of you very much.

Boy, I must feel like typing tonight.....
Sorry for the book. (If you think this is bad, you should see how much I deleted back out when I got done....:-)

More later! (don't say - Oh No, not again, I promise it will be shorter next time...:-))

Cheers!
ahammar
0
bruintjeCommented:
OK I'll take the short road

I'll post 2 "points for ?" questions with a pointer to this 1

one for SIM99
one for KDavid

and then VBMaster can answer this one

then every contributor is awarded...

and I'm curious about that program of yours.....

:O)Bruintje
0
KDivadCommented:
Since ahammar has chosen not to tell you what his program actually is, I won't either, but I will tell you that it's a program that should cause much interest to any of you. If he has indeed used most/all of the code that I helped him with PLUS added new features then I, for one, am very much looking forward to seeing the released product.

Good luck to you, ahammar!

Later,
KDivad Leahcim
0
SiM99Commented:
What is the program ahammer ?

At least give me a URL for info/downloads .. :)
0
KDivadCommented:
I never got URLs and I helped write the app! It won't hurt you to wait like the rest of us. :-)

Happy waiting!
0
ahammarAuthor Commented:
Hi all,
Thanks for the comments and extra incentive. I'm sorry I don't explain a little more (although there are a couple hints towards the bottom) , but I'm just trying to protect myself and all my work. The wait should be short now. I don't have any url's or anything, as I don't have a web page or nothing like that, and this is just something I've been working on at home for a long time now. It's pretty much ready, I just don't know where to start with the copyrighting and patenting or whatever else I need to do, so I just need to find get more info of the best way to publish or distribute this thing (or if it's even worth the trouble) then when I do, you can have all the details you want. That's the only wait that should be left. I know it wont be something for everyone, but I think it will be really great for a lot of people. Time will tell I guess.
But don't worry, whether it goes that far or not, you will all get a copy for free. I am going to save this entire page to my hard drive, so I'm sure not to lose it.  I hope you will really like it.
It saves me atleast 25% if not more key strokes in any program I want it to, and has the potential to save you much more, depending on what you use your computer for alot. Some keys I don't even have to use any more if I don't want. Some things I used to have to make my computer do all the time, all gets done with so many less steps it's unreal.

A not very good example:
Steps that used to take me 5 minutes to complete, I can now do in 1 second or less, and that involves most anything I want.

Another not very good example:
Some things that would normally take me 1/2 hour type, I can now do in 2 seconds or less.

There is a lot more, but maybe that will give you a shadowy idea of one thing it does.

KDavid already knows one of the other things it does.
KDavid: Thanks for not spilling the beans.

Bruintje:
You are just to generous. I told you this once before, but you probably do have about a million points by now since you never have to ask a question and you've been here a long time.
Give me one more go ahead and I'll accept VbMaster's comment as an answer, and you can do as you said, and I'll be sure to remember that I owe you one....or more.....:-)
Many Thanks to you and everyone else!!

I lied. I guess this is Chapter 2......:-)

Shorter next time,

Cheers!
ahammar

0
SiM99Commented:
OK, sorry for being pushy ,...

I'll leave it up to you what goes on from now :)
0
KDivadCommented:
>>A not very good example:
Steps that used to take me 5 minutes to complete, ...

Another not very good example:
Some things that would normally take me 1/2 hour type,<<
I've got a sneaking suspicion about what this is and if I'm right, it sounds like something I've started before.

>>KDavid already knows one of the other things it does.<<
2, actually, but this one is something I'm VERY proud of and have coded into one of my own apps. Very glad we got this working!

>>KDavid: Thanks for not spilling the beans.<<
Not a problem. Besides, I don't know what the other things it can do are and I'd hate to spoil your fun and then miss out on a free copy. :-)

>>You are just to generous.<<
Yes, she/he is.

>>Give me one more go ahead and I'll accept VbMaster's comment as an answer, and you can do as you said,<<
She already has...

Later,
0
ahammarAuthor Commented:
Ok, I am going to accept VbMaster's answer. You were all a great help and I appreciate it a lot! I'm sure Bruintje will do as he said and give the other 2 of you points.

Thanks bruintje: You really are very generous and I owe you one. I will remember.

KDavid: Yea, I wouldn't put it past you to already have done some of this before. When I first started this, it was just suppose to be to help me out, but as time went by, and I kept adding things to it, and when it all came together and some of the new ideas I had, actually worked, I decided that I would go all out and try to fix every bug, add as many options as I could,  make it look nice and fix it up so that it would be simple enough for anyone to use. It is just so handy I figured it might be worth the time and trouble. I have to give you a lot of credit, and depending on what happens with it, maybe more than that.
I hope I didn't come up with anything new that is to close to something you already did, and if I did, hopefully it's got enough added or different stuff that it wouldn't be like stealing your idea....:-(

Anyway, we will soon see. I'm investigating and learning what I need to do to get this going, so hopefully it won't be to long.
Who knows, maybe it won't go anywhere, but I'm gonna give it a shot.

I will keep you all informed.

Cheers!
ahammar
0
KDivadCommented:
>>KDavid: Yea, I wouldn't put it past you to already have done some of this before.<<
Uh-uh, the one thing I was guessing about was something I started, but then abandoned as too much trouble for what it was worth.

>>When I first started this,...so that it would be simple enough for anyone to use.<<
I've had some of those, nobody was ever interested in using them, though, so it's just for personal pride, I suppose.

>>depending on what happens with it, maybe more than that.<<
Oh? Hmm...interesting...

>>I hope I didn't come up with anything new that is to close to something you already did,<<
We shall see. Don't worry, I won't sue you for too much. :-)...maybe...
Besides, an idea is non-patentable, so there's not much to worry about anyway.

Later,

P.S. What?!?! No book?!
0
SiM99Commented:
LOL, I can't wait to see what this is if KDavid is using it in other apps too...

I origionally thought that it was one type of program, but now im not too sure..

on the other hand, it could still be...
0
SiM99Commented:
Hmm, I just read the origional question again....

It sounds like it has nothing to do with what i thought it was... deleting characters from a file ?
This isn't some sort of virus is it ? :) (j/K)
0
KDivadCommented:
SiM99,
>>if KDavid is using it<<
If I'm using the same code, it must be good?!?!

>>one type of program<<
Unless I miss my guess, it's a multi-purpose app. It wasn't when I was helping him, but now...?

>>deleting characters from a file<<
{in childish sing-song voice (nanie-nanie-boo-boo, I'm sure some of you know this one)}
I know what it is! I know what it is!
I'm not tellin'! I'm not tellin'!

>>This isn't some sort of virus is it?<<
Not that I know of, but you know how those computer-geeks get in their dark little dusty corners with their fancy little 'puters. ;-)
0
ahammarAuthor Commented:
Now, now now children. Let's not get fussy.....:-)
Now that you have almost figured it out I might as well tell you that it's not a multi-purpose app, and not only a virus, but a whole collection of viruses that I've been saving and adding to.......:-)

I'm sure you know I am joking. Actually, the virus that I  accidently already wrote (but for a good reason) in Excel (and it's a killer), I can garuantee will never leave my hard drive, (except for all the people that have already downloaded it.......just kidding :-)
 
It is virus free!!!!!!!!!Yaaaaa..Hoooooo!! Yea! Yeh! Yea!
It is a multi-purpose app (3 main utilities with a 4th to be added soon [maybe unless I decide to make it a seperate one because it uses/can use a lot of system resources]) and all 3 run all the time (if you choose) with any windows application.

I will make the suspense (if you have any) as short as I can.

With some recent information I got (thanks to KDavid and someone else both giving me the same story), I'm hoping it will be ready withing the next few days.


I hope I haven't exaggerated to much here and made it out to be a lot more than it really is. It is pretty cool, but I know 2 of the 3 do already exist, but I think this one just works a little better. Actually not better, just works differently or has more options that could prove to be very handy. The 3rd I don't know if it has been done yet or not. Just because I've never seen it, doesn't mean it doesn't exist.

Thanks again for all your help!

Stay tuned for chapter 5...:-)


Cheers!
ahammar
0
KDivadCommented:
Ya know, I think ahammar is doing it on purpose. I bet he's had the app written and fully tested for about 2-3 months now and he only asked this question so that he could drive us up the wall saying that he's written the greatest app that ever was and he might even let us see it sometime if we're really good. Either that or he wants to test his book-writing skills and he's forcing us to read it!

:-)

Later,
0
ahammarAuthor Commented:
Ahhhhhh! and it has been fun too!....:-)

Cheers!
ahammar
0
SiM99Commented:
lol.. 3 months :)



>>>>This isn't some sort of virus is it?<<<<
>>Not that I know of, but you know how those computer-geeks get in their dark little dusty corners with their fancy little 'puters. ;-) <<

in a dark corner, on a fancy computer ??
It's not porn is it ? :)
0
KDivadCommented:
Hmm...maybe it's a porn-virus. It infects your computer, changes all your icons into little porn scenes and modifies your sound settings to make...umm...I think you know where I'm going with this...

;-)
0
ahammarAuthor Commented:
hmm...my computer is in a dark place....your giving me some good ideas.....:-)

Anyway, I am adding the list of names now. It's about ready.
If you want your name listed different than what it is here, then tell me what you want it as. I'll wait until Tuesday, and anyone I don't hear from by then, I'll list it as it is here.

I got yours KDivad, so yours is done.

Cheers!
ahammar
0
SiM99Commented:
nope, SiM99 is fine ith me - it's what i put on my programs :)

NOW will you post a URL ? :))
0
KDivadCommented:
LOL! SiM99 is getting almost desperately curious, isn't he(she?)?

ahammar, I'll try to have the page fixed up for you by then(Tuesday), ok?

Later,
0
SiM99Commented:
KDavid: nope... he :)
0
KDivadCommented:
I don't know why, but I thought maybe you were a "he" and I didn't want to just assume. You might have gotten offended and infected this computer with that pron-virus! I wouldn't mind, but this is my MOM'S computer...
0
ahammarAuthor Commented:
Well, atleast I know SiM99 and KDivad will need the copy with girly pictures and not guy pictures......:-)

KDivad:
Ok, thanks for the Web page help. I still haven't got a place on a server to put it, but I think I am close. I found out that my current provider allows me 5 mg of space to do just that, I just haven't been able to make it work yet. I am figuring out how to do that though. I'll be in touch with you by e-mail shortly too. I just gotta go give the baby something to eat first.

SiM99,
As you can probably tell from the context here, I'm just about ready to post a URL. As soon as I have one, I'll post it and hopefully you'll be able to download the thing if all goes well.
I'm real new to this creating web page stuff, so it's kinda touch and go.

Thanks again!

Cheers!
ahammar
0
SiM99Commented:
ahh, i see :)

there's a provider that gives 50 MB - www.50megs.com, but they put their own advertisments at the top of your pages :(
0
ahammarAuthor Commented:
Hi all!

Well, I finally have a url and download site. I will say it needs some work, but it's a start. I actually used 50.megs.com as SiM99 commented about. Thanks SiM99!

If it comes about that you download the file, and you want the reg. key, send me an e-mail and I'll send it to you. Make sure I can identify you as someone that has commented here, so I will be sure and know you should have the key.

ahammar@cyberhighway.net

MERRY CHRISTMAS!!!

Cheers!
ahammar
0
ahammarAuthor Commented:
How many of you had problems going to the url I didn't post....:-)

http://www3.50megs.com/ahammar/CatchInput/catchinput.html

That might make it a little easier to find.

Cheers!
ahammar
0
KDivadCommented:
Guess what? I know wish I had finished my version of "Speed Keys" when I originally started writing it. Very nice!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.