Date in Label..

desperado

Well-known member
Joined
Oct 7, 2006
Messages
68
Programming Experience
Beginner
Hi, was wondering if anybody could offer me some help please. On a form I have a textbox and 2 labels. I want the labels to show a specific date, considering what the number is in the textbox.

VB.NET:
  Dim datetod As Date 
  datetod = Date.Now.ToLongDateString 
  Label1.Text = datetod

The above is the first label which shows the current date in label 1. In label2 what I need is a date being calculated from the number in the textbox. For example if the number is between 1 and 3 then I want the date to be exactly 2weeks from label1, if the number is between 4 - 6 then I want the date to be 1 week from label1, and if the number in the textbox is 7+ then I want the date to be 3 days from label1 BUT is there any chance I can exclude weekends? For example if the date is Wednesday in label1, I want the second date to be Monday not Saturday. So far I have the following coding, but when running there are so many errors, could anyone help me out a little please.

VB.NET:
Dim datetod As Date 
        datetod = Date.Now 
        Select Case datetod.DayOfWeek 
            Case 0, 6 
               Messagebox.show "Please order on Monday" 
            Case Else 1,2 
If textbox1.text = "0 - 3" Then 
Label2.Text = datetod.AddDays(14).ToString 
Else If textbox1.text = "4 - 6" Then 
Label2.Text = datetod.AddDays(7).ToString 
Else If textbox1.text = >7 Then 
Label2.Text = datetod.AddDays(3).ToString 
   Case Else 3 
If textbox1.text = "0 - 3" Then 
Label2.Text = datetod.AddDays(14).ToString 
Else If textbox1.text = "4 - 6" Then 
Label2.Text = datetod.AddDays(7).ToString 
Else If textbox1.text = >7 Then 
Label2.Text = datetod.AddDays(5).ToString 
   Case Else 4 
If textbox1.text = "0 - 3" Then 
Label2.Text = datetod.AddDays(14).ToString 
Else If textbox1.text = "4 - 6" Then 
Label2.Text = datetod.AddDays(7).ToString 
Else If textbox1.text = >7 Then 
Label2.Text = datetod.AddDays(4).ToString 
   Case Else 5 
If textbox1.text = "0 - 3" Then 
Label2.Text = datetod.AddDays(14).ToString 
Else If textbox1.text = "4 - 6" Then 
Label2.Text = datetod.AddDays(7).ToString 
Else If textbox1.text = >7 Then 
Label2.Text = datetod.AddDays(3).ToString 
        End Select
 
First things first, what language are you using? It looks like standard VB to me. If you are using VB.NET, here is what I see.

VB.NET:
Dim datetod As Date = Now()
 

Select Case datetod.DayOfWeek[INDENT]' If today is a weekend, then display message to order on Monday[/INDENT]

[INDENT]Case DayOfWeek.Saturday, DayOfWeek.Sunday[INDENT]MsgBox("Please order on Monday")[/INDENT]

Case DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Friday[INDENT]AssignValue(3)[/INDENT]

Case DayOfWeek.Wednesday[INDENT]AssignValue(5)[/INDENT]

Case DayOfWeek.Thursday[INDENT]AssignValue(4)[/INDENT]

[/INDENT]End Select
 

Private Sub AssignValue(ByVal daysToAdd As Integer)[INDENT]If CInt(textbox1.Text) >= 0 And CInt(textbox1.Text) <= 3 Then[INDENT]' Add two weeks to the current date[/INDENT]

[INDENT]Label2.Text = datetod.AddDays(New TimeSpan(14, 0, 0, 0)).ToString[/INDENT]

ElseIf CInt(textbox1.Text) >= 4 And CInt(textbox1.Text) <= 6 Then[INDENT]' Add one week to the current date[/INDENT]

[INDENT]Label2.Text = datetod.AddDays(New TimeSpan(7, 0, 0, 0)).ToString[/INDENT]

Else[INDENT]' Add the passed in number of days[/INDENT]

[INDENT]Label2.Text = datetod.AddDays(New TimeSpan(daysToAdd, 0, 0, 0)).ToString[/INDENT]
End If

[/INDENT]End Sub

You have a lot of syntax errors. You can not do a comparison of "1 - 3" and expect VB to know that you mean between 1 and 3. "1 - 3" is a string and not an integer range. VB would see your test as follows.

If the text in textbox1 is 1 -3 Then do the following. But since we are putting integers in the text box, this would never take place. You need to conver the value of textbox1.Text into an Integer then do your test.

If CInt(textbox1.Text) >= 1 And CInt(textbox1.Text) <= 3 Then

If you are using Visual Studio, do some reading on the Documentation Index to learn more about the objects that you are using as well as the syntax.

>=
<=
<>
==
MsgBox
If, Else, End If
Select, Case, End Select

Good luck and happy programming.

PS. After reading some of your other posts, it looks like you are also confused between standard VB and VB.NET.

Standard VB is a programing language that was used (and probably is still used by some) as the main language to create windows applications. A "step child" of standard VB was used to do some programing for web (VBScript) and therefore we had standard ASP applications.

VB.NET unlike standard VB is using the .NET Framework which is a newer technology developed by Microsoft. VB and VB.NET have some similarities but there are also some major differences. When you mention that your VB.NET applications do not work on VS 2005 and with the errors that you mention, and the syntax errors you give us, we all know that that is standard VB and not VB.NET. You can convert standard VB applications to VB.NET, but there will be some modifications that will need to be made for this converted applications to work in the .NET Framework.

Some of the VB.NET objects are also used to create web applications (under a different project) to create ASP.NET applications.

The .NET Framework is also not dependant on a programing language. You can create an entire application in VB.NET and have it interact with a whole different application written in C#, and yet another in J#. Something that was very limited (if at all possible) before.

To learn more as to what the .NET Framework is visit
http://en.wikipedia.org/wiki/.NET_Framework

And to read the documentation on this .NET Framework, visit microsoft's .NET homepage
http://msdn2.microsoft.com/en-us/netframework/default.aspx
 
Last edited:
Back
Top