By w0051977


2013-10-05 17:08:34 8 Comments

Please see the DDL below:

CREATE TABLE TestDate (bookingdate datetime)
INSERT INTO TestDate VALUES ('2013-10-04')

Please see the ADODB recordset below:

rs.open "SELECT bookingdate FROM TestDate"
If rs("bookingdate") > dateadd("yyyy", -6, Now)
  msgbox("test")
end if

What is the difference between specifying rs("bookingdate") and rs("bookingdate").value. I have read some questions on here where answerers say always use .value, but it is not explained why. I had a look on MSDN but could not find an answer.

1 comments

@GSerg 2013-10-05 17:18:59

Value is the default property of the Field object, so in VB6 there is no difference between rs("bookingdate") and rs("bookingdate").value when used without Set.

I personally prefer not using default properties that don't take parameters. It makes the code less confusing IMO.

In VB.NET the default property must have a parameter, so this situation does not occur.
Note Recordset has such default property with parameter, and you are using it to return the Field object: rs("bookingdate") is actually rs.Item("bookingdate"). Using those, IMO, makes no harm.

@w0051977 2013-10-05 17:36:53

SET involves manipulating the reference according to your link. Is that correct?

@GSerg 2013-10-05 18:14:10

@w0051977 Yes, it involves manipulating the reference. E.g. you could declare a variable f of type Field and Set f = rs("bookingdate").

@Bob77 2013-10-05 22:23:43

Not true. There are many cases where Set isn't a factor, such as any time you pass the expression as an argument to some procedure.

@GSerg 2013-10-06 08:05:09

@Bob77 While passing parameters is a different matter that has little to do with assigning variables, it also may or may not use default properties (which also adds confusion). If you take expression rs("bookingdate") and pass it to a procedure that accepts a Field, Object or Variant parameter, the Field object will be passed. If you pass same expression to a procedure that accepts e.g. a String parameter, the compiler will call rs("bookingdate").Value and pass that.

@Bob77 2013-10-06 17:07:39

It seems like everyone wants to contrive examples to prove that lazy reliance on default properties is a healthy thing. It isn't and has never been a recommended practice. It makes it harder for anyone (including the compiler) to know what's intended. However... you always have the option to do so, it just isn't considered good practice.

@GSerg 2013-10-06 17:47:59

@Bob77 Who is doing that? I'm not. The people the OP met aren't doing it either.

Related Questions

Sponsored Content

1 Answered Questions

[SOLVED] Populating listbox vb6 with recordset

  • 2014-09-17 04:20:18
  • alejandro carnero
  • 2433 View
  • 0 Score
  • 1 Answer
  • Tags:   vb6

2 Answered Questions

[SOLVED] Populate DBCOMBO in VB6 with recordset

  • 2016-09-28 13:57:31
  • alejandro carnero
  • 710 View
  • 2 Score
  • 2 Answer
  • Tags:   vb6

0 Answered Questions

SELECTing data from SQL-SERVER to be formatted in a certain way

1 Answered Questions

[SOLVED] Is output parameter a string or date?

1 Answered Questions

[SOLVED] How to construct a Recordset object with multiple Recordsets inside it?

  • 2013-04-19 17:55:38
  • AngryHacker
  • 1702 View
  • 1 Score
  • 1 Answer
  • Tags:   vb6

2 Answered Questions

[SOLVED] .NET Thread unsafe code

4 Answered Questions

[SOLVED] Copy one Recordset to another

  • 2012-11-20 14:09:55
  • user1838163
  • 17982 View
  • 3 Score
  • 4 Answer
  • Tags:   vb6

1 Answered Questions

VB6 Recordsets and SQL count

  • 2012-01-06 12:54:21
  • w0051977
  • 1337 View
  • -2 Score
  • 1 Answer
  • Tags:   vb6

1 Answered Questions

[SOLVED] updating the table using recordset

  • 2009-12-09 01:06:50
  • pbrp
  • 673 View
  • 0 Score
  • 1 Answer
  • Tags:   vb6

2 Answered Questions

[SOLVED] assign table values to recordset and update with another recordset using vb6

  • 2009-12-04 20:28:23
  • pbrp
  • 1889 View
  • 0 Score
  • 2 Answer
  • Tags:   vb6

Sponsored Content