Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read Characters from a File 1

Status
Not open for further replies.

MaxRaceSoftware

Programmer
Jun 10, 2002
36
US
How can you read for example the first 10 Characters of a Text File ??

Thanks


MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Hum... Smells like homework.

Search the VB related forums/faq's for "read" "file" "input" and you will find a few threads/examples that should help you.

Once you've done this and still have problems come back and post the code you've tried so far.

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Hum... Smells like homework.

Search the VB related forums/faq's for "read" "file" "input" and you will find a few threads/examples that should help you.
=========================================================

i wish i was young enough to have homework :) LOL

and the "Search" usually hardly works in this Forum

anyways i found the answer a few minutes right after i posted the question...i was actually working on an old Visual Basic for DOS 1.0 program to give a sort of File preview or a preview what was in the File before you opened it....and forgetting to add "$" at the end of INPUT
and was getting an ERROR ..fixed it to INPUT$ in VBDOS1.0
=======================================================

The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return–linefeed (Chr(13) + Chr(10)) sequence. Carriage return–linefeed sequences are skipped rather than appended to the character string.

Dim TextLine
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
Debug.Print TextLine ' Print to the Immediate window.
Loop
Close #1 ' Close file.


Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Get one character.
Debug.Print MyChar ' Print to the Immediate window.
Loop
Close #1 ' Close file.
--------------------------------------------------------------------

in Visual Basic for DOS 1.0

INPUT$(n[,[#]filenumber%])

¦ n Number of characters (bytes) to read

¦ filenumber% Number of an open file; if omitted, INPUT$ reads from
the keyboard

Dim MyChar
Open "TESTFILE" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input$(1, #1) ' Get one character.
Debug.Print MyChar ' Print to the Immediate window.
Loop
Close #1 ' Close file.


MaxRace Software - Larry Meaux
ET_Analyst for DragRacers
Support Israel - Genesis 12:3
 
Good.

The homework bit is not always true, but this type of basic question does show very often.

Next time put the code you are having problems with, with an indication of the error you were getting, as that will always get someone to help.


As for the search bit it does work well for me.

And for this particular search there were many, including thread222-852949 on the first page



(As an apart, age has nothing to do with Homework. I'm near 40, and I'm back to college, and there are some guys on the same class as me that are well on their 50's.)

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
This should read the first ten characters of a text file for ya!
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Text.txt", 1)
    strCharacters = objFile.Read(10)
    msgbox strCharacters

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top