Page 1 of 2
DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 5:13 am
by Djiber
I have function that's called with button click and it should populate DBF with DATA from another DBF.
I'm stuck cause I don't know why it doesn't do that for all DATA (It does it for 1'st line only)
Can some1 explain me what I'm doing wrong except everything
Code: Select all
FUNCTION Manj()
LOCAL ID:=Space(20), Dat, VP:=Space(5), VK:=Space(5)
USE Manj NEW INDEX Manj
USE Message NEW INDEX Datum, User
SET ORDER TO "Datum"
DO WHILE .NOT. EOF()
ID = FROM_USER
Dat = DATE
IF MSG = "In"
VP = TIME
ENDIF
IF MSG = "Out"
VK = TIME
ENDIF
SKIP
SELECT Manj
Mreza(); Append Blank
Mreza(); Replace User_ID With ID,;
Datum With Dat,;
Vri_P With VP,;
Vri_K With VK
CLOSE Manj
ENDDO
RETURN .T.
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 5:32 am
by GeneB
You are not reselecting the dbf that you are trying to go to the end of.
Change the last lines to:
SELECT Manj
Mreza(); Append Blank
Mreza(); Replace User_ID With ID,;
Datum With Dat,;
Vri_P With VP,;
Vri_K With VK
// CLOSE Manj // delete this line and close it after the ENDDO loop
SELECT Message // add this line
ENDDO
// close the dbf's you have opened
// erase any indexes created only for this routine
RETURN .T.
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 5:49 am
by Djiber
Thanks, that solved my problem
Or maybe not, I get only 10 lines now and again don't know why
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 6:26 am
by bwolfsohn
USE Message NEW INDEX Datum, User
SET ORDER TO "Datum"
DO WHILE .NOT. EOF()
add a go top before the do while .not. eof()
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 8:29 am
by Djiber
Still I get just 10 Lines
Code: Select all
USER_ID DATUM VRI_P VRI_K
AMIHA 1.3.2012
ADMIN 1.3.2012
AMIHA 1.3.2012
ADMIN 1.3.2012
ADMIN 1.3.2012
AMIHA 1.3.2012
AMIHA 1.3.2012
ADMIN 1.3.2012
ADMIN 1.3.2012 15:54
ADMIN 21.3.2012 15:54 10:43
Is it problem cause some messages aren't In or Out, but just some gibberish so it's getting data just until he get all variables.
(I've changed 10'th entry into In and nothing changed so I guess that's not problem - Last entry doesn't have Vri_K now and Vri_P is 10:43)
Or is it maybe problem cause in Message DBF there's just 1 column with Messages
Code: Select all
FROM_USER DATE TIME MESSAGE
AMIHA 1.3.2012 14:37:26 sdfsadfasd
ADMIN 1.3.2012 14:41:03 "Hi"
AMIHA 1.3.2012 15:08:38 "Hi"
ADMIN 1.3.2012 15:08:51 "Sup"
ADMIN 1.3.2012 15:09:02 hedsgsfdg
AMIHA 1.3.2012 15:16:03 sdgdfgsd
AMIHA 1.3.2012 15:19:44 fdgadsasdf
ADMIN 1.3.2012 15:54:40 dfgsdfgdfg
ADMIN 1.3.2012 15:54:45 In
ADMIN 21.3.2012 10:43:54 Out
ADMIN 21.3.2012 16:04:11 In
ADMIN 21.3.2012 16:04:15 Out
ADMIN 21.3.2012 16:04:20 In
ADMIN 21.3.2012 16:04:23 In
ADMIN 21.3.2012 16:04:28 Out
ADMIN 21.3.2012 16:04:32 Out
I would like to accomplish that Manj.DBF take Time from same user that sent In and Out
I didn't even try that with user cause I had EOF problems
So basically I would like to do this:
Message.DBF:
Code: Select all
ADMIN 21.3.2012 16:04:32 In
John 21.3.2012 16:05:32 In
ADMIN 21.3.2012 16:24:32 Out
Steve 21.3.2012 16:32:32 In
Steve 21.3.2012 16:36:32 Out
John 21.3.2012 16:40:32 Out
Manj.DBF
Code: Select all
ADMIN 21.3.2012 16:04:32 16:24:32
John 21.3.2012 16:05:32 16:40:32
Steve 21.3.2012 16:32:32 16:36:32
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 10:50 am
by skiman
Hi,
Always work with the alias names. This way your code will be more readable.
Code: Select all
FUNCTION Manj()
USE Manj NEW INDEX Manj
USE Message NEW INDEX Datum, User
SET ORDER TO "Datum"
DO WHILE !message->(EOF())
IF message->MSG = "In" .or. message->MSG = "Out"
manj->(dbappend())
manj->user_id := message->from_user
manj->datum := message->date
manj->.... := message-> ...
endif
message->(dbskip(1))
ENDDO
close manj
close message
RETURN .T.
This way you will have shorter code.
Hope this sample helps.
Re: DO WHILE .NOT. EOF
Posted: Thu Mar 22, 2012 8:05 pm
by GeneB
In your code, what does Mreza() do ?
Re: DO WHILE .NOT. EOF
Posted: Fri Mar 23, 2012 2:45 am
by Djiber
Mreza is function that's checking if DBF is edited by another user/computer.
Thanks skiman, I'll try to use Aliases and see will that solve my problem.
Still only 10 lines are checked
Code: Select all
USER_ID DATUM VRI_P VRI_K
ADMIN 1.3.2012 15:54 15:54
ADMIN 21.3.2012 10:43 10:43
Re: DO WHILE .NOT. EOF
Posted: Fri Mar 23, 2012 7:27 am
by bwolfsohn
remove mreza() and see if you still only get 10 records.
Re: DO WHILE .NOT. EOF
Posted: Mon Mar 26, 2012 1:06 am
by Djiber
I did, same result, but I've solved my problem by creating function for Indexing and then reindex everything with it, now it works like a charm ( At least until I get some error
).
Now I just need to figure out how to filter same user and use his messages to get In and Out for every user.