Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Date - Time If Then Else Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Date - Time If Then Else Help

    Hi All,

    Let's see if I can explain what I want.

    I am putting to together a Printing Requistion System (Fancy Title) whereby Staff fill in a Grid and Upload the file to the Print Room Operator.

    All is going well and is nearly finished but I am stuck on thge Following.

    I need to Update the Date Due and Due Time fields but in different ways.

    Fields

    Submitted Date, Submitted Time - These are set with an Initial Value of =Now() and disabled.
    Due Date and Due Time are the fields I need to Update depending on whih of the Services below is Selected.

    We Offer 3 Services

    1 - Standard Printing which is 2-3 Days - I would want to make this at Least 2 days after the Submitted Date but it will be enabled as the user can change it.

    2 - 24 Hour Printing - Just Add 24 Hours after Submission Date to the Due Date

    3 - Quick Printing (Same Day) - If before 10:30am the Due Date set to Today and Due Time would be set to 12:30am. If after 10:30am Due Date set to today and Due Time Set to 15:30. If after 12:30 Due Date set to next Day and Due Time Set to 12:30.

    I do not really know where to start with the If statement or whether I should be using Javascript or XBasic. Any pointers in the right direction would be greatfully received. I have searched all morning but not really got anywhere.

    Thanks in anticipation

    Chris

    #2
    Re: Date - Time If Then Else Help

    Hi Chris,

    I'm not sure what you have not gotten a response from the forum folks yet, but I'll try and help you out.

    What I would do is handle this in the OnSaveRecord events section of your database.

    You could put in some code such as:

    t=table.get("yourDbf")
    if isblank("standardprinting")
    t.change_begin()
    t.standardprinting=date()+2
    'Note: you can then add other code here...
    t.change_end()
    end if


    Hope this helps get you started.

    Charlie

    Comment


      #3
      Re: Date - Time If Then Else Help

      Hi Charlie or should that be Brad

      Thanks for the reply - From what I have seen and read I am looking to populate the text fields with JS Get and Set Values within the Grid.

      Chris

      Comment


        #4
        Re: Date - Time If Then Else Help

        Hi Chris,

        I took the liberty of using case instead of if-then, and created a little function called duewhen().
        It needs just 2 pieces of information, a date-time value, and a service code ("a", "b", or "c") as
        I set it.

        Hope this helps.

        Gregg

        Code:
        FUNCTION duewhen AS t (offered AS T,servreq as c)
        	
        duewhen = case(servreq = "a",offered + (48*3600),servreq = "b",offered + (24*3600),servreq = "c" .and. substr(ctime(offered),9,4) < "1030",ctodt(dtoc(date())+" 12:30"), servreq = "c" .and. substr(ctime(offered),9,4) < "1230",ctodt(dtoc(date())+" 15:30"), servreq = "c" .and. substr(ctime(offered),9,4) >= "1230",ctodt(dtoc(date()+1)+" 12:30"))
        	
        END FUNCTION
        Gregg
        https://paiza.io is a great site to test and share sql code

        Comment


          #5
          Re: Date - Time If Then Else Help

          If you want to stay in javascript then give this a try. I find working with dates and times in Javascript to be... icky... at best. I put this code on the onChange event of the field where you select the Print Service. You'd need it on the date and time as well, so putting it into a function would be best. Maybe there's a better way of working with dates in Javascript but I haven't seen it yet. Another route would be to do an Ajax Callback and then you get to use an XBasic function with work decently with dates and times and then just send back a Javascript setValue statement.

          I believe there's a problem with Alpha with running Javascript code off a Radio Control. When displaying an existing record, before the initial display completes I get an error. And, when the submit button is clicked for an existing record or a new record another error. If I change the control to a dropdown... no errors. I'm using MySQL tables and version 2539-3903.

          The date and time formats are really specific here because we have to pull apart the date and time values and then put them back together. So, be aware of dd-mm-yyyy formats... same for time.

          Code:
          var rowNum = {Grid.RowNumber};
          var printService = {grid.Object}.getValue('G','PRINTSERVICE',rowNum);
          var currDate = {grid.Object}.getValue('G','SUBMITTEDDATE',rowNum);
          var currTime = {grid.Object}.getValue('G','SUBMITTEDTIME',rowNum);
          var currDay = currDate.substring(0,2);
          var currMth = currDate.substring(3,5)-1;
          var currYr = currDate.substring(6);
          var dueDate = new Date(currYr, currMth, currDay);
          var dueTime = currTime;
          
          switch(printService)
          {
          case '1':
          	dueDate.setDate(dueDate.getDate()+2);
          	dueTime = currTime;
          	break;
          case '2':
          	dueDate.setDate(dueDate.getDate()+1);
          	dueTime = currTime;
          	break;
          case '3':
          	var end = '10:30 AM';
          	var timeStart = new Date('1/1/2007 ' + currTime);
          	var timeEnd = new Date('1/1/2007 ' + end);
          	difference_in_milliseconds = timeEnd - timeStart;
          	if (difference_in_milliseconds < 0)
          		{
          		var end = '12:30 PM';
          		var timeStart = new Date('1/1/2007 ' + currTime);
          		var timeEnd = new Date('1/1/2007 ' + end);
          		difference_in_milliseconds = timeEnd - timeStart;
          		if (difference_in_milliseconds < 0)
          			{
          			dueDate.setDate(dueDate.getDate()+1);	
          			dueTime = '12:30 pm';
          			}
          		else
          			{
          			dueDate.setDate(dueDate.getDate());							
          			dueTime = '15:30 pm';
          			}
          		}
          	else
          		{
          		dueDate.setDate(dueDate.getDate());							
          		dueTime = '12:30 pm';
          		}
          	break;
          default:
          	alert('Invalid Printing Service selected');			
          }
          
          
          var currDay = dueDate.getDate();
          var currMth = dueDate.getMonth()+1;
          var currYr = dueDate.getFullYear();
          
          var newDueDate = currDay + '/' + currMth + '/' + currYr;
          
          {grid.Object}.setValue('G','DUEDATE',rowNum,newDueDate);
          {grid.Object}.setValue('G','DUETIME',rowNum,dueTime);
          Attached Files
          Last edited by Davidk; 04-17-2012, 07:09 AM.

          Comment


            #6
            Re: Date - Time If Then Else Help

            Nice function Gregg... I never could write such a nice compact function like that.

            Comment


              #7
              Re: Date - Time If Then Else Help

              Would someone mind taking a few minutes to confirm the errors I'm seeing in the project? Included is the full database, 1 dbf table, 1 grid.

              The grid's radio control has onChange JS attached to it.

              Run this in Live or Working Preview.

              When the grid is displayed, empty table, all is fine. Enter some Data and click Submit, an error occurs. Click "No" on the error, get back in Design, then back into Live Preview. As the grid displays (now's there's a record in the table) and error occurs. Click "No" and the grid will display.

              If the Radio Control is changed to a Dropdown... no errors. Thanks for trying this.
              Attached Files
              Last edited by Davidk; 04-17-2012, 07:45 AM.

              Comment


                #8
                Re: Date - Time If Then Else Help

                Gregg and David,

                Thanks so much for the time you have spent with the above.

                I have been watching XBasic Videos alll morning so will hopefully be able to understand and put together what I need from that. But for now will use the code above.

                Once again thanks very much I really do appreciate it.

                OK if I comeback withany questions if I have them?

                Chris

                Comment


                  #9
                  Re: Date - Time If Then Else Help

                  David

                  I have used a Drpdown for the Service Type but when I tried your example with the Radio Button I get the same error.

                  Comment


                    #10
                    Re: Date - Time If Then Else Help

                    I'm always willing to answer questions I can.
                    If you need help adjusting it for your usage, I can certainly do that.
                    The way I set it up leaves room for the changes and corrections that
                    always seem to come up (I assumed you meant 1230 pm, unless you have
                    superman powers to go back in time ).
                    Gregg
                    https://paiza.io is a great site to test and share sql code

                    Comment


                      #11
                      Re: Date - Time If Then Else Help

                      David,

                      var currDay = currDate.substring(0,2);
                      var currMth = currDate.substring(3,5)-1;
                      var currYr = currDate.substring(6);


                      In my quest to understand JS and Dates. Can you let me know what the numbers in brackets and the minus 1 is doing.

                      At a guess the in brackets mean 0,2 - start at 0 and pickup the next 2 characters, 3,5 start at 3rd character and pickup the next 2 (don't know what the -1 is doing and start 6 and pick whatevers left)

                      Also, when the month or day is showing as a single character I have tried this to add the 0 but it isnt working.

                      if (currMth<10)
                      {
                      currMth='0'+currMth;
                      }

                      if (currDay<10)
                      {
                      currDay='0'+currDay;
                      }


                      Chris
                      Last edited by Turnbullca; 04-17-2012, 04:27 PM.

                      Comment

                      Working...
                      X