Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello, having a small problem....

 

Want to create my label dynamicly. Found another post on this forum where i have found the info with the With function, so that worked.... only now i've got another small problem. If I run my loop, the previous created label is gone!

 

That is not what I want. How do I create something so that every created label stays?

 

Under here my current code....

 

 Dim iDaysInMonth As Integer 'The number of days in a month
 Dim iCurrentDay As Integer = 1 'The current day... necessary for the loop
 Dim iDowStart As Integer 'Declare daysofweek from the 1st day of the month
 Dim iTxtBoxWidth As Integer = 24 'The width of the text box with the day number in it.
 Dim iTxtBoxPos As Integer
 iDaysInMonth = Now.DaysInMonth(Now.Year, Now.Month)
 iDowStart = DateTime.Now.Parse(Now.Year & "/" & Now.Month & "/01").DayOfWeek + 1
 ' MessageBox.Show(iDowStart)
 Do Until iCurrentDay = iDaysInMonth
   txt = New Label
   iTxtBoxPos = (iCurrentDay * iTxtBoxWidth) + (iCurrentDay)
   'MessageBox.Show(iCurrentDay)
     With txt 'Not correct??
       .Location = New Point(iTxtBoxPos, 15)
       .Size = New Size(24, 24)
       .Text = iCurrentDay
       .Visible = True
       .BackColor = Color.Red
     End With
   Me.Controls.Add(txt)
   iCurrentDay += 1
 Loop

Posted

I tested your code in Page_Load and all dates were shown EXCEPT the last one. Your loop condition should probably be:

 

Do Until iCurrentDay > iDaysInMonth

 

rather than

 

Do Until iCurrentDay = iDaysInMonth

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...