Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Read Text File In VB6


I have a text file that has around 1,000 lines in the text file. I need to import this text file into my SQL Server. The file is delimited by ~ for the different columns. I have been searching the net and I can get VB6 to read the first line but not continue to goto the next line until the end. Can someone please help with this?

Also what would be the best way, load each line into an array and then insert into the database or insert into the database after you read each line? For right now the text file only has about 1000 lines but will quickly grow to 10,000 lines and will be updating the database 3 times a day by deleting the rows in the SQL Server and then reinserting all the data.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read From Text File Using VB And Insert Into SQL Table Until Eof Text File Reach
Dear All,

my text file like following,

a1, b1, c1, d1, e1
a2, b2, c2, d2, e2
a3, b3, c3, d3, e3
a4, b4, c4, d4, e4
.................

and im going to insert this values into SQL Tables with columns, [a, b, c, d,
e]

how im going to do so? i use below src code to do but i can not get the next
line and next line of text file until it finished insert

Private Sub mot_Click()
'Shell ("C:Program FilesMicrosoft OfficeOffice11MSACCESS.EXE c:fisherdb.
mdb /x ImportOpsNilai")

'frmPicCd.Show
Dim db_connect
' Path = App.Path & "ERP consumable code.xls"

Dim objFSO
Dim objFile, objTextStream
Dim strContent
Const ForReading = 1
Dim FileName, IEPath, strC1 As String
FileName = "U:ureportuopsRepNilai.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.GetFile(FileName)

Set objTextStream = objFile.OpenAsTextStream(ForReading,
TristateUseDefault)

If objFSO.FileExists(FileName) Then

Set objFile = objFSO.OpenTextFile(FileName, ForReading)

'While Not objFile.EOF
strC1 = objFile.ReadLine
Dim word
ReDim word(2)
word = Split(strC1, ",")
' Dim t1, t2, t3 As String
' MsgBox RTrim(LTrim(word(44)))
' t1 = Replace(word(0), """", "")
' t2 = Replace(word(1), """", "")
Dim sql
Dim rs As New ADODB.Recordset
sqldb.Execute ("delete from OPS_Nilai")
rs.Open ("Select * from OPS_Nilai"), sqldb, adOpenDynamic,
adLockOptimistic
With rs
.AddNew
!Field1 = RTrim(LTrim(word(0)))
!Field2 = RTrim(LTrim(word(1)))
!Field3 = RTrim(LTrim(word(2)))
!Field4 = RTrim(LTrim(word(3)))
!Field5 = RTrim(LTrim(word(4)))
!Field6 = RTrim(LTrim(word(5)))
!Field7 = RTrim(LTrim(word(6)))
!Field8 = RTrim(LTrim(word(7)))
!Field9 = RTrim(LTrim(word(8)))
!Field10 = RTrim(LTrim(word(9)))
!Field11 = RTrim(LTrim(word(10)))
!Field12 = RTrim(LTrim(word(11)))
!Field13 = RTrim(LTrim(word(12)))
!Field14 = RTrim(LTrim(word(13)))
!Field15 = RTrim(LTrim(word(14)))
!Field16 = RTrim(LTrim(word(15)))
!Field17 = RTrim(LTrim(word(16)))
!Field18 = RTrim(LTrim(word(17)))
!Field19 = RTrim(LTrim(word(18)))
!Field20 = RTrim(LTrim(word(19)))

!Field21 = RTrim(LTrim(word(20)))
!Field22 = RTrim(LTrim(word(21)))
!Field23 = RTrim(LTrim(word(22)))
!Field24 = RTrim(LTrim(word(23)))
!Field25 = RTrim(LTrim(word(24)))
!Field26 = RTrim(LTrim(word(25)))
!Field27 = RTrim(LTrim(word(26)))
!Field28 = RTrim(LTrim(word(27)))
!Field29 = RTrim(LTrim(word(28)))
!Field30 = RTrim(LTrim(word(29)))
!Field31 = RTrim(LTrim(word(30)))
!Field32 = RTrim(LTrim(word(31)))
!Field33 = RTrim(LTrim(word(32)))
!Field34 = RTrim(LTrim(word(33)))
!Field35 = RTrim(LTrim(word(34)))
!Field36 = RTrim(LTrim(word(35)))
!Field37 = RTrim(LTrim(word(36)))
!Field38 = RTrim(LTrim(word(37)))
!Field39 = RTrim(LTrim(word(38)))
!Field40 = RTrim(LTrim(word(39)))

