Excel VBA

css navigation by Css3Menu.com

Increment a Hour/Minute String

Someone in my department was showing me where they were trying to build a batch file that would show the times and string to be run every 5 minutes around the clock. I shot my mouth off and said I could write a 7 line macro that would do the trick. I eventually needed the “Select Case” statement to handle the first 2 occurrences each hour.
Sub GenBatch()
    Dim X As Integer, Y As Integer, AntEater As String, M As String
    Dim Iter As Integer
    AntEater = " stuff in the job stream"
    Iter = 0
    Open "C:\JOE.TXT" For Output As #1
    For X = 0 To 23	'Hours 0 to 23 in Military time
        For Y = 0 To 55 Step 5	'Minutes 0 to 55 skip 5s
            Select Case Y
                Case 0
                    M = "00"
                Case 5
                    M = "05"
                Case Else
                    M = Y
            End Select
            Iter = Iter + 1
            Print #1, "First part of " & X & ":" & M & AntEater
	'Print the string to the file
        Next	'Increment Y (minutes) loop
    Next	'Increment X (hours) loop
    Close #1
    MsgBox "Finished with " & Iter & " iterations in the file"
End Sub


First part of 6:50 stuff in the job stream
First part of 6:55 stuff in the job stream
First part of 7:00 stuff in the job stream
First part of 7:05 stuff in the job stream
First part of 7:10 stuff in the job stream

© 2000-2024

Updated:  06/21/2024 07:42
This page added:  01 July 2000