King Erik I Posted April 21, 2004 Posted April 21, 2004 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 Quote
JABE Posted April 21, 2004 Posted April 21, 2004 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 Quote
King Erik I Posted April 21, 2004 Author Posted April 21, 2004 Hmmm... ok :) shall test it again Quote
King Erik I Posted April 21, 2004 Author Posted April 21, 2004 Name 'txt' is not declared.... my VS 2003 .NET Pro says.... I Declare it under the Do Until loop txt = New Label ...Gmbl... Quote
Administrators PlausiblyDamp Posted April 21, 2004 Administrators Posted April 21, 2004 the line txt = New Label is trying to assign a value to a variable you haven't declared. Somewhere before that line you need to do dim txt as label Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
King Erik I Posted April 21, 2004 Author Posted April 21, 2004 Great!! it's working :-D Thanks alot... Declare = Dim something... doh... stupid me sometimes :o) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.