!Field41 = RTrim(LTrim(word(40)))
!Field42 = RTrim(LTrim(word(41)))
!Field43 = RTrim(LTrim(word(42)))
!Field44 = RTrim(LTrim(word(43)))
!Field45 = RTrim(LTrim(word(44)))
.Update

End With
'objFile.SkipLine
'objFile.MoveNext
' Loop
End If

objTextStream.Close
MsgBox "Update completed!!!", vbOKOnly + vbInformation, "Fisher Nilai"
End Sub

kindly advice


thank you

--
Message posted via VBMonster.com
http://www.vbmonster.com/Uwe/Forums...vbasic/200707/1

Read And Append Text File Details To Onother Text File
i have three text files and i want to read staff from the other two and append it to one .how do i do it??

when opportunities arises ,only the prepared mind is fovoured

RESOLVED Read Text File And Append Into Another Text File
I have a text file named names1.txt.... The contents of the names1.txt file is as follows:


Emp id:"B1234"
Emp id:"246810"
Emp id:"B88888"
Emp id:"B55555"
Emp id:"111555"

I want to read the text file and take the value from between the " " where the first character after the " is a letter b followed by a number and append this value into a new txt file named Final.txt.

Final.txt would look like this:

"B1234"
"B88888"
"B55555"

It took only the values between the " starting with B followed by a number...

Code To Read Two Text Files, Concatenate One After The Other, Output To New Text File
hello,
what would be the code that would allow me to read in two text files, concatenate the second one to the end of the first one, then output the file as a new third text file?
thanks in advance,
david

Read Number Of Line In A Text File (text.txt)
Hi,

Anyone has the fastest way to get the number of line in the a text file?

Please share with me.

Thanks.

Read The Text From The Image And Create A Text File
hello expert
i want to make a programe in vb 6.0 in which i have a picture with some text written over it
is there any method to read that text automatically and generate a text file of written text to a particular location.
if yes then send me some ideas

How To Read Text On Text File And Store To Variable
I need to read a text from a text file and store it to variable and use it as a parameter to pass

rgds
cyrus

How Can I Read A Specific Line Of Text From A Text File.
I need to know how to read a specific line of text from a text file. I have searched for this problem and found no obvious solutions. Please help me out if you can. Thanks

Using ADO Recordset, Read From An Access Database File And Write To A Text File
Using the ADO data control and the recordset property I am reading records from an Access data base file, selecting and manipulating records, and then trying to write to a text file. I know how to get the records from the database file, but I need sample code for how to write out to a text file.
Thanks

cruella69

Read Chinese From Text File - Input Past End Of File
I have a text file with content of Chinese character which is store as ANSI format. When i call the function below, it give me error "Run-Time Error '62'. Input past end of file".

