Sort Large Text File
Hello All
I am trying to do a sort on a very larger text file, approx 75 MB. I have implemented the code below, but I am having a problem copying the file at the end of the run, I get a 75 file access error. Is there a reason why I cannot copy the file even though I closed both of them?
By the way is there a better way of doing this beside a bubble sort?
Thanks Steve
VB Code: Private Sub ProcessFile()Dim SortComplete As BooleanDim BeginRead As BooleanDim SrcFileNum As IntegerDim SrcFilePath As StringDim DesFileNum As IntegerDim DesFilePath As StringDim SrcString1 As StringDim SrcString2 As StringDim i As LongDim j As Long Do While SortComplete = False SrcFilePath = "c:Combined.txt" SrcFileNum = FreeFile Open SrcFilePath For Input As SrcFileNum SrcFilePath = "C: emp.txt" DesFileNum = FreeFile Open SrcFilePath For Output As DesFileNum j = j + 1 SortComplete = True BeginRead = True Do While Not EOF(1) DoEvents If BeginRead = True Then Line Input #SrcFileNum, SrcString1 Line Input #SrcFileNum, SrcString2 Else Line Input #SrcFileNum, SrcString2 End If BeginRead = False If SrcString1 < SrcString2 Then Print #DesFileNum, SrcString1 SrcString1 = SrcString2 Else Print #DesFileNum, SrcString2 SortComplete = False End If i = i + 1 If i Mod 1000 = 0 Then Debug.Print "Run: " & j & ", Line: " & i Loop Print #DesFileNum, SrcString1 Close #SrcFileNum Close #DesFileNum DoEvents FileCopy DesFilePath, SrcFilePath Loop End Sub
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Very Large Text File
What control would you suggest loading the entire text file (5mb +) into so the user can scroll through the file and view it unedited? (As read only)
Im using a listbox, but it takes awhile for it to load, any suggestions?
I would like to have the user be able to scroll through the data using their scroll wheel on the mouse, how do I implement that?
Lastly, how would I make a progress bar to show how far through the text file the program is? I was thinking I could go through the file first, have it count the number of lines, then just use simple VB graphics to fill up the bar based upon how many lines its gone through so far. Is there an easier way of doing this?
LArge Text File
I am opening a txt file and filtering out un wanted spaces. The file is approx 350 mb.
The program is hanging on the 1st line input statement. It is hung now or I would copy cut and paste the code. Why is that? Any suggestions on getting around this problem?
The code is something like this:
Open FileName for input as #1
Open OutputFileName for output as #2
While not eof(1)
line Input #1, strInput
' Filtering code here
wend
Close #2
Close #1
Thanks
LJ
2D Strings Compare Large Text File With Dat File
Hi
i am trying to compare a search a large server.log for listings stored in a dat file
one by one.
so
dat file listing like this
mr a
mr b
mr c
then look in the server log file line by line for mr a, mr b and then mr c then if say at line 20 a hit on mr c is found stop, perform a task then resume the search till the next hit or till the end of the log
also as the server log is constantly updated i want a way to remember last postition and only scan the new additions to the log not the whole thing over and over
not asking for some one to hand it to me on a plate as i want to learn this as i go but allmost idiot proof examples of code would be very much welcome
thanks again
Reading A Large Text File
At about line 1,426 VB decides it doesn't want to read anymore. How can this be fixed?
Code:
Dim ff As Integer
Dim readme As String
ff = FreeFile
Open readmes_path & "" & frmReadmes.File1.FileName For Input As #ff
readme = Input(LOF(ff), ff)
Text1.Text = readme
Close #ff
Edit A Very Large Text File
Dear Guys,
I have a problem with a massive text file which has the following format:
xxxxxxxxx
xxxxxxxxx
xxxxxxx">
cccccccc
xxxxxxxxx
xxxxxxxxx
xxxxxxx">
cccccccc
xxxxxxxxx
xxxxxxxxx
xxxxxxx">
cccccccc
Basically I want this to end up being:
xxxxxxxxx
xxxxxxxxx
xxxxxxx">cccccccc
xxxxxxxxx
xxxxxxxxx
xxxxxxx">cccccccc
etc....
So every time there is a "> it should move the line after that right next to it using the delete or removing the line feed.
Please help as I havent used VB in quite a while and need help.
Thanks and Regards
Large Text File Import
I hope someone can help me with this: I have to import a text file (using a VBA code) which is more than 65536 rows long into Excel. Preferably, the macro has to split the text file in two and devide them over two worksheets. Any suggestions?
Slurp Large Text File!
How can I slurp a large text file (300Mb+) into a single variable. How can I make use of the variable length string's 2 Billion Characters?
Large Gaps In Text File
Hi, I have a basic program that writes records from text boxes to a file.
Each set of records start on a new line.
After I enter a couple of sets of data and check the text file I find that there is large gaps at the begging of each new line.
Could someone please look through my code to see if they can find why it is doing this?
vb Code:
Dim LineCount As Long, DataLine As String Option Explicit Private Type NoteRecord StaffID As String * 4 Title As String * 4 Fname As String * 20 Sname As String * 20 DOB As String * 10 Address As String * 50 Town As String * 50 PCode As String * 7 HPhone As String * 12 MPhone As String * 11 Email As String * 50 JStatus As String * 8 AType As String * 9 APassword As String * 50 End Type Private Sub cmdcreate_Click()Dim i As IntegerDim file_name As StringDim fnum As IntegerDim note_record As NoteRecordDim value As StringDim l As Integer Screen.MousePointer = 11 ' hour glass l = lblgetline + 1 ' Open the data file.file_name = App.Path If Right$(file_name, 1) <> "" Then file_name = file_name & "" file_name = file_name & "accounts.txt" fnum = FreeFile Open file_name For Random As fnum Len = Len(note_record) ' Save the records. For i = l To l note_record.StaffID = Trim(txtStaffID.Text) note_record.Title = Trim(cmbtitle.Text) note_record.Fname = Trim(txtfirstname.Text) note_record.Sname = Trim(txtsecondname.Text) note_record.DOB = Trim(cmbday.Text & "/" & cmbmonth.Text & "/" & cmbyear.Text) note_record.Address = Trim(txtaddress.Text) note_record.Town = Trim(txttown.Text) note_record.PCode = Trim(txtpostcode.Text) note_record.HPhone = Trim(txthomephone.Text) note_record.MPhone = Trim(txtmobilephone.Text) note_record.Email = Trim(txtemail.Text) note_record.JStatus = Trim(cmbjobstatus.Text) note_record.AType = Trim(cmbaccounttype.Text) note_record.APassword = Trim(txtpassword.Text) & vbCrLf Put #fnum, i + 1, note_record Next i ' Close the file. Close #fnum Screen.MousePointer = 0 CreateStaff.Hide End Sub Private Sub Form_Load() 'see how many lines are in the file to see where to put nextOpen App.Path & "/accounts.txt" For Input As #1Do Until EOF(1) Line Input #1, DataLine LineCount = LineCount + 1Looplblgetline.Caption = Str$(LineCount) Close 'adds user types to list boxcmbaccounttype.AddItem "Admin"cmbaccounttype.AddItem "Reception"cmbaccounttype.AddItem "Maid"cmbaccounttype.AddItem "Caretaker" End Sub
Thanks
Sorting A Large Text File
Hi, I have a text file with about 80,000 lines and I need to convert it to an other format. Converting is not a problem, but I have no idea how to sort the new text file in alphabetical order. A Listbox and Listview can't hold so many lines.
Thanks.
Very Large Text File Manipulation
I have a SQL script that I am including in my instalation that will create the database for our app.
In VB 6, I have a dialog that would allow the user to choose the name of hte database, server, etc.... and create the database, and then create configuration files.
However, the database script is roughly 30,000 lines. The VB app does not like me using an "Open" or a file scripting object call. It freezes up the computer. The code is correct though, when I use a smaller file ( 3000 or less lines) I have no real slow down whatsoever.
Any ideas?
Thanks!
-Jason
Reading Large Text File
thanks for trying guys but still hanging. STARMAN - that would make sense, how would i found this out or go about replacing the characters??
Searching In A Large Text File
Hello, I'd like to search for movie names in a large text file and return the matches. I know how to do it with predefined words, but what I'd like to do now is more complicated.
This is the code I normally use with predefined words.
Code:
Private Sub Command1_Click()
Dim sLines As String
Open "C:movielist.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, sLines
If InStr(1, sLines, "matrix") And InStr(1, sLines, "revolutions") Then
Text1.Text = Text1.Text & sLines & vbCrLf
End If
DoEvents
Loop
Close #1
End Sub
Now I have this in a textbox:
Code:
!search matrix revolutions final end
If "!search" is in the textbox, then the other words (excluding "!search") need to be used as search strings, but only if they are at least 4 characters. In this case "matrix", "revolutions" and "final".
I know I can find out if "!search" is in the textbox with the Left function and that I have to put the words in an array, but how do I only add the words with at least 4 characters to the array and how do I use the array to search in the text file?
Code:
Private Sub Command2_Click()
Dim strArray() As String
If Left(Text2.Text, 8) = "!search " Then
strArray = Split(Text2.Text, " ")
End If
End Sub
Finding Text In A Large File
Is there a way to find text within a large file (several megabytes)? I'm trying to find out if a chm file contains a topic, and it looks like the topics are listed at the top. Alternatively, if there is something that allows me to find this out, rather than open a dialog with "page not found" displayed, that would work to solve my problem.
Thanks in advance.
Displaying A Large Text File
I want to read a large text file and display it as a wordpad. How can I do this. I tried to display my file using notepad but it displays only part of it. I suspect this is due to a limitation in notepad. Any sample code would be much appreciated
Thanks in advance
Deepal
Large Text File Editor
At my job I need to view files to verify that the data is not corrupt, some of these files are very large(4 gigs or more sometimes) and I am limited to 2 gigs with text editors such as SlickEdit, etc. My first option was to find a suitable editor on the internet, but every one that I downloaded had a similar limitation, and the ones that were supposedly unlimited file size tried to load the whole file into memory, which doesn't work. So now I am thinking I will have to write my own editor that will only load portions at a time, view that portion, then load another portion and unload the previous. I would like to update the line count for each portion of the file. I only have a little over a year's experience programming, so I am not sure if this is out of my league. If any of you could steer me in the right direction, pertaining to how to only load a portion of the file into memory(I think VB has a 2 gig limit, so this will have to be done) I would greatly appreciate it.
Sean
Reading Last Line Of Very Large Text File
Hi
Can anybody please tell me a way of reading the last line of a very large text file.
Each line is of a fixed length and are comma seperated.
Any help would be most appreciated
Scouse
Reading A Large Line Of Text From A File
I have log files that can be easily read using notepad and such. Though it is seen as one big long line of info when reading this into a string, ie
Code:
strString as string
Open C:file.000 for Input as #1
Line Input #1, strString
the file ranges from 3-5 MB.
loading the string takes about 1 full minutes to do the input part, (processor cranks up a bit, using a decent machine 2Ghz with 1Ghz ram)
not to mention the lengthy time it takes to hack up the string once I do get it loaded. I have searched and looked at many of the File I/O threads, but did not find one that related to my one line 4mb file. How can I speed this up.
Import Large Text File To Excel?
Hello, Everyone:
I would like to input a text file to my Excle data sheet. It has more than one line and I want to the excel sheet has 32 column with each row. How can I do it manually and in VBA also?
Thank you very much!
Charlie
Speeding Up A Text Search For A Large File
i have text files between ~8M and 40M ranging from ~5000 lines to 50000 lines, with 9 'columns' of data (8 tabs per line)
using most of the search code i have, if the number of results returned is small (500 or less) the search goes fairly quickly. 10, maybe 20 seconds (win XP, 2gb cpu, etc)
but if the search is to return 4000 records i'll be waiting for 4 min or so. and all the data is right here on my PC. that just seems way too slow. there must be a much faster way to dig into a large file and, before you can blink, it returns the results, no matter how many there are
it seems the issue is not the number of lines that slows the search down, but the number of results returned.
hopefully there is a way to do this.
Problem When Open Large Text File
i make a programe which open text file then replace each char. in it with another char.
i but the text i open in a String >>>all are right but the problem appear when i open a large text file(more that 3000 lines) then i press the button to do the process but no result appear in the textbox >>>
while if i open text file which have for expmle 1000 lines the programe work very good>>>>
where is the problem>>>>>>
Handle Large Text File Superfast
Hi all,
I have a large text file like 50000 lines (minimum). My program reads this file and do some modification in each line and write it to another text file.
That's what I do?
Normally if the text file has only 100 lines then it takes only 2 seconds to process it. But if the file is large then it takes even 10 seconds to process each 100 lines.
How to fix this issues? I need to keep the process time as 2 seconds for each 100 lines for any number of lines.
show me the best way to do this.
Thanks in advance.
Display Large Text File In Textbox
hello all
I have to open and display a selected portion of large file (more than 64K) but I'm getting problem when using textbox or richtextbox. The program always hang when using this method.
Any other solution?
Thanks.
Reading Last Line Of A Very Large Text File?
Hi
Can anybody please tell me a way of reading the last line of a very large text file.
Each line is of a fixed length and are comma seperated.
Any help would be most appreciated
Scouse
Best Way To Read A Large Text File Quickly
I'm still a fairly novice VB programmer, but i've been knocking up some bits and bobs to teach myself.
I've written a random URL generator that picks a random word from a large text file and opens up a basic web browser window to see if it turns out to be an actual site.
The problem is that the text file containing the random words is 180,000 lines long and takes forever to read as I choose a line at random and read the file line by line until i get to the chosen word.
Is there a quicker way to read it ?.
I want to be able to continually add words to the text file y'see, so i can't really create an array in the program as it would defeat the object of adding to the file.
Any clues would be most welcome .. thanks ..
Import Large Text File To Access Db
I have a large text File (more than 20Mb) and I can import it easly in a Ms-Access Db using the below codes. But the progress is slow (it takes more then 4 minutes) and I am looking for fastern procedures. I will appreciate if any body help me.
Thanks
Code
Sub ImportTxt()
Dim proddb1 As Database
Dim MyRs As Recordset
Dim f As Integer
Dim MyStr(21) As String
Dim MyFld As String
Set proddb1 = OpenDatabase("e: empdbtmp.mdb")
Set MyRs = proddb1.OpenRecordset("select * from datasheet", dbOpenDynaset)
For j = 0 To MyRs.Fields.Count - 1
MyFld = MyFld + "," + MyRs.Fields(j).Name
Next j
MyFld = Right(MyFld, Len(MyFld) - 1)
MyRs.Close
f = FreeFile
counter = 0
Open "e: emp10-2.mgd" For Input As f
Do While Not EOF(f)
Input #f, MyStr(1), MyStr(2), MyStr(3), MyStr(4), MyStr(5), MyStr(6), MyStr(7), MyStr(8), _
MyStr(9), MyStr(10), MyStr(11), MyStr(12), MyStr(13), MyStr(14), MyStr(15), MyStr(16), _
MyStr(17), MyStr(18), MyStr(19), MyStr(20), MyStr(21)
StrValues = ""
For i = 1 To 21
StrValues = StrValues + "," + Chr$(34) + MyStr(i) + Chr$(34)
Next i
StrValues = "10-2" + StrValues
strSQL = "INSERT INTO datasheet (" & MyFld & ") "
strSQL = strSQL & "VALUES(" & StrValues & ") "
proddb1.Execute strSQL
counter = counter + 1
Loop
MsgBox counter & " Records Imported"
Close #f
proddb1.Close
End Sub
Problem With Compare Two Large Text File
I am wondering is there a way or different method to compare two large text file without taking up so much time. I tried the FC.exe command and it did it very fast, but when I try to compare it in my VB program, it takes forever to finish with following code.
open FN1 for input as #1
while not eof(1)
line input #1, Str1
open FN2 for input as #2
do while not eof(2)
line input #2, Str2
if (Str1 = Str2) then
bfound = true
exit do
end if
loop
wend
Thanks you in advance
Fastest Way To Sort Thru Large Files?
Hi,
I have a text file that is about 400,000 characters that I need to search for specific items. I currently read file and read one line at the time and use the "Instr() to check for the item that I am looking for. Unfortunately, this is taking too much time. Is there a better way of doing this?
Than You.
Charles
Sorting Large Number Of Large Text Files
Hi,
I have around 500 text files (csv format). Each file is ca. 5MB and sorted by a timestamp. my application needs to playback all these files line by line but sorted by time.my goal is not to put all files in memory, use a sorting algorithm, create one sorted output file and then read from the output file.
I am rather thinking of sorting the files as they stream. For this I would only need to know in each file the time stamps of the current lines and compare them to each other.
what is the best way to do this? any ideas?
thanks
Sorting A Large Text File ..... Waves To Hack :)
Based on the other thread with the same name which is marked as reolved ...
I'm now using this Quicksort routine to sort a text file thats nearly 2 meg in size.
It contains fixed length records.
I towkred before, but now the file is bigger I am getting "Input Past End Of File" error messages on the line of code highlighted below.
Anyone know why ?
VB Code:
' Now sort file into alphabetical order Open "C:att_value.txt" For Input As #1 [b]str1 = Split(Input$(LOF(1), 1), vbCrLf)[/b] Close #1 QuickSort str1, LBound(str1), UBound(str1) Open "C:att_value.txt" For Output As #1 Print #1, Join(str1, vbCrLf) Close #1
Splitting A Large Text File... Or Searching Contents?
Hi all. I've been beating down the search function attempting to find the cleanest (and more importantly, easiest) method to read a large text file with a few hundred records and multiple fields per record.
I had originally decided to type in the first field (name), then execute a search through the records till the name was found, then assign variables to each field of that particular record. Now, I think I'm switching to a combo box drag-down list that displays only the first field of each record. My problem comes in sucking in all that information for the combo box, while still maintaining the variables for the other fields.
Let me give an example:
(Contents of my text file)
Bob Ward,15,BobWard.wav
John Thompson,31,JohnThompson.wav
Steve Kirk,16,SteveKirk.wav
Heather Sparks, 15,HeatherSparks.wav
Initially, I would have typed "Bob Ward" in, and search for an instance of that name in the text file. If Bob Ward wasn't found, the program would simply move to the next step. (This will happen throughout). Now that I'm typing this, it seems like that may be the way to go anyhow- as any record NOT found in a Combo Box I'll need to add anyhow... and that will require more coding.
Regardless, I was planning on pulling in the data, splitting it by vbCrLf into one group (records) and splitting it by comma for the other group (fields). In fact, I've already done this on a much smaller scale 12 record .txt file, and it works perfectly. However, with the much larger file, that would require a lot more lines of code the method I used... not an impossible task, but it would require more coding if I even decided to add more records. (I wasn't doing for I.. next I, rather just naming record1-12 as seperate arrays)
This post may be confusing, but I've been trying to structure my thinking so as not to waste coding time later. Any advice at all will be appreciated, and I am by no means a VB professional, rather just a hacking amateur.
Thanks in advance!
Importing A Very Large Text File In A String Variable
Hello friends...
I'm having an urgent problem here; I'm trying to import a very large text file of +54 MB(!!) into a String variable but each time the machine crashes...
Does anyone know what the problem is? Normally seen a string variable can contain up to 2 billion characters (says the VB Help)...
PS. It works fine with large files of 10 to 20 MB.
PPS. The machines who need to process those files are Pentium III's with 128 MB internal memory...
Here's the code I use in my program:
====================================
Public Function ImportFile(iMessage As Integer, Optional ByVal fLatestFile As Boolean = False, _
Optional strFileName As String) As String
Open sFileName For Input As #1
ImportFile = Input(lLength, #1) -> Crash!
Close
====================================
lLength contains a value like this = 55000000
Is it crashing because of a memory-overflow?
Please help Me if You know a solution for this...
Thank You
Bart
Sort Text File
Hi guys,
It's me again.....
Maybe this site has spoiled me a bit, but you guys always comes up with the best solution....
I want to be able to sort a text file....
I the text file there FirstName, LastName, address, etc.
I want to sort the file by LastName...
Can someone point me to the right direction?
Thanks in advance for all your help.....
I Need Help Reading From A Large Text File, And Rewriting Each Single Word
Here's what I have. I have a large text document with all the 5 letter words. I've attached the file so people can see. I got the list from an online dictionary.
Now - it seems to be broken up by space. So it's a word, then a space, then a word, then a space, word, space, etc, etc. From A-Z
Now - what I need help doing is opening the file (no problem), then reading each word one by one and adding it to a premade text file named Letter.txt (where the letter is the first letter of the word).
So - basically I want it to open the file, read the first word and toss it into the A.txt file, then the next word and toss it into the A.txt file, when it gets to B it throws those words into the B.txt file.
I can only seem to read the file as one long string when I try to read it, so I'm having trouble with that.
I could just copy all of the A words to the text file, and then manually seperate each one on its own line - but that would take a lot of time.
How To Read A Large Amount Of Plain Text Into An Application From A File?
Hi,
I have the user click on a number of labels which are all in a control array whatis(). When a user clicks on a label, I want the appropriate and corresponding file to be opened and read into the memory a few bytes at a time.
My current code is as follows, (the array means I don't have to have a different file open function for every label.
My problems are described below the code
VB Code:
Option ExplicitDim helpfilename(20) As String Public Sub whatis_click(index As Integer)Dim helpno As Integer helpfilename(0) = "whatdoesthisdo.txt"helpfilename(1) = "whomadethis.txt"helpfilename(2) = "whatisencryption.txt"helpfilename(4) = "whatisdecryption.txt"helpfilename(5) = "howdoesitwork.txt"helpfilename(6) = "howsecureisit.txt"helpfilename(7) = "useitfor.txt"helpfilename(8) = "discloseinfo.txt"helpfilename(10) = "legalegit.txt"helpfilename(11) = "upgrade.txt"helpfilename(13) = "modifyprog.txt"helpfilename(14) = "troubleshooter.txt"helpfilename(16) = "howdoiuse.txt"helpfilename(17) = "faq.txt"'Code here to read in an appropriate text file a few bytes at a timeEnd Sub
The index is of course the index of the label within the control array. Each index number in the array above corresponds to the file that should be opened for the index number of the label that was clicked in the control array.
What would be the best way to:
Read the corresponding file into memory without overflowing the memory or the variableRead it in only a few bytes at a time (each text file is a large passage of text equating to around 2kb to 10kb).
Many thanks,
Jord
Problem Retrieving Large Text Data From The Excel File
Hi
I am trying to retrievd data from the excel file using ADO and updating the SQL aerver based on that.
My problem is that the code is giving error for any column which has a large text data.
Please help me what i need to do.
the connection that i am establishing is as:
cn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & _
Trim(strFilePath) & Trim(strFileName) & _
";Extended Properties='Excel 8.0;IMEX=1;FMT=Delimited;HDR=Yes;MaxBufferSize=2048;PageTimeout=5'"
cn.Open
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient
Read Text File And Sort
Hello, I'm trying to read 20 numbers from a text file as integers, and sort them.
I'm absolutely STUMPED after I've gotten this far. Could someone take a look at my code and help me out?
I realize that some of my code may be all over the place - if someone can help me organize or fix it it would be greatly appreciated.
Code:
Private Sub Command1_Click()
' Defining
Dim iStartPoint As Integer, vTemp As Single
Dim lItem As Long, lCtr As Long, lCtr2 As Long
Dim vVal As Single
Dim vOrigArray As Single
Dim vAns As Single
Dim Numbers(1 To 20) As Single
Dim lNumSorted As Long
Dim lMax As Long
Dim FName As String
Dim tmpnum As Single
' Write this file to List1 and sort it
Open "H:ICS4M1Full Sorter
umnum.txt" For Input As #1
i = 1
Do While Not EOF(1)
Input #1, Numbers(i)
i = i + 1
Loop
vOrigArray = vAns
iStartPoint = LBound(vAns)
lMax = UBound(vAns) - 1
lNumSorted = 0
For lItem = iStartPoint To lMax
vVal = vOrigArray(lItem + 1)
For lCtr = iStartPoint To lNumSorted
If vAns(lCtr) >= vVal Then Exit For
Next
For lCtr2 = lNumSorted To lCtr Step -1
vAns(lCtr2 + 1) = vAns(lCtr2)
Next
'insert new item
vAns(lCtr) = vVal
lNumSorted = lNumSorted + 1
Next
SortedArray = vAns
errorhandler:
SortedArray = vbEmpty
Close #1
End Sub
Text Box / TxT File Sort Code
Can anyone give me the code to put the contents off a text box from highest to lowest (Sort) or sort a text file
Example:
7 - Ash Kri
9 - Kay Wells
8 - Bert Winn
Becomes:
9 - Kay Wells
8 - Bert Winn
7 - Ash Kri
my quiz saves the name from the first form to a text file, so the first line is the name, then from the last form it saves the score so the second line is the score.
Kay Wells
9
Bert Winn
7
So basically i want vb on the last form to organise the contents of an external file in to order of highest first or vb to organise the contents of a text box.
To save to file i use this code:
Code:
Private Sub cmdCal_Click()
Rem Replace 'c: est.txt' with the name of the file you want to edit.
Open "c: est.txt" For Append As #1
Print #1, lblResult.Caption
Close #1
End Sub
And to display the contents i use this:
Code:
Private Sub cmdHighScores_Click()
Rem Change "c: est.txt file to change what contents are displayed in the text box"
Dim iFile As Integer
iFile = FreeFile
Open "C: est.txt" For Input Access Read As #iFile
txtFile.Text = Input(LOF(iFile), #iFile)
Close iFile
End Sub
confused:
Cheers ppl
Sort Text File Content. Ideas Please :D
Hi ppl.
i have a text file look like this:
Code:
t155.4 ;B277i ;t.3918 ; ; ;
t155.4 ;B277i ;t.3917 ; ; ;
t371.102019 ;M672v ;t.3945 ; ; ;
t371.102019 ;M672v ;t.3946 ; ; ;
m347.952 ;A511e ;t.19409 ; ; ;
m331.88(81) ;P436c ;t.19396 ; ; ;
m347.955 ;P436r ;t.19362 ; ; ;
m34:502.7 ;V855r ;t.19338 ; ; ;
m347.77 ;A779p ;t.19358 ; ; ;
m347.919.3 ;O48j ;t.19373 ; ; ;
and i need to sort him in ALPHABETICAL order, using 2nd column (separated by ; ) to make a sort. i have to 'transform' my text file in something exactly like this:
Code:
m347.77 ;A779p ;t.19358 ; ; ;
m347.952 ;A511e ;t.19409 ; ; ;
t155.4 ;B277i ;t.3917 ; ; ;
t155.4 ;B277i ;t.3918 ; ; ;
t371.102019 ;M672v ;t.3945 ; ; ;
t371.102019 ;M672v ;t.3946 ; ; ;
m347.919.3 ;O48j ;t.19373 ; ; ;
m331.88(81) ;P436c ;t.19396 ; ; ;
m347.955 ;P436r ;t.19362 ; ; ;
m34:502.7 ;V855r ;t.19338 ; ; ;
ps: i already open, read and works with file contents normally. i just want sort content of file using 2nd column.
anybody can help me ?
Newbie Needs Help....sort Timefield In A Text File
I have a comma delimited text file and want to sort by the 4th column which is in 24hr format. Any ideas on the easiest way to do this. The single digit times do not have leading zero's. ex. 7:00:00 instead of 07:00:00.
Thanks in advanced!!!!
Kelly Mills
Convert Large Binary Files (3270 Exports) To Text File Format.
Access XP doesn't appear to import Binary files when exported directly from Attachmate.
Some of these files are quite large 18mb - to 100mb.
When I attempt to open the files in Access XP they fail and lockup Access XP. I have looked at the file format with some Hex compare utilities and they report that the file is 'Binary'.
If I take the same exact file and open it in Notepad then click save the file date and time changes and the file works perfectly with Access XP. (And the HEX compare utility no longer indicates that the file is binary)
Now that I am aware of this limitation - How do I take the file called XYZOutput.txt - open it in VB with FSO and write it back out as the same file name?
My theory was - If I can open the file in notepad - make NO CHANGES - but click 'SAVE' - the file structure changes from binary to text.
I have the following code to open the file and close it - but in VB it does not change the structure the way notepad.exe did?
One catch - the routine needs to handle large files, and since they are large I don't want to make a second file. I don't know what the file size limitation is of Notepad.exe. I want to fix the broken file. So for example - If my file is called "XYZOutput.txt" I want the VB routine to open this large file 'fix the formatting from binary to text' and save it.
'' Code ----------------------------------
Dim fso As FileSystemObject
Dim fil As File
Dim ts As TextStream
Set fso = CreateObject("scripting.filesystemobject")
Set fil = fso.GetFile(sourcefile)
Set ts = fil.OpenAsTextStream(ForAppending)
ts.Close
Set fso = Nothing
Kramerica
How To Read A Text File, How To Sort A List, How To Print
I have no idea how to complete this program, can anybody teach me please!!
But i have write some part in my program.(see my attach file)
i tried to put the score column in the last part of the list. but i can sort the score, and i don't know how to write a array in the program. Can anybody tell me how to fix it!!
Code:
Private Sub sort_Click()
Dim strListItem As String
Dim i As Long
For i = 0 To pLBName.ListCount - 2
Do While pLBName.List(i) > pLBName.List(i + 1)
If pLBName.List(i) > pLBName.List(i + 1) Then
strListItem = pLBName.List(i)
pLBName.List(i) = pLBName.List(i + 1)
pLBName.List(i + 1) = strListItem
i = 0
End If
Loop
Next
Label1.Caption = pLBName.List(0)
Label2.Caption = pLBName.List(25)
End Sub
Private Sub read_Click()
pLBName.Clear
If Dir("CIC_Current_List.txt") = "" Then
MsgBox "File not found"
Exit Sub
End If
Open "CIC_Current_List.txt" For Input As #1
Do While Not EOF(1)
Input #1, a, b, c, d
pLBName.AddItem "Score:" & d & " ,ID:" & a & " ,First Name:" & b & " ,Last Name:" & c
Loop
Close #1
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Included with this test is a file (CIC_Current_List.txt) that contains the details of some students enrolled for a unit at Curtin International College. The file is composed of four columns: the first contains the ID for each of the students, the second the family name, the third column holds the given name and the last column gives the score (%) for each student in the exam.
For this test you need to design an application that reads in the file CIC_Current_List.txt, rearranges the list in order of their scores (either ascending or descending – you choose) and prints out the rearranged file. The user can then ask for the details of the most successful student and the least successful student to be displayed (you choose how this is done) and the user can also ask for the average score for all the students.
The details of how the application looks, runs, sorts and prints are left entirely up to you. Marks will be allocated for the professionalism of the displays, proper documentation of the code, sensible naming conventions and error messages/windows that will help the user etc.
Need Bubble Sort To Read Two Seperate Text Files And Sort Data Into One List
I have two seperate text files, have to read the data from both, such as:
(file one)
2, Tom
5, Bill
3, Tony
7, Charlotte
1, Pedro
etc.
(file two)
6, Penelope
8, Joann
4, Mark
10, Jose
9, Gerald
etc.
Then open, read and sort the two files, then put that data into combined order (by the number) to come out as one list:
1, Pedro
2, Tom
3, Tony
4, Mark
5, Bill
6, Penelope
7, Charlotte
8, Joann
9, Gerald
10, Jose
etc.
My exposure so far with Bubble Sort has been comparing and sorting words that were entered into text boxes. That is the only code I have and does not match this current scenario. Need help with code on opening both files simultaneously and then bubble sorting. I know this needs to be an array.
Can someone tell me what to do or show a similar example I could follow? Thank you for any help.
Little Dilemma With &"user-defined Data Types + Bubble Sort + Text File&"
I seem to be in a little dilemma!
Three elements:
User-defined data type
Type PhoneRec
PH as Single
Name as String *15
End Type
Listbox
Lists the phone numbers
Textfile
933215,”Fred”
965458.”Barney”
9314587,”George”
------------------------------------
I’m trying to bubble sort the listbox, but when I do I get “zeros” instead of the phone numbers. I know how to bubble sort, but when using a textfile I am having trouble.
*i don't want to use the Sort = true property, because the linked data (names) do not get sorted with the phone numbers*
/----Module---
Public Sub BubbleSort(Number() As PhoneRec)
Dim pass As Integer, n As Integer
Dim temp As Single
For pass = 1 To (UBound(Number) - 1)
For n = 1 To (UBound(Number) - 1)
If Number(n).PH > Number(n + 1).PH Then
temp = Number(n).PH
Number(n).PH = Number(n + 1).PH
Number(n + 1).PH = temp
End If
Next n
Next pass
End Sub
---Module---/
/---Form---
Option Explicit
Dim Phone() as PhoneRec
Private Sub cmdSort_Click()
Dim i As Integer
Call BubbleSort(Phone)
Call lstPHNumbers.Clear
For x = 1 To UBound(Phone)
Call lstlstPHNumbers.AddItem(Phone(i).PH)
Next
End Sub
---Form---/
may anyone know a remedy to my problem, i would be very thankful!
|