How do I change the position of textboxes Based on selected Value from a DateTimePicker (Putting Textboxes in Order)

Gary Simpson 471 Reputation points
2022-02-19T13:07:56.743+00:00

Hi Good People,

I have 7 Textboxes and a DateTimePicker, After Selecting a Date from the (DTP) , I want to put the textboxes in order, of a selected day/Date
At this moment the textboxes on my form run from Friday to Thursday. (Friday being the first day of the week)

So if I select a different day/Date as start of week. I then want to change the textboxes position to the day/date selected to be at the top of the textboxes

Example... I have now is Fri 18/02/2022 selected from the DTPDate.

TxtFri
TxtSat
TxtSun
TxtMon
TxtTue
TxtWed
TxtThu

But If I select, Mon 21/02/2022 from the DTPDate, I then want to change the order of the textboxes to...

TxtMon
TxtTue
TxtWed
TxtThu
TxtFri
TxtSat
TxtSun

Is there a way I can achieve the above.

I have tried writing code for this to no avail, The code I have at the moment is below...

 Private Sub GetPostion()  
        Dim DayFri As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DaySat As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DaySun As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DayMon As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DayTue As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DayWed As Date = DtpDate.Value.Day.ToString("ddd")  
        Dim DayThu As Date = DtpDate.Value.Day.ToString("ddd")  
  
        If DtpDate.Value.Day = FirstDayOfWeek.Friday Then  
            Dim X101 As Point = X101  
            Dim Y29 As Point = Y29  
            TxtFri.Location = (X101, Y29)  
  
  
        End If  
  
    End Sub  

176048-question-photo.png

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 116.6K Reputation points
    2022-02-19T15:09:08.057+00:00

    Try one of solutions:

    Const Y = 20 ' Vertical position of first textbox '
    Const DY = 40 ' Vertical step '
    
    Dim d = CInt(DateTimePicker1.Value.DayOfWeek)
    
    TxtMon.Top = Y + ((8 + 0 - d) Mod 7) * DY
    TxtTue.Top = Y + ((8 + 1 - d) Mod 7) * DY
    TxtWed.Top = Y + ((8 + 2 - d) Mod 7) * DY
    TxtThu.Top = Y + ((8 + 3 - d) Mod 7) * DY
    TxtFri.Top = Y + ((8 + 4 - d) Mod 7) * DY
    TxtSat.Top = Y + ((8 + 5 - d) Mod 7) * DY
    TxtSun.Top = Y + ((8 + 6 - d) Mod 7) * DY
    

    Adjust Y and DY.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.