sFileName3 = "abc.txt"
sFilePath = sParentPath & sFileName3
Open sFilePath For Input As #1
sBasicDesc = Input(LOF(1), #1)
Close #1

I tested on 9 PC but 2 PC fail.
Do i miss out any component or the code is not compatible?
Please help.
Thankyou.

How To Read A Text File That Conatains Asp Code Into An Another Asp File And Execute?
Hi,
I just want to know if there is something like the eval() function in ASP ........... I want to read a asp page into another as page using FSO .... and execute it .....

this is the code i now use


Code:
on error resume next

sPage = Request.QueryString("url")

Set filesys = CreateObject("Scripting.FileSystemObject")
path = server.MapPath(sPage)
Set filetxt = filesys.OpenTextFile(path, 1, True)
tl = filetxt.ReadAll
filetxt.Close

if len(tl) < 1 then
Response.write("File Not Found !")
End if

response.Write(tl)


now when I read a asp page using this code the page includes and the asp codes are not executed ........

How can I read and excute a ASP file .......

http://www.weareequal.org/goto_text.asp?url=Home

Regards,
Dasith

Very Urgent How To Read Text From .doc File Into Text File
hi this is very urgent
 
i have a document file . i have to open the document file programatically read text data from it and craete a new text file file paste the text data into it

please help me how to do this in Vb 6.0

How Do I Read A Text File Into A Rich Text Box?
hey i want to read from a text file and display it in a text box... any ideas?

[VB6] Read In A File Delete Text And Write File
I have a tab delimited text file that I need to read in, remove text up to and including the first CR/LF and then write the remaining text back out to a file.

In the example file below, the first CR/LF is after 20080513 (although that number could be different). The file always starts with the word "Report". As an example, what I need to do in the file below is read the file in, remove the first line up to and including the CR/LF (which in the case below is Report Executed at Mon May 14 20:28:24 CDT 2007 for dates between 20070315 and 20080513 ) and then write the remainder of the file back out to another file.


Here is an example of the tab delimited file: (sample.txt)

Report Executed at Mon May 14 20:28:24 CDT 2007 for dates between 20070315 and 20080513
WRIDTTNASGN GROUPWCOOSJOBTYPETZCOMM_DTTMRPT_DTTMLOAD_START_DTTMLOAD_END_DTTMSOURCESTATUSBUCKET
5036884471089GA_Atl_NORTHEAST_D404295MRDLCTEASTERN20070316 23:5920070316 09:2420070316 00:0120070316 00:01LMOSPENDINGNONDEMAND
50398881236676GA_W_ROME_NEWNAN_PC770408MRMIFTEASTERN20070319 23:5920070319 04:5620070319 00:0120070319 00:01LMOSPENDINGNONDEMAND
50398885236800GA_W_ROME_NEWNAN_PC770400MBCTRTEASTERN20070319 23:5920070319 04:5720070319 00:0120070319 00:01LMOSPENDINGNONDEMAND
50398886236831GA_W_ROME_NEWNAN_PC770400MBCTRTEASTERN20070319 23:5920070319 04:5720070319 00:0120070319 00:01LMOSPENDINGNONDEMAND
50422929261569GA_W_ROME_NEWNAN_PC770400MRMIFTEASTERN20070320 23:5920070320 04:5120070320 00:0120070320 00:01LMOSPENDINGNONDEMAND
50489568333675GA_W_ROME_NEWNAN_PC770400MBCTRTEASTERN20070323 23:5920070323 04:5620070323 00:0120070323 00:01LMOSASSIGNNONDEMAND

Thanks in advance for your help...

How To Read Binary File And Export To Text File ??
how to read binary file and export to text file ??
thanks very much !

How To Read From Text File And Append It To Excel File
could somebody pls help to read from a text file
and append the content to excel file.
the text file format is like this:

abs,123
aaann,89
1111,ybk

and i want to append it to excel file

col1 col2
abs 123
aaann 89
1111 ybk

please help

How Do I Read In A Non-text File ?
I'm having a thicky attack.
I need to load in a custom file format. Basically in blitzbasic i had a file format that stored tiles.
However I cannot work out how i read in the file into VB6 so that i can create an app using them.
The file format is Number of Tiles in the set in WORD format, then 1024 entries of 3 bytes each per tile. (yes, this is a subset of the TST format created by C Matthews). The 3 bytes are BYTE red, BYTE green, BYTE blue.

Any help on how i can read thes in would be really appreciated. Thanks.

Read From Text File
I have text file

ID (Tab) Name (Tab) Value1 (Tab) Value2
1 N1 123 87.12
2 N2 67.10 54.12
..... ........ ....... ........

I define structure :
Type Oneline
ID as string
Name as string
V1 as double
V2 as double
End type

I want read text file, each line in to structure Online (VB program)

Thanhs.

Read Text File
Hi there

Please could someone advise me, i am used to looping through a db getting the data that i need, but now i need to loop through a text file and pick out certain data. So what i have is a list box populated with names and two dtpickers for date selection. So what i need to do is pick out only the data from the text file that match the name in the listbox and the dates from the dtpickers, and don't know where to start, could i use a select statement to get the data, not sure, Please could someone advise me.

Many thanks

Read Text Out Of File
Hi all!

Is it possible to read 32 characters of text out of a file? The text starts at offset 32881 and ends at 32912. The file is binary and you can only open it with a hex editor. I tried a lot of ways, but can't find the good way. Sorry for my poor English and thanks in advance!

Read Text File From Web
How do i open a text file for reading from a website?

Read From Text File
I have been looking all morning and have read alot of information but I can not figure out how to read from a text file.

What I need to do is have a text file that only has lets say tn1 in the file. When my program starts up I need it to read tn1 from the text file and place it in a textbox we will call t1.text. The reason for this is my program connects to a remote mysql and tn1 will tell the program what record to read from. I could hard code this but I have several I am doing and would like to be able just to use a text file that I can type tn1 in the first and compile it with the program and then on the second program type in tn2 in a text file and compile it with the program and so on and so on.

Thanks in advance for any help anyone can give me on this.

Read From Text File
I need to write a program that can read data saved to a text file. I used the open filename dealy from a sepate form to get the information and that works fine. But on a different form, I need to read the text file and display the info in a picture box. I'm not really sure how to go about this. I probably don't have the right code, but I keep getting "0" with the code I had. I've got another question. And this is probably pretty easy, but I can't get it to work. How do I only allow numbers to be entered into a text box? Thanks for your help.

Read From Text File
How do we read the text from the text file just like the Apiviewer application does with win32api.txt file?

Will somebody give me a small (not big pls) example so that i will understand it easily?

Read A Text File From An URL?
How might I do this?

My first attempt was just to change the file path from a local directory to the URL, that failed miserably

Read From Text File
I've got a routine to import a text file into my access DB. The first line of the file looks like: 1,Fish'n'Chips where 1 is the Order Number and Fish'n'Chips is the Order Name.

What I need to do is read the first line and extract only the Fish'n'Chips part of the string as I then search my database for an existing record with the same name. The "Order Number and "Order Name" change with each new order.

Can someone give me a suggestion or even better post some example code.

Thanks.

Read A Text File From SQL
I think this is the correct forum to post this, forgive me if I'm wrong.

I have a comma delimited text file that I want to load to a SQL table. This operation needs to take place on a regular basis so I don't want to use the data transformation wizard to import it to a temp table first.

Ideally, I would like to know what the syntax is to read this text file from a stored procedure and load it to a table.
If I need to first load it to a temp table via stored procedure, that would work just fine.

Any ideas?

How To Read A Text File?
I save a text file that is defined using CommonDialog1.filename. And the file extension is *.SAV. I wish to get open it in the Open CommonDialog Box.

How would I go about it and what would the code look like?

Read From Text File
Code:
Private Sub Form_Load()
On Error Resume Next
Dim strLogs As String
Dim FF As Integer

FF = FreeFile
Open "C:ChatLog.txt" For Input As #FF
Input #FF, strLogs
Close #FF
rtbLogs.Text = strLogs
End Sub


This only puts the top line of my chat logs into the text box.

Can I read and put ALL the text into the text box?

Thanks,
Philly0494

Read From Text File
i have a text file i want to read this from vb6 is this possible can anyone have code these records are seperated by |

How To Read Text File
hi,

I want to read a text file using the vb. what I want is.....
I have a text box and two command buttons. When user click on 1st button a open file dialog box should be opened and use should be able to select any .txt file. The selected file name should be displayed in the text box.After that, when user clicks on next button the lines from the selected text file should be displayed in message box. Specifically When the new line character is encountered the message box should be displayed.

Can any one help me please?
Thanks

Read From End Of Text File
I need to monitor the log output of a system. The system appends a text file every second with new data. (to the end of the file)

i want to parse this file every second and read what is logged.

i cannot however modify the file, or even copy it because the other application keeps it open.

i basically want to read the last couple of lines of text.

is there a way to open a text file and start reading from some spot near the end rather than having to read in the entire file?

Read Text File
hi
i was wondering if it is possible to find how many line r n a text file and then find out wats on line 10 and assign to textbox
thanks n advance

Read Text File
Hi

Please could someone advise me on the following, i need to loop through a text file picking out certain data. Basically i have a listbox populated with names and two dtpickers for date selection, i have the following code to open the textfile but don't know how to cycle through it picking out the data that match the criteria.


VB Code:
Private Sub cmdView_Click()    Dim FF As Integer        FF = FreeFile            Open "C: est est.txt" For Input As FFEnd Sub


Please could somene help me.

Many thanks

Read Text File
i have a text file contains


Quote:




!! HELLO !!
3D4DCAHDGDBD$8&$^&D^&$^&D^&$






i want only 3D4DCAHDGDBD$8&$^&D^&$^&D^&$ to be appeared on my textbox..

how to do this?

br

How To Read Utf-16 Text File
Hi,

I'm trying to write code to read and then write a UTF-16 text file. Can anyone give me sample code to do this? Thanks a lot..

Read Text File
I have a text file as attached and I want to read the GROUPID NUMBER AND the Category and descriptions for each GROUPID NUMBER

gROUPid nUMBER CATEGORY description

AAL 001 AA LLC OUT-OF-NETWORK DED
AAL 002 AA LLC IN-NETWK OUT-OF-POCKET

Any help is appreciated..

Thanks,

Prasad

Read A Text File
Sir,
I want to open a text file and read the lines , using VB6, till it finds a line starting with "Total:" . Some numbers are on the same line ; but the 1st number needs to be stored into a variable.
Ex:
Total: 5340 2930 2410 2394

5340 needs to me stored into a variable.

Thanking you in advance
M.Manoj









Added [RESOLVED] to thread title and green "resolved" checkmark - Hack

How To Read A Text File?
hello how read a text file like this:


Code:
UFS/TWISTER old and new activations generator
You know who done it...

serial (dec) Ericsson:015ED37847CA4E283D Ericsson:01E0C3E8ECA0BEA75B
Nokia:05954E6146733ADF3D Nokia:05A0ECB4E8998267D6
Motorola - Acer:06184DEB64D91AC155 Motorola - Acer:06FD67A40BAB229C06
Samsung:0CEC53EF543947DB51 Samsung:0C00B7561D006D320B
Siemens:0D5B9C9F17CA61631B Siemens:0D2848972318388D1E
press Enter...


i want only to read the data in the right side...

Thanks

Read Text File
Hey,how can i read data from text file and load it into a texbox,listbox

Read From Text File
Ok I have a giant file full of names my question is how can i read and organize it. Here is the code I have so far , but it gets an overflow error.



VB Code:
Private Sub Form_Load() Dim ReadFF As String                    Open "C:Documents and Settings
ub3xDesktopNicks.txt" For Input As #1                    Do While EOF(1) = False                        Line Input #1, ReadFF                        Dim k$, y%                        k = ReadFF                        y = InStrRev(k, ":")                        y = y + 2                        Text1.Text = Left(k, Len(k) - y)                    Loop                 Close #1End Sub

Im going to put it in another text file instead of a text box that was just an example. The first few lines of the file look like this:


Code:
afabian:~afabian:cs70112247-52.austin.rr.com:Leah
Hoedin:SUP:user-1120j76.dsl.mindspring.com:Robin
cynic`:Snake:recky.user.gamesurge:Louisa
s^BeaneR:s_BeaneR:pcp0010312966pcs.avenel01.nj.comcast.net:Lily


The format im trying to get them in is:


Code:
afabian:~afabian
Hoedin:SUP
cynic`:Snake
s^BeaneR:s_BeaneR


So basicly chopping off the mask.

Read Text In File
How can I search a text file for a word?

Thanks,
Sir Loin

Read A Text File
Ok, im kinda new to VB 6.0, i am 15 but am learning slowly.

I have a new form, i also have a label and a comman button, the click event for the command button is:

Private Sub Command1_Click()
dim username as string

username = inputbox("Enter your name:")

If username <> "" then
label1.Caption = "Your password is: " & "password"
else
label1.caption = "Please enter a valid username!"
end if

end sub

Now then, i need the program to scan through a '.txt' file and find the username, in the text file, the password is also listed. How do i get the program to find the line with the username in and then display the password as the second variable? Thankyou for your help

Read From Text File
I am writing web application authentication ,instead of specifying the username list in the code, I want to put that in a .txt file, so anyone can edit it.
can any one show me how to read data from a .txt file and put them in an array?

the text file looks like this...
username1
username2
username3

I want to put them back to a string array.

How To Read From A Text File
hi, i have encounter a problem when doing my vb application.
that is how do i read from a txt file....

inside the txt file is a list of content. i need it to read it line by line and put it in a combo box.....

when i click on the combo box there will be a list of item that is load from the text file....

anyone can help...

Ah Xing

Read From Text File
I've got a routine to import a text file into my access DB. The first line of the file looks like: 1,Fish'n'Chips where 1 is the Order Number and Fish'n'Chips is the Order Name.

What I need to do is read the first line and extract only the Fish'n'Chips part of the string as I then search my database for an existing record with the same name. The "Order Number and "Order Name" change with each new order.

Can someone give me a suggestion or even better post some example code.

Thanks.

Read Text File
how do i read a text file

How To Read From A Text File
Hello. I have a project i'm working on and it deals with list boxes. The problem i'm having is that I can't take what i've saved to the text file, and display it in a label when i click on the specific list item ive added. I've uploaded all the files needed to debug this program, if someone could help me with this problem i would gladly appreciate it. Thanks in advance.

www.bridgeport.edu/~cottrell/vb/

The site above is my personal site, and it gives you all the information that i'm suppose to do with this program.

To Read A Text File
i want to open a text file and read the contents of it through VB.
How to do the. Can some one give me the code.

Copyright 2005-08 www.BigResource.com, All rights reserved