Page 1 of 1

Setting the date to one day previous

Posted: Fri Apr 10, 2015 5:20 pm
by mghali
I have a date field. I am trying to set the date to the previous date on any give date.
the C# code for this would be eqivalent to:

DateTime startDate = Datetime.Now;

Console.WriteLine(startDate.AddDays(-1).ToShortDateString);
Console.ReadLine();

so if the date today is 5/15/2014 then the date set should be 5/14/2014

This date has to be set to the element startDate with the xpath

(.//tabpage[@title~'^VERC-23451\ -\ Williams,\ Wa' and @controltypename='TabPage']/?/?/container[@controltypename='SplitContainer']/container[2]/?/?/tabpage[@title~'^Procedure:\ MCT\ 4/10/2015\ ' and @controltypename='TabPage']/container/container[@controltypename='Panel']/container[@controltypename='Panel']/container[@controltext='Procedure Information']/datetime[@controltypename='DateTimePicker']/?)

The Date TimePicker has to read the value of yesterday's day.

The errors that I get are

(1) The type or namespace name 'Datetime' does not exist in the namespace 'System' (are you missing an assembly reference?) (CS0234) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:44,45

(2) Ranorex.Unknown' does not contain a definition for 'set' and no extension method 'set' accepting a first argument of type 'Ranorex.Unknown' could be found (are you missing a using directive or an assembly reference?) (CS1061) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:45,47

Please Help

Thank you!!!

Re: Setting the date to one day previous

Posted: Fri Apr 10, 2015 7:15 pm
by krstcs
I think you have the code correct. What isn't working?


If you are asking how to do it without code in Ranorex Studio, then that isn't possible directly. You will need to create a usercode method that performs the calculations and validation.


Also, in the future please include the following information as it will help us better understand your situation:
1. Ranorex version (5.3.1 is current)
2. Windows version and bit-ness (x86 vs x64)
3. Any error messages (if applicable)

Re: Setting the date to one day previous

Posted: Fri Apr 10, 2015 7:32 pm
by mghali
How to display as a set value for a repository item called startDate?

Where should i direct the WriteLine to ?

Re: Setting the date to one day previous

Posted: Fri Apr 10, 2015 7:36 pm
by krstcs
I don't understand your issue. Can you please explain in more detail what you are trying to accomplish?


If you just want to print out the date to the report you can use a Report action in the module or in user code. You should probably not be using Console.Writeline in Ranorex tests.

Re: Setting the date to one day previous

Posted: Fri Apr 10, 2015 7:48 pm
by mghali
I update my post please review it and let me know if you need anymore information.

Re: Setting the date to one day previous

Posted: Fri Apr 10, 2015 7:54 pm
by krstcs
Please do not update your posts after someone has replied to them without noting the edits. This can create confusion and misunderstandings as people reply to one thing only to have it changed to something else. (For example, you could have asked "Is the sky blue?" I would have answered "Yes." And then you changed the question to "Is Ranorex free?", which is not the question I answered.)

If others have replied to the post already you should create a new reply instead of updating in order to maintain the integrity and flow of the conversation.



As for your current errors, without also seeing the code you have written it will be impossible to tell you what is wrong. Please post the code you are using, or create a sample project that has the same issue and post it so we can look at it.

Re: Setting the date to one day previous

Posted: Mon Apr 13, 2015 8:36 am
by odklizec
mghali wrote:I have a date field. I am trying to set the date to the previous date on any give date.
the C# code for this would be eqivalent to:

DateTime startDate = Datetime.Now;

Console.WriteLine(startDate.AddDays(-1).ToShortDateString);
Console.ReadLine();

The errors that I get are

(1) The type or namespace name 'Datetime' does not exist in the namespace 'System' (are you missing an assembly reference?) (CS0234) - C:\Users\BeaconUser\Documents\Ranorex\RanorexStudio Projects\Patients\Patients\NewPatientFile.UserCode.cs:44,45
I think you should fix Datetime.Now; to DateTime.Now;
DateTime startDate = DateTime.Now;

As for the other error, could you post the failing code (from NewPatientFile.UserCode.cs:45,47)?