Results 1 to 7 of 7

Thread: time format problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    New Delhi, India
    Posts
    75

    Unhappy

    Just paste this code

    private sub command1_click()
    dim intH as integer, intMin as integer, intSecs as integer
    intH = 0
    intMin = 0
    intSecs = 0

    MsgBox Format(intH & " : " & intMin & " : " & intSecs, "hh:mm:ss")
    end sub

    of course the message box shows 00:00:00


    now change the value of intSecs to 60 and run the code

    now the message box shows 0 :0 :60

    Can anybody help me how do retain the format of hour and minutes to 00 i.e. I wan the result to
    be 00:00:60 if the value of intSecs is 60. Can somebody help me why this the formatting is lost in the second case. urgent help needed

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    you're asking vb to format an invalid value to a standard time format

    try this (if you must)

    MsgBox Format(intH, "00") & " : " & Format(intMin, "00") & " : " & Format(intSecs, "00")
    Mark
    -------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    New Delhi, India
    Posts
    75
    Thanx for the suggestion. It worked for me!!!. I never realized that I am passing illegal values. Can you please explain me why its illegal.

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    i think it would have something to do with vb requiring two digits for each of your time variables.??

  5. #5
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Formatting

    I think that you can also use....

    Code:
    MsgBox Format(intH, "0#") & " : " & Format(intMin, "0#") & " : " & Format(intSecs, "0#")
    If a number is 1 digit then it will prefix a zero.

    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    New Delhi, India
    Posts
    75
    Is there still any way to do this by using just one Format function instead of using three

  7. #7
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334
    Code:
        Dim iArr%(3), sArr$
        
        For iloop% = 0 To 2
            iArr(iloop) = 0
        Next
        
        iArr(2) = 60
    
        For iloop = 0 To 1
            sArr = sArr & Format(iArr(iloop), "0#") & ":"
        Next
        
            sArr = sArr & Format(iArr(2), "0#")
            
        MsgBox sArr
    This code works but it isn't streamlined in anyway, shape or form. I couldn't come up with a quick way of getting it down to 1 format call.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width