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
        Else
            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

Recommended Answers

All 2 Replies

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"
            txtJulian.Focus()
            txtJulian.SelectAll()
            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

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
                Next
            Else
                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")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.