This is a migrated thread and some comments may be shown as answers.

Trouble getting weekday name in VB code

3 Answers 169 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jurij
Top achievements
Rank 2
Jurij asked on 07 Apr 2015, 12:39 PM

I want to use VB code for comparing TextContent, but I can't. If I run the following code I get an error stating that "Weekday is not declared", but according to VB tutorials I should be able to use it without a problem:

Dim todayDate As Date = Date.Now()
Dim dateToday As String = todayDate.ToString("yyyy/MM/dd")
Dim timeToday As String = todayDate.ToString("yyyy/MM/dd hh:mm")
Dim dayName As Integer
Dim dayNameShort As String

dayName = Weekday(todayDate)

Select Case dayName
     Case Is = 1
         dayNameShort = "Sun"
     Case Is = 2
         dayNameShort = "Mon"
     Case Is = 3
         dayNameShort = "Tue"
     Case Is = 4
         dayNameShort = "Wed"
     Case Is = 5
         dayNameShort = "Thu"
     Case Is = 6
         dayNameShort = "Fri"
     Case Is = 7
         dayNameShort = "Sat"
End Select

Pages.CashLedger.xDdTag.AssertContent().TextContent(ArtOfTest.Common.StringCompareType.StartsWith, dateToday & " 12:00 AM " & dayNameShort & " - " & timeToday)

Also when seeing the output of the code if I leave our Weekday, I see that date is not correctly formatted. Instead of defined "/" separator a "." is used, like:

OK - 04/07/2015

NOK - 04.07.2015 - this is what formatting in VB does in Test Studio!

Please help or point me to doc where such cases are already explained and can be done without a code.

Thanks, Jurij

3 Answers, 1 is accepted

Sort by
0
Nikolai
Telerik team
answered on 10 Apr 2015, 05:11 AM
Hi Jurij,

Test Studio is using VB.NET not VB (2003/2008) or VBScript, so there is not class/object called Weekday.
If you want to get the current day of the week this is the proper way to do it:

Dim todayDate As Date = Date.Now()
Dim day As String = todayDate.DayOfWeek.ToString()

By default the Date/Time returned by the Date struct in VB.NET is formatted as the current thread culture taken from the current user's Global Date/Time format confinguration. This is why the date formating depends and changes. This behavior can be changed by adding culture object when you parse or work with dates.

Test Studio uses VB.NET and all the resources for it can be found here, for the DateTime struct here, please refer to the MSDN for specific VB.NET tasks.

Hope this helps.

Regards,
Nikolai
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Jurij
Top achievements
Rank 2
answered on 10 Apr 2015, 07:06 AM

Hi Hikolai,

Perfect, that explains a lot and now I'm able to do what I wanted! THANKS!

BR, Jurij

0
Boyan Boev
Telerik team
answered on 10 Apr 2015, 11:20 AM
Hello Jurii,

We are very happy to hear that.

If you need further assistance please let us know.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Jurij
Top achievements
Rank 2
Answers by
Nikolai
Telerik team
Jurij
Top achievements
Rank 2
Boyan Boev
Telerik team
Share this question
or