hi again..
Could sure use some help in another code I am currently working on. Would really appreciate the help.
Today i am trying to convert a date i put in a textbox(txtJulian) to a normal date like 02/05/2011(or any other conversion depending what is imputed in the textbox). I cant get it to print to correct date. When I type 011-2011 it print out 1/11/2000 when I want it to print 1/11/2011. Also the error messag doesnt show when I type nothing or the correct format in the txt box. Here is my code

Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        'holds the value of what the user inputs in the textbox
        Dim JulianDate As Long

        Dim 2Centuries As Long
        Dim ConvertToJulianDate As Date

        If txtJulian.Text = "" Or txtJulian.Text = Format("DDD - YYY") Then
            lblOut.Text = "Julian date must have a dash"
        End If

        'Prompts the user to input in textbox and assign the value entered to
      ' then JulianDate 
        JulianDate = Val(txtJulian.Text)

        'converts julian date to a regular date
        If Int(JulianDate / 1000) < 30 Then
            2Centuries = 2000
            2Centuries = 1900
        End If

        ConvertToJulianDate = DateSerial(Century + Int(JulianDate / 1000), _
        1, JulianDate Mod 1000)

        'Display the new date in the normal date format.
        lblOut.Text = ConvertToJulianDate

    End Sub
End Class

Thank you

6 Years
Discussion Span
Last Post by codeorder

already solved conversion...
just cant get the error code to work.
The error code has to print an error message on thelabel if they don't
use the correct format, like (ddd-yyyy) for julian date..
im sure it is something very simple.

Dim julianDate As String
        Dim convertJulianDate() As String
        Dim returnDate As Date

        If txtJulian.Text = "" Or txtJulian.Text = "DDD-YYYY" Then
            lblOut.Text = "Julian date must have a dash"
            Exit Sub
        End If

        julianDate = txtJulian.Text

        convertJulianDate = julianDate.Split("-"c)
        Dim dt As New Date(CInt(convertJulianDate(1)), 1, 1)

        returnDate = dt.AddDays(CInt(convertJulianDate(0)) - 1)

        lblOut.Text = returnDate.ToShortDateString
    End Sub
End Class

Edited by msqueen082: n/a


See if this helps.

Dim arDaysOfWeek() As String = {"mon", "tue", "wed", "thr", "fri", "sat", "sun"} '// days of week in "ddd" format.
        Dim isValidDay As Boolean = False
        Dim arTemp() As String = Nothing
        With TextBox1
            If .Text.Contains("-"c) Then
                arTemp = .Text.Split("-"c)
                For Each myDay As String In arDaysOfWeek '// loop thru days.
                    If myDay = arTemp(0).ToLower Then '// compare values to .Lower, for not case sensitive.
                        isValidDay = True
                        Exit For
                    End If
                MsgBox("value must contain ""-""")
                Exit Sub
            End If
        End With
        If isValidDay = False Then
            MsgBox("wrong day format")
            Exit Sub
        End If
        If Not IsNumeric(arTemp(1)) Then
            MsgBox("wrong year format")
            Exit Sub
        End If
        '// rest of code here.
        MsgBox("valid date format")
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.