Thread: VB Script

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2008
    Posts
    244
    Rep Power
    11

    VB Script


    Doing this...I can specify the Now() and it works...BUT i need to feed it a value from a text box. I am trying to set the variable GetDate to the value of the textbox...but errors on the setting of WeekDayName variable.
    So basically everything works I just need to change the Now() with the string value from my textbox...
    ex: 04/25/2013 4:22:26 PM

    ERROR if I try this:
    WeekDayName=(WeekDay(GetDate))

    CODE:
    Code:
    Sub txtAppointment_Change 
    
    Dim WeekDayName, WeekDayResult 
    Dim GetDate = txtAppointment.text    
    
    WeekDayName=(WeekDay(Now())) 
    'WeekDayName=(WeekDay(GetDate)) 
    
    Dim DayResult 
      
    If WeekDayName = 1 Then    
         DayResult = "Sunday" 
    ElseIf WeekDayName = 2 Then    
         DayResult = "Monday" 
    ElseIf WeekDayName = 3 Then    
         DayResult = "Tuesday" 
    ElseIf WeekDayName = 4 Then    
         DayResult = "Wednesday" 
    ElseIf WeekDayName = 5 Then    
         DayResult = "Thursday" 
    ElseIf WeekDayName = 6 Then    
         DayResult = "Friday" 
    ElseIf WeekDayName = 7 Then    
         DayResult = "Saturday" 
    End If 
    
    txtDayOfWeek.text = DayResult 
    
    End Sub
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Not sure about VBScript, but this works fine in VB6:
    Code:
    Private Sub Command1_Click()
        Dim DaysOfWeek
        DaysOfWeek = Array("Empty", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
        txtDayOfWeek.Text = DaysOfWeek(Weekday(txtAppointment.Text))
    End Sub
    J.A. Coutts
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2008
    Posts
    244
    Rep Power
    11
    This works out...

    Code:
    If Len(txtAppointment.text) = 0 Then        
    'msgbox "There wasn't any appointment date set"    
    Else        
    txtDayOfWeek.text = WeekDayName(WeekDay(txtAppointment.text))    
    End If
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Posts
    289
    Rep Power
    45
    Actually, anytime you manipulate date fields, you should verify that it is a valid date:
    Code:
    Private Sub Command1_Click()
        Dim DaysOfWeek
        DaysOfWeek = Array("Empty", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
        If IsDate(txtAppointment.Text) Then
            txtDayOfWeek.Text = DaysOfWeek(Weekday(txtAppointment.Text))
        Else
            MsgBox "Not a valid date!", vbExclamation
        End If
    End Sub

    Comments on this post

    • jaykappy agrees

IMN logo majestic logo threadwatch logo seochat tools logo