Welcome! Log In Create A New Profile

Advanced

Last Value in a Table - Basic Question !

Posted by Denis Vaughan.pcs.crosspost 
Denis Vaughan.pcs.crosspost
Last Value in a Table - Basic Question !
August 19, 2008 07:48PM
Hi, I am trying to get the value of a column from the last record in a table.

I have tried to use HLast, HSeekLast but can't seem to get the value.
I also tried to create a Select Query giving me the MAX of the column in question (it is an incrementing number). This works in Query Test, but when I try to update a variable it only gives the value 1 which I assume is a true/false type value.

Can anyone advise - new to WINDEV.

DV

Message forwarded from pcsoft.us.windev
Art Bonds
Re: Last Value in a Table - Basic Question !
August 19, 2008 08:04PM
Have you tried HReadSeekLast?
Piet van Zanten
Re: Last Value in a Table - Basic Question !
August 19, 2008 09:07PM
Hi, it's hreadlast
Regards,
Piet
Gautam.pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 20, 2008 03:55PM
When you refer to a 'Table' are you referring to a Table Control? or are you referring to a Data file in the database?

To access the last record in a table control assuming you have a table called TABLE1 and columns called Name, Address etc

you can try something like :

sName is string
sName = Table1.Name[Table1..occurrence]

the above code will return the Name column value from the last row of the table and assign it to the sName variable.

If you are looking for the last record in a data file then you can use the HREADLAST command.

Hope this helps.

Gautam

Message forwarded from pcsoft.us.windev
Denis Vaughan.pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 20, 2008 04:20PM
Hi Gautam

Thank you for your response.

I am trying to read the last value from a data file. I have used HREADLAST but it is not giving me the value I expect.

The data file as 28 rows and the last row has an ID of 28. I have the following code against a button control and to test I was showing the returned value in an edit box:

gnMatchTableNextId=HLast(matched,MatchID)
EDT_LastMatch=gnMatchTableNextId

The value it returns is always 1

The data file is a table in MS Access

Thanks

Denis

Message forwarded from pcsoft.us.windev
"Michel HERRSCHER".pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 20, 2008 05:05PM
check if that field is defined as a key and start the
"hlitrechecherserrnier" (sorry for french) using this key.

--
Michel HERRSCHER Consultant
tel : +33450870912

"Denis Vaughan" <denis.vaughan@pocasystems.ie> a écrit dans le message de
news: 261f8e9824711b88e158f1c52b9fd424@news.pcsoft...
>
> Hi Gautam
>
> Thank you for your response.
>
> I am trying to read the last value from a data file. I have used HREADLAST
> but it is not giving me the value I expect.
>
> The data file as 28 rows and the last row has an ID of 28. I have the
> following code against a button control and to test I was showing the
> returned value in an edit box:
>
> gnMatchTableNextId=HLast(matched,MatchID)
> EDT_LastMatch=gnMatchTableNextId
>
> The value it returns is always 1
>
> The data file is a table in MS Access
>
> Thanks
>
> Denis
>


Message forwarded from pcsoft.us.windev
Denis Vaughan.pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 20, 2008 05:37PM
Hi, MatchID is defined as Key.

Thanks

DV

Message forwarded from pcsoft.us.windev
Piet van Zanten
Re: Last Value in a Table - Basic Question !
August 20, 2008 09:23PM
Hi Denis,

Hlast only points the index file to the last record and does not read the data (the file buffer is not updated). You should use hReadLast

Best regards,
Piet
Denis Vaughan.pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 21, 2008 10:35AM
Hi,

I am using the following:

gnMatchTableNextID=HReadLast(matched,MatchID)
EDT_LastMatch=gnMatchTableNextID

Thanks

DV

Message forwarded from pcsoft.us.windev
Piet van Zanten
Re: Last Value in a Table - Basic Question !
August 21, 2008 12:47PM
Hi Denis,

Try:
HReadLast(matched,MatchID) 
gnMatchTableNextID=matched.MatchID

Regards,
Piet
Hello Dennis

If you check the help you will see that most windev commands return a boolean value to indicate the success of the command or not, so your code:

gnMatchTableNextID=HReadLast(matched,MatchID)

can only ever return 1 for a succesful operation or 0 or -1 for an unsuccessful operation.

Piet's code will work because it assigning the file field value from the read buffer.

Why not access this forum directly rather than via the PCSoft newsgroup. I think you will get a quicker response
[forum.mysnip.de]

Regards
Al



Edited 1 time(s). Last edit at 08/21/2008 05:25PM by Al.
"Michel HERRSCHER".pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 22, 2008 09:37AM
CQFD ( french acronym) ... Roger has got it.

(Same response from me)

--
Michel HERRSCHER Consultant
tel : +33450870912

"Roger Dunk" <roger@at.com.au> a écrit dans le message de news:
48adec86@news.pcsoft.fr...
>
>
>
> Hi Denis,
>
> The return value of the HReadLast function is a Boolean, describing
> whether
> a record was successfully read or not.
>
> Assuming "matched" is your file name (table), and MatchID the column you
> are
> searching on, what you need is:
>
>
> HReadLast(matched,MatchID)
> EDT_LastMatch = matched.MatchID
>
>
> Cheers...
> Roger
>
> "Denis Vaughan" <denis.vaughan@pocasystems.ie> wrote in message
> news:0008338a348d928a62785d277a9bea35@news.pcsoft...
>>
>> Hi,
>>
>> I am using the following:
>>
>> gnMatchTableNextID=HReadLast(matched,MatchID)
>> EDT_LastMatch=gnMatchTableNextID
>>
>> Thanks
>>
>> DV
>>


Message forwarded from pcsoft.us.windev
Denis Vaughan.pcs.crosspost
Re: Last Value in a Table - Basic Question !
August 22, 2008 10:57AM
Richard / Michel,

That's brilliant thanks. I know all very basic but it's a big help, worked perfect.

Regards

Denis

Message forwarded from pcsoft.us.windev
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: