hey..
can someone help me here??

how can i get the second to the last
and the last record in the notepad??

then, i will subtract those values and
insert into the database.

tnx. im using vb6 and mysql.

Recommended Answers

All 6 Replies

There are no records in the notepad. Notepad is a binary executable file -- a program. It contains no data.

There are no records in the notepad. Notepad is a binary executable file -- a program. It contains no data.

no..i mean there are numbers written and saved in a notepad (.txt file)
example:

5
4
3
2
1

i need to get 2 and 1 then subtrat it using vb6.

then, next will be:

5
4
3
2
1
6

so, i need to get 1 and 6..then subtract it again.
tnx..

hi newbie26, its quite hard to achieve what you want. you have two loop through the contents of the notepad count the number of entries, then from there you can get the second to the last record.

why not put the data on an excel file it's quite easy to manipulate excel you can use VBA.

but anyway since you want it to do by notepad, check out this thread it will give you an idea.
http://www.daniweb.com/software-development/visual-basic-4-5-6/threads/72344

1 Read a number. Save it.
2 Read another number.
3 Is it the last number?
4  if not save it and go back to 2
5  if so subtract this number and the saved one
Member Avatar for gowans07
Open App.path & "\ FileName.txt" For Input as #1
    Do until not EOF(1)
         Line input #1, Temp
         LstTemp.additem Temp
    Loop
Close #1
Counter = LstTemp.ListCount
2ndlast = LstTemp.List(Counter-2)
Last = LstTemp.List(Counter -1)
DBVal = 2ndLast - Last

Not tested - Thats all i could come up with let me know if it works

You need to read the text file using the Microsoft Scripting Runtime Libary or
just use the older file function Line Input to loop through the lines of the text file.

If you use the Scripting Runtime Library, then you'll need to use the TextStream Object using its ReadLine function to loop through the lines of the text.

Use a loop to read and keep track of the lines storing the individual lines in a string array. If you declare an integer variable to keep track of the number of lines read in the loop, then you can use its last value to determine the last line read. And the previous value will be one less.

The previous post shows how to use Line Input. But you'll need to add code to save the individual lines of code so that you can use the saved values to enter into your MySQL database.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.