Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Mondays in vb.net

Posted on 2009-02-23
14
Medium Priority
?
329 Views
Last Modified: 2013-11-26
Hi, the next code, bring me the dates from 01/01/2009 until Today, but i want to know, how can I put every value in an Array, and then filter this dates by day of week Monday, for a combobox

Thank yoi
Function ObtenerFecha(ByVal diaDeSemana As DayOfWeek, ByVal numeroSemana As Integer, ByVal año As Integer, Optional ByVal addyear As Integer = 0, Optional ByVal addMonth As Integer = 0, Optional ByVal addDay As Integer = 0) As Date
 
        ' SE OBTIENE EL PRIMER DIA DEL AÑO
        Dim strAño As String
        strAño = Year(Now)
        Dim dFecha As New Date(strAño, 1, 1)
        Dim fechaHoy As Date = Today
        Dim i As Integer
        Dim arrFecha(i) As String
        ReDim arrFecha(UBound(arrFecha))
 
        While dFecha <> fechaHoy 'SE SUMA HASTA ENCONTRAR EL DIA ACTUAL
            dFecha = dFecha.AddDays(1)
            
        End While
        Return dFecha
 
    End Function

Open in new window

0
Comment
Question by:edr_1973
  • 8
  • 5
14 Comments
 
LVL 13

Expert Comment

by:Onthrax
ID: 23713960
Dim DateArray as new Arraylist

Then in your loop add:
DateArray.add(dFecha)

I do not understand the second part of your question.
 and then filter this dates by day of week Monday, for a combobox

Please clarify.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 23714032
How about?

    ComboBox1.DataSource = GetDays(DayOfWeek.Monday, 2009)

Using the GetDays() function:
    Private Function GetDays(ByVal RequestedDayOfWeek As DayOfWeek, ByVal Year As Integer) As List(Of Date)
        Dim dts As New List(Of Date)
 
        ' Find the first Monday of the Year
        Dim day As New DateTime(Year, 1, 1)
        While day.DayOfWeek <> RequestedDayOfWeek
            day = day.AddDays(1)
        End While
 
        ' Add all the Mondays up to the Current Date
        While day <= DateTime.Today
            dts.Add(day)
            day = day.AddDays(7)
        End While
 
        Return dts
    End Function

Open in new window

0
 

Author Comment

by:edr_1973
ID: 23714444
Hi, the second comment, bring me all the 8 mondays of this year, until the day of today. But in the combobox, doesn't display anything

Thank you
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23714875
My ComboBox displayed all the dates...I didn't change anything about it, just set the DataSource as shown above.

Do you have any other "data" type properties on the ComboBox set already?
0
 

Author Comment

by:edr_1973
ID: 23715052
This is what i Have in the Combobox: <asp:DropDownList ID="fechaInicio" runat="server" CssClass="Combo" Width="100px" AutoPostBack="True"> </asp:DropDownList>

Thank you
0
 

Author Comment

by:edr_1973
ID: 23715132
Hello, Ignore the last comment, the data allready display in the combobox. Thank you for your help
0
 

Author Closing Comment

by:edr_1973
ID: 31550193
Thank you so much, you saved me from be fired
0
 

Author Comment

by:edr_1973
ID: 23715255
Hi, i have another question, the data in the combo appears as date and time, but I only need the date, how can i arrange this?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23715426
I don't work with WebForms so I don't know if there is a better way...

...but you can instead create an Array/List of Strings already formatted properly and use that as the DataSource.

That might look like:
(again, there might be a better way that I don't know...consider asking in a new question)
    Private Function GetDays(ByVal RequestedDayOfWeek As DayOfWeek, ByVal Year As Integer) As List(Of String)
        Dim dts As New List(Of String)
 
        ' Find the first Monday of the Year
        Dim day As New DateTime(Year, 1, 1)
        While day.DayOfWeek <> RequestedDayOfWeek
            day = day.AddDays(1)
        End While
 
        ' Add all the Mondays up to the Current Date
        While day <= DateTime.Today
            dts.Add(day.ToString("mm/dd/yyyy")) ' <--- change format here
            day = day.AddDays(7)
        End While
 
        Return dts
    End Function

Open in new window

0
 

Author Comment

by:edr_1973
ID: 23715560
the ToString, doesn't work. How can I create and Array for this function?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23715588
Define "doesn't work"....I changed several things about that code...

All of the "(Of Date)" became "(Of String)".

You may need to modify the format...see here for all the codes:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
0
 

Author Comment

by:edr_1973
ID: 23715674
Sorry, I didn't see, all the code, but now it puts me in the ComboBox the dates like this 00/23/2009
 I appreciate your help.

Thank you
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 23716147
Like I said...look at the FORMATTING codes in the link I provided...  =\

Change "mm" to "MM" (or whatever you need).

Sorry, I think "m" is minutes and "M" is month.  Again, LOOK at the link I provided.
0
 

Author Comment

by:edr_1973
ID: 23716276
It works with the M, thank you so much

Best regards
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question