Passing Values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MikoKitty
    New Member
    • Nov 2006
    • 12

    Passing Values

    Okay, now I'm embarassed. I'm having trouble passing and returning values from a function. The Function call is

    Code:
    Dim w As String
    
    w = TimeCon(strTempDate)
    strTempDate contains a SQL date that needs some work before it will fit into a VB Date format. the work is done by the TimeCon function

    Code:
    Private Function TimeCon(ByVal strTempDate As String)
       
       Dim strDate As String
       Dim StrTime As String
       Dim dteDate As Date
       Dim dteTime As Date
       Dim dteDatTimComp As Date
       Dim intTest As Integer
         
        strDate = Left(strTempDate, InStr(1, strTempDate, "T", vbTextCompare) - 1)
        dteDate = FormatDateTime(strDate, vbShortDate)
        StrTime = Right(strTempDate, InStr(1, strTempDate, "T", vbTextCompare) - 1)
        StrTime = Left(StrTime, InStr(1, strTempDate, "-", vbTextCompare) - 1)
        dteTime = FormatDateTime(StrTime, vbLongTime)
        dteDatTimComp = (dteDate & " " & dteTime)
        w = CStr(dteDatTimComp)
        
         
        intTest = 2
                        
    End Function
    I can get the data into the function, but it's only returning "" into w
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by MikoKitty
    Okay, now I'm embarassed. I'm having trouble passing and returning values from a function. The Function call is ...
    Here's a fix to the passing/returning of your value. I haven't looked into what the function actually does - that's your job :).
    Code:
    Dim w As String
    w = TimeCon(strTempDate)
    ...
    
    Private Function TimeCon(ByVal strTempDate As String) [B][U]As String[/U][/B]
       Dim strDate As String
       Dim StrTime As String
       Dim dteDate As Date
       Dim dteTime As Date
       Dim dteDatTimComp As Date
       Dim intTest As Integer
         
        strDate = Left(strTempDate, InStr(1, strTempDate, "T", vbTextCompare) - 1)
        dteDate = FormatDateTime(strDate, vbShortDate)
        StrTime = Right(strTempDate, InStr(1, strTempDate, "T", vbTextCompare) - 1)
        StrTime = Left(StrTime, InStr(1, strTempDate, "-", vbTextCompare) - 1)
        dteTime = FormatDateTime(StrTime, vbLongTime)
        dteDatTimComp = (dteDate & " " & dteTime)
        [B]' w = CStr(dteDatTimComp)
        ' intTest = 2[/B]
        [U][B]TimeCon = CStr(dteDatTimComp)[/B][/U]
    End Function
    As you can see, I've corrected the Function definition, commented out a couple of incorrect or unnecessary lines (why were you setting intTest, just for debugging?) and properly returned the value by placing it in the "variable" TimeCon.

    Comment

    • MikoKitty
      New Member
      • Nov 2006
      • 12

      #3
      That did it, Thank you SO much!

      Comment

      Working...