We help IT Professionals succeed at work.

Retrieve the last 1000 characters from a .txt file using Visual Basic v6.0

KingSencat
KingSencat asked
on
190 Views
Last Modified: 2011-10-19
I need to retrieve the last 1000 characters(Not lines) from a .txt file, how can i do that with visualbasic ?
Comment
Watch Question

Commented:
well this function loads the whole text file into a continious string, from that do a right(str,1000)


strLast1000 = right(fileload(strMyFile),1000)


zf



*note you may also want to replace(vbcrlf, "") first to remove end of line

strLast1000 = Right(Replace(FileLoad(strMyFile), vbCrLf, ""), 1000)
Function FileLoad(ByVal sFileName As String) As String
    Dim iFileNum As Integer, lFileLen As Long
 
    On Error GoTo ErrFinish
    'Open File
    iFileNum = FreeFile
    'Read file
    Open sFileName For Binary Access Read As #iFileNum
    lFileLen = LOF(iFileNum)
    'Create output buffer
    FileLoad = String(lFileLen, " ")
    'Read contents of file
    Get iFileNum, 1, FileLoad
 
ErrFinish:
    Close #iFileNum
    On Error GoTo 0
End Function

Open in new window

Author

Commented:
I need to return those 1000 characters back to my visual basic project
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Am I missing something?


zf

Author

Commented:
its show blank, i have  attached the  text document for you, any idea why is not working?
Game10.txt

Commented:
Wow lol thats some file.  My eyes hurt.  Ok are you using the first or second retrevial?  
This one
strLast1000 = right(fileload(strMyFile),1000)

or this one
strLast1000 = Right(Replace(FileLoad(strMyFile), vbCrLf, ""), 1000)



zf

Commented:
And now that I have you rfile I will test here as well.  In addition to which retreval you rusing are you trying to place into a variable? textbox? other


zf

Author

Commented:
I want just to create a new file with the last 1000 characters :) thanks for your help

Commented:
No problem, you have it working now?

zf

Author

Commented:
No :( its just blank

Author

Commented:
what i am doing wrong?

Commented:
Hi KingSenCat,
I am truly sorry for not getting back sooner.  Work went south in a hurry today and turned into the second Monday of the week.  Got home about 30 min ago and am going to bed.

I will readdress this with you tomorrow and help you figure out whats going on.  First glance I think its the data in the file not being true text formatting not sure but we will get it worked out.



zf

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.