Not sure which code to use

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,816
Hi,
I had this in use the other day,
Code:
[COLOR=#333333]TextBox2.Value = Format(CDbl(Date), "dd/mm/yyyy")[/COLOR]
I was told that the CDbI was not needed so i put this in use.
Code:
TextBox2.Value = Format(Date, "dd/mm/yyyy")
Looking through some of my code i see this pop up in a few places so the thing is do i need to change / edit it or what,i dont even know what it does or doesnt do with regards the CDbI
Code:
TextBox1.Value = Format(CDbl(Date), "dd/mm/yyyy")
Can you advise please
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,254
Office Version
2013
Platform
Windows
CDbl is a function that converts a value to a double integer data type. Since the Date Constant is already a double interger data type, the CDbl function is not needed, but it does not hurt anything if it is there. You can delete it or leave it alone and the results are the same for the Format function. If the intent was to make the TextBox2 value a double then that would need to be done at the point in the code where that value is applied to something. But, more likely, the CDate funtion would be used than the CDbl. You can get a full read on the C conversion functions by opening the vbEditor and clicking the Help Icon. Then in the help search box, type 'Conversion Functions' and press Enter.
 
Last edited:

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top