Read Specific Line
Hello,
I'm looking at writing a password generator that uses real words. In order to do this I've downloaded a relatively small dictionary text file, about 80K words (600kb), with a word-per-line.
Now, my problem is what is the best way to pick a word out of this file randomly, preferably with FSO?
Currently I count the number of lines in the file and use a random number generator to pick a number within the lines-of-file range. This is where I run into problems/issues. I can read each line into an array, and access the random element as required, but is this the best/most efficient way for such a large number of lines?
Thanks.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Read Specific Line
Can someone tell me how to read the line that start with "03" in a file?
Thks in advance
Read Specific Line
Hi,
In my current project I need to load ever first and every fifth text line (from a txt file for example) to 2 textboxes
However the current code I use only allows me to but all the 10 lines to 10 texboxes and use it after that.
So as far as I know this code is only usable to load either every line to a seperate textbox, or to get the first line from a text file
My current code is:
Private Sub File1_Click()
Open File1.Path + "" + File1 For Input As #1
Line Input #1, a1
Line Input #1, b1
Line Input #1, c1
Line Input #1, d1
Line Input #1, e1
Text1.Text = a1
Text2.Text = b1
Text3.Text = c1
Text4.Text = d1
Text5.Text = e1
End Sub
Hope you can help
tnx in advance,
Maartuh03
Read A Specific Line
Hi i have a text file and i would like to read a specific lines in that file. any one with ideas on how i can do that?
Thanks
Read Line Until Specific Character
I'm trying to read in some lines from a text file but the only part I want is a number located at the beginning of the line, after the text is a space and then some text. How would I go about reading in only the number and stopping when I get to the space??
Read From Specific Line In Text File
How can I read and write to a specific line in a textfile.
Say I want to write a string to say line 5 into info.txt and later I want read line 5 from info.txt
thanks Vidar
Read Specific Line Of Multiline Textbox?
I've only been working with VB for a very short time. I'm trying to read a specific line of a multiline text box. For example, I wish I could do something like this:
Dim Line4Data
Line4Data = txtBox.Text (line = 4)
Is there an easy solution to this? Everything I've read starts talking about SQL databases and blows my mind.
Thanks.
How Do I Read A SPECIFIC Line From A Text File ?? GURUS PLEASE HELP =)
A few easy questions for you gurus =)
1. How would I read a specific line from a textfile (for example line number 5)
2. How would i read a specific value in a text file? Lets say the file looks like an ini file:
thing1=value1
thing2=value2
How would i read/write from the specific value?? PLEASE HELP!!!!
Is it possible to search for a string in a file without loading it in a textbox? How would i then extract the value of thing2 for example then???
How Would I Read A Specific Line From A Text File As A String?
I would like to read configuration from a text file like config.txt
each line would look like: variable value (for example: version "0.9")
What code would i need to write if i only wanted to extract one variable and it's value from the config.txt?
How would i find the variable and read it's value ????
---------------------
~:{Decayed}:~
the.decayed@usa.net
http://www.q3seek.com
How To Read A Specific Http Link On A Specific Page And..
Hello ppl!
I am a REAL newbie to VB and I am trying to do a simple thing (I hope) I have no real basecode just the one to open a specific link: Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Sub Form_Load()
ShellExecute 0, vbNullString, "http://play.mp3.com/cgi-bin/play/play.cgi/AAIBQgAAAADABG5vcm1QBAAAAFLeTgEAUQoAAABYAQAAAFneTgEAQ2.J0TwUhHw6YJu97A3gU7XcOVum/fuzytoes.m3u/", vbNullString, vbNullString, vbNormalFocus
Unload Me
End Sub
Now, Id like to add some functionality since MP3.com changes the links every now and then. I need the program to go to the page, snatch the new link and then use it to open, say winamp. BTW, IE 5.5 does not alway's respond to the code above.. Dunno why. Sometimes it does. sometimes nothing happends whatsoever. Strange!
Ideas? Perhaps not a whole solution cause then I'll not learn. Thanx in advance! /FuzyToes
Line Input #1, Line...how Do I Read Ahead One Line (or Back Up One Line)
I am loading a file line by line using the LIne Input but at one point i need to look ahead at the next line to decided what to do on the current line...how do i look ahead one line? or how do i use the line Input function and then back up? Any help would be greatly appreciated.
Shane Thomas
p.s. please email replys in addition to the reply of post too
shathoma@nmsu.edu
Line By Line Text File Read And Correct Each Line
Can anyone help me create a small program or have any pointers
on pieces of code that reads a text file from folder "unfixed" then
fix the contents and then store the corrected contents
in another folder "fixed" and then move the file in folder "unfixed" to folder "old"
Details of contents.
There is a space infront of each line that should be removed.
Between the first group of numbers and the second there should be a zero for every space.
Then after the second group of numbers there should be just one space and the rest trimed off.
011531015222360000500355 3350505212004 50122
011531015222360000500363 5336305212004 6255
011531015222360000503465 2404505212004 50022
011531015222360000503463 1345205212004 50025
02153101522236 13 1503256
The @ symbol represents where a space should be.
I would like to read the file and then correct it and then
place the fixed contents in another folder with the original name.
Below is how I would like it to look.
01153101522236000050035500000003350505212004@
01153101522236000050036300000005336305212004@
01153101522236000050346500000002404505212004@
01153101522236000050346300000001345205212004@
021531015222360000000013@
Read, Find A Line And Delete The Line In Text File
Hi, I am writing codes to do the following things: read a line from a text file, if this is a matched line, delete the line and go to the next line.
Can any one give me some direction? Such as access mode, method to use, etc.
Thanks.
.Input ( Read Contentsof Text File - Line By Line )
I'm trying to import Data from a text file, which includes the following,
Vessel Name
000115600
000025600
000000000
000089000
000019000
000000000
6670.43
The above file is updated every five minutes and I wish to retreive this data in
order to perform calc's and then display a completion time for a process on the
User Form.
code:-----------------------------------------------------------------------------
---
Open "YourFile.txt" For Input As #1
While Not EOF(1)
Input #1, YourVariable
List1.Additem YourVariable
Wend
Close #1
--------------------------------------------------------------------------------
Instead of adding to a list as in the above example, I want to process it Line by
Line ( How do I achieve this using .Input ).
Help
Read A Word In A Line Of Text And Delete That Line
I have some aim logs that I'm going to put in .txt format, and I want to be able to delete the text that the other person has written.
Is there a way for me to specify a screen name and have the program delete that line of text?
Thanks,
Brad
How To Read Rich Text Box Content Line By Line
Hi all. I got a rich text box and i wonder how i can read each line of it one by one. For example i want to read each line of it and display it in massage box.
Furthermore, if i have 10 line of content in textbox how i can refrence each line and display it in massage box?
I be happy if some one show me how this can be done.Thanks
Run Time Error When Read File Line By Line
I'm trying to read a txt file line by line that I can stop reading at any place I want.
Below is the code:
VB Code:
Do While Not EOF(1) Line Input #1, fString Text1.Text = Text1.Text + fString + vbCrLfLoop
The problem is, if the txt file has empty lines at the end of it, it will have run time error : "Input past end of file".
Does anyone know how to solve this problem?
Thanks in advance!
Read Line By Line Problem && Question
have a text file that I need to read line by line. This text file is very large (upwards of 1.5GB). The problem with this is that the lines are not separated by normal vbCRLFs but by Unix line feeds which means I can't use the normal Open Blah as #1.
I have tried reading the file in and changing the vbLF to vbCRLF which works for small files and even putting the thing into an array and splitting on the vbLF, but it just won't work. The file is so large that I can't just read the whole thing into memory because it will kill the system.
I know other people may have experienced this because this is an Apache web log and I am hoping someone has some insight or knows of another way or even a custom ReadLine Function that is out there that someone else has built to solve this.
Thanks in advance.
How To Read Text File Line By Line?
Dears Friends,
I am coding a program to read emails.
Is there a way to read the email body text line by line ? if not possible, how can I set the bodytext to a text file and use that text file to read line by line?
Here is my psuedocode for reading email line by line:
With .bodytext
Loop from line 1 to EOF
If line x has string "Hello" then
If line x + 1 has "Money" then
forward this to youare@somewhere.com
end if
end if
End loop
End with
Here is my psuedocode for set .bodytext to file.
dim sFirststring as string
dim sSecondstring as string
With .bodytext
save the .bodytext to a file name A.txt
sFileName = " C:A.txt"
Open sFileName For Input As #1
Do Until EOF(1)
Input#1, sFirststring, sSecondstring
If Mid(sFirststring, 1, 1) = "Hello" Then
If Mid(sSecondstring, 1, 1) = "Money" Then
forward this to youare@somewhere.com
End IF
End If
Loop
Thanks,
Bil
Read Line By Line Problem && Question
I have a text file that I need to read line by line. This text file is very large (upwards of 1.5GB). The problem with this is that the lines are not separated by normal vbCRLFs but by Unix line feeds which means I can't use the normal Open Blah as #1.
I have tried reading the file in and changing the vbLF to vbCRLF which works for small files and even putting the thing into an array and splitting on the vbLF, but it just won't work. The file is so large that I can't just read the whole thing into memory because it will kill the system.
I know other people may have experienced this because this is an Apache web log and I am hoping someone has some insight or knows of another way or even a custom ReadLine Function that is out there that someone else has built to solve this.
Thanks in advance.
Read Text File Line-By-Line
I need to take a text file, read it line by line, and put certain lines into an array...
I need some help on the reading line by line part...
Can anyone steer me in the right direction? I don't need to read it all into an array, just 1 line at a time, and if the line meets certain criteria, put THAT LINE in an array...(I can handle the "if it meets certain criteria" part...)
Thanks!!
How To Read 1st Variable Line By Line From A .txt File
1st question. Is it easier if I use a database I assume?
Say for example I have a file named test.txt which looks like this
"Test1"
"Tst2"
"tt3"
And I do a search for "Tst2" how would I go through file to find that?
Open test.txt for input #1
white not EOF(1)
????
I am totally lost here. And are there any thorough tutorials online for visual basic 6 or a GOOD quality book that would touch on things like this an DBGrid's? The only one I have is too basic.
Thanks in advance and I apologize for the question but I can't find a resolution anywhere.
Open File And Read Line By Line
how would i open a file and read line by line?
i have it opening and reading this way
FNum = FreeFile()
Open fileIn For Binary Access Read As #FNum
FBuf = Space$(LOF(FNum))
Get #FNum, , FBuf
correction = FBuf
Close #FNum
but i want to be able to read each sentence at a time and for there to be a loop for the whole text file that goes through sentence by sentence
the file looks like this
<blah blah blah>
<blah blah blah>
...
basically i want to read each <blah blah blah> at a time
Any ideas??
Specific Line Only
I've done a search of the forum and found a mix of replies, but not one that seems particularly usefull. I'm wondering if there is a command to read only the specific (last) line of a text file. Btw, its for a highscores table containing exactly 15 entries, I want to read the last line in to compare to the new score. I know it can be done with *.ini file, but not sure this would be the best method for this. Obviously with only 15 files I could simply read in the whole lot each time, but figured I might aswell try to learn something new while I'm trying.
Any intelligent suggestions welcome. Cheers.
How I Can Read A Specific Sector In A Cd-rom?
Hello everybody,
how I can read a specific track in a cd-rom through VB?
For example:
if I need to read the data contained in a specific zone of the cd-rom, can I pilot the head of the CD for read only that zone?
and if is possible, how?
thank you
Reading From A Specific Line
Hi,
How would i go about opening a file and reading watever is on say for example line 10, then out that in a text box??
Thanks
Goto Specific Line
I have a rich text box, that the user can load text files in. The problem is I need to be able to jump to a specific line number of the text box. How is this possible?
Go To A Specific Line In A File
I have different files of all sorts, and I wish to go to the end of the first line, insert a carridge return and line feed. Then insert a string variable and save the file to its original name.
I can't just do a string comparision, because the files will always be different. How can I do this?
Basically, I want to find a specific location in any file.
ie. nth line xth column
Thank you.
How Do I Tell This Line To End In A Specific Spot??
The following code creates a random wavy line.
Code:
Private Sub Timer1_Timer()
Me.Cls
segments = 20
X1 = 100
Y1 = 300
X2 = X1 + Int(Rnd * 20) + 1
Y2 = Y1 + Int(Rnd * 10) - 5
linelength = 300
For t = 1 To linelength / segments
Form1.Line (X1, Y1)-(X2, Y2)
X1 = X2
Y1 = Y2
X2 = X2 + linelength / segments
Y2 = Y2 + Int(Rnd * 10) - 5
Next t
End Sub
as you can see in the code, the line has a fixed start point.
The problem is, it's end point is not fixed. it jumps around like a string being blown in a breeze.
I'm going to use code similar to this to make a 'BumpyLine'
function that I can use to draw realistic coastlines for
random continents. so being able to set a fixed end point is important.
Any help would really be appreciated.
Inputing A Specific Line From A Txt
Ok i want to take a line from a txt file based on a word. For instance if the fifth line has the word "dog" in it it would take the fifth line and make it a variable. By that way is there anyway you can tell it to goto a specific line in general or even find out what line you are on. Thanks in advance.
How To Get Data From A Specific Line?
I want to get data from a file? how to put data in line 2 to a textbox, data in line 3 to a textbox and continue..........
i using code below but come an error "type mismatch" and ReDim Preserve MyArray(i) was highlighted.
Dim temp As String, MyArray As Variant
Open "filename.txt" For Input As #1
While Not EOF(1)
ReDim Preserve MyArray(i)
Line Input #1, MyArray(i)
i = i + 1
Wend
Close
Y Value Of A Line At A Specific Point
say i have a line called line1 and it has its positions:
.x1 = 100
.y1 = 1000
.x2 = 2000
.y2 = 3000
this makes a diagonal line. is there a formula to get the y position that line1 intersects at say x = 500?
if you don't know what i mean tell me and i will post a picture
i have tried to come up with a formula myself but failed so i was wondering if any of you guys could help
thanks
Cut Selected Line Only(specific)
--------------------------------------------------------------------------------
I cant seem to find how to simply select a certain number of lines, in a text.
Dim PadId As Integer
On Error Resume Next
PadId = Shell("Notepad MyFile", 1)
AppActivate(PadId)
'select and cut lines 1 thru x. ??? I already have the line counter x.
'paste elsewhere
'save file
'close file
Thanks in advance!
Read Specific Bytes At An Offset
I need to read a few bytes at a specific offset, say for example the first 10 bytes of the file. I also need to write to a specific offset... This is for patching a file.
Example of what i need this information for:
(function breakdown)
Check for file -> Check File Size -> Check Bytes* -> Check if file is writable -> Write Log
I appreciate any posts to help me out here, sorry if this is a newbie question. Im not that educated with VB File I/O.
Read A Specific Character From An Array
I've this code:
Code:
Dim buffer As String
Dim bufferarray() As String
Open App.Path & "datasettingslicense.ini" For Input As #1
Line Input #1, buffer
Close #1
bufferarray() = Split(buffer, "-")
Now bufferarray(0) = "AGBS1"
I only need the "1" from this array. Does anyone knows how I can select just the "1" out of the array?
Thanx in advance.
Read File From Specific Point To The End??
I am attempting to read a file and write what I read to the end of another file. My problem is that I do not want to read the first part of the file I am reading. I need to find a "keyword" which tells me where to start reading and writing the information to the other file. Here is my code.... this code opens one file for reading and then writes the whole file to the end of the other file?
Do I need to do this line by line to accomplish what i need? The problem is the file i am reading is an extremely long html file.
dim fso as new FileSystemObject
Dim file as file
dim filetocopy as file
dim textstream as textstream
dim newTextstream as textstream
Set file = fso.GetFile(MyfilePath.html)
set filetocopy = fso.getfile(MyFileToCopy.html)
set textstream = file.OpenAsTextStream(ForAppending)
set newTextstream = file.OpenAstextStream(ForReading)
textstream.write newtextstream.readall
textstream.close
newtextstream.close
set file = nothing
set fso = nothing
Any suggestions
Thanks,
M
Read Only Status For A Specific People??
Hi,
I have been working on Excel VBA. I wanted to know whether there is any way that the excel spreadsheet status can be set to readonly for a specific group of users ??
|