[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VB6 add a minute to the date time value

Posted on 2016-08-23
8
Medium Priority
?
108 Views
Last Modified: 2016-08-24
Hi

I'm trying to add a minute to the date / time value in column 1 of the value in column 1 = the value in column 0.

date time
ex: if column 0 and 1 have the value "09/14/2016 13:00:00" then in column 1, it will add 1 minute. The result would then be: 09/14/2016 "13:01:00".

I tried like below but no luck.

Private Sub Command1_Click()
    Dim kk As Long

    For kk = 1 To MSHFlexGrid1.Rows - 1

        If MSHFlexGrid1.TextMatrix(kk, 1) = MSHFlexGrid1.TextMatrix(kk, 0) Then
          '  MSHFlexGrid1.TextMatrix(kk, 1) = Format(CDate(Format(MSHFlexGrid1.TextMatrix(kk, 0), "0000-00-00 00:00")) + DateAdd("n", 1, Time()))
        End If

    Next kk
End Sub

Open in new window


How can i do that?

Thanks
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 41767950
Without a project to test with it's hard, but try

MSHFlexGrid1.TextMatrix(kk, 1) = Format(CDate(Format(MSHFlexGrid1.TextMatrix(kk, 0), "0000-00-00 00:00")) + DateAdd("n", 1, MSHFlexGrid1.TextMatrix(kk, 0)))
        End If
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41767971
Just tested and i have an error of incompatible type.

Here is the sample.
TEST-DATE.zip
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41768024
I think i was able to do it like this. But it does not look too clean.

I will test it more:

    Dim kk As Long

    For kk = 1 To MSHFlexGrid1.Rows - 1

        If MSHFlexGrid1.TextMatrix(kk, 0) <> "" Then
            MSHFlexGrid1.TextMatrix(kk, 0) = Mid(MSHFlexGrid1.TextMatrix(kk, 0), 7, 4) & Left(MSHFlexGrid1.TextMatrix(kk, 0), 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 4, 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 12, 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 15, 2)

        End If

        If MSHFlexGrid1.TextMatrix(kk, 1) <> "" Then
            MSHFlexGrid1.TextMatrix(kk, 1) = Mid(MSHFlexGrid1.TextMatrix(kk, 1), 7, 4) & Left(MSHFlexGrid1.TextMatrix(kk, 1), 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 4, 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 12, 2) & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 15, 2)

        End If
        On Error Resume Next
        If MSHFlexGrid1.TextMatrix(kk, 1) = MSHFlexGrid1.TextMatrix(kk, 0) Then
            MSHFlexGrid1.TextMatrix(kk, 1) = Format(CDate(Format(MSHFlexGrid1.TextMatrix(kk, 0), "0000-00-00 00:00")) + 0.001, "yyyymmddhhnn")
            
        End If
        
         If MSHFlexGrid1.TextMatrix(kk, 0) <> "" Then
            MSHFlexGrid1.TextMatrix(kk, 0) = Mid(MSHFlexGrid1.TextMatrix(kk, 0), 5, 2) & "/" & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 7, 2) & "/" & Left(MSHFlexGrid1.TextMatrix(kk, 0), 4) & " " & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 9, 2) & ":" & Mid(MSHFlexGrid1.TextMatrix(kk, 0), 11, 2) & ":" & "00"
            MSHFlexGrid1.TextMatrix(kk, 1) = Mid(MSHFlexGrid1.TextMatrix(kk, 1), 5, 2) & "/" & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 7, 2) & "/" & Left(MSHFlexGrid1.TextMatrix(kk, 1), 4) & " " & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 9, 2) & ":" & Mid(MSHFlexGrid1.TextMatrix(kk, 1), 11, 2) & ":" & "00"
        End If

    Next kk

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 41768153
Try this and tell me what's wrong (if anything).
Private Sub Command1_Click()
    Dim kk As Long

    For kk = 1 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(kk, 0) <> "" Then
            If MSHFlexGrid1.TextMatrix(kk, 1) = MSHFlexGrid1.TextMatrix(kk, 0) Then
                MSHFlexGrid1.TextMatrix(kk, 1) = Format(DateAdd("n", 1, MSHFlexGrid1.TextMatrix(kk, 0)), "mm/dd/yyyy hh:mm:ss")
            End If
        End If
    Next kk
    
    'Auto column fit
    Dim cell_wid As Single
    Dim col_wid As Single

    For c = 0 To MSHFlexGrid1.Cols - 1
        col_wid = 0
        For r = 0 To MSHFlexGrid1.Rows - 1
            cell_wid = TextWidth(MSHFlexGrid1.TextMatrix(r, c))
            If col_wid < cell_wid Then col_wid = cell_wid
        Next r
        MSHFlexGrid1.ColWidth(c) = col_wid + 120
    Next c

    '---------- Align MSHFlexgrid ----------------
    With MSHFlexGrid1
        Dim k As Long
        For k = 0 To .Cols - 1
            .ColAlignment(k) = flexAlignLeftCenter
        Next
    End With
    
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41768503
I'm almost there. The only thing left is that instead of putting a "/", it puts a dash "-".

result
I assume i can do a replace and that would fix it unless you see that it could be done a better way.

Like below:
    Dim kk As Long
    Dim txt As String

    For kk = 1 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(kk, 0) <> "" Then
            If MSHFlexGrid1.TextMatrix(kk, 1) = MSHFlexGrid1.TextMatrix(kk, 0) Then
                MSHFlexGrid1.TextMatrix(kk, 1) = Format(DateAdd("n", 1, MSHFlexGrid1.TextMatrix(kk, 0)), "mm/dd/yyyy hh:mm:ss")
                
                txt = MSHFlexGrid1.TextMatrix(kk, 1)
                If InStr(txt, "-") Then
                    txt = Replace(txt, "-", "/")
                    MSHFlexGrid1.TextMatrix(kk, 1) = txt
                    MSHFlexGrid1.Row = kk
                    MSHFlexGrid1.Col = 1
                    MSHFlexGrid1.CellBackColor = &H80FF&
                End If
            End If
        End If
    Next kk

Open in new window


what do you think?
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 41768586
I will go with this solution and add the replace function to it.

Thanks a lot again for your help.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 41768827
Are we using the same code? This is what I see.
????
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 41768882
yes, i was using the same code.

Probably a regional setting problem.

 For kk = 1 To MSHFlexGrid1.Rows - 1
        If MSHFlexGrid1.TextMatrix(kk, 0) <> "" Then
            If MSHFlexGrid1.TextMatrix(kk, 1) = MSHFlexGrid1.TextMatrix(kk, 0) Then
                MSHFlexGrid1.TextMatrix(kk, 1) = Format(DateAdd("n", 1, MSHFlexGrid1.TextMatrix(kk, 0)), "mm/dd/yyyy hh:mm:ss")
            End If
        End If
    Next kk

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question