Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to understand user input box

Status
Not open for further replies.

steve4king

IS-IT--Management
Feb 6, 2007
154
US
I am a bit unclear on some of this script.. I am a newb at this and really trying to learn. If anyone feels inclined to assist, I could use a few explanations. (line by line??) Thanks in advance.

PS. I probably will not need the entire script below. I actually only need it to ask for one date (not a date range) The default will be blank (not -60days) And I just need be able to plug in that date all over the rest of my script.

Code:
IF SELECT("zmirrinv")
       SELECT 0
       USE zmirrinv
    ENDIF
    SELECT ZMIRRINV
       
       GO bott
       LastDate = ZMIRRINV.DATE
    USE
    release Public_dStartDate, Public_dEndDate
    PUBLIC Public_dStartDate, Public_dEndDate
    
    DO WHILE .t.
    dStartDate = LASTDATE-60
    dEndDate = LASTDATE
    
        DO FORM daterang WITH  dStartDate, dEndDate, "Enter Range of Invoice Dates" TO lOkay
        
        dStartDate = public_dStartDate 	
        dEndDate    = public_dEndDate 
        
        IF !lokay
           RETURN
        ENDIF
        
    DO case
       CASE dStartDate > dEndDate OR EMPTY(DStartDate) OR EMPTY(dEndDate)
            MESSAGEBOX("Invalid or Empty Date Range!",0,"Re-Enter Dates")
            LOOP
       OTHERWISE
            IF MESSAGEBOX("Are you sure you want to locate by date ranges "+ DTOC(dSTartDate)+" To " + DTOC(dEndDate) +"?",4+32+256)=6
               EXIT
            ELSE
               return
            endif   
            
    ENDCASE 
    ENDDO
 
dDate = CTOD(INPUTBOX("Enter a date","Search by date",DTOC(DATE())))

?dDate
 
Baltman's given the answer - I'll help with the explanation:

The INPUTBOX() function asks the user for a string. It takes 3 parameters here:

"Enter a date" is the prompt on the box.

"Search by date" is the caption of the dialog

DTOC(DATE()) is the value that will be displayed in the textbox when it pops up.

Here the DATE() function is getting the system date but we need to work with text so we use DTOC() to do a Date TO Character conversion.

Finally, the InputBox returns text but we want a date so CTOD() does a Character TO Date conversion.

Quite simple really <g>. The only hassle is the need to switch back and forth between Date and String types.

Geoff Franklin
 
Geoff,

Mostly I create a dedicated form for data-input.
The reason is that as far as I know you can't give the inputbox an inputmask.

Is there probably a workaround for giving an inputmask when using the inputbox?

-Bart
 
I would say there is no work-around as such.

I have sometimes done an inputbox and then had a DO WHILE loop, in which I can run the inputbox again, changing the caption or prompt, which tests that the return from the inputbox matches certain criteria.

The inputbox I believe was originally set up for use in SQL calls to server data and so is very basic. I guess VFP released it for general use in response to requests.

It has the advantage that if you need a simple response from the user, it's a whole lot easier than designing a new form.

Referring back to Baltman's response, CTOD is of course dependant on the setting of DATE.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Great explanation Geoff, I really appreciate that. (even the DTOC and CTOD.. I've been using those terms for a long time but didnt even know what they meant.)

now with that line.. Can I just run something like this?? or do I need to throw that DDATE into a cursor somehow?

Code:
DDATE = CTOD(INPUTBOX("ENTER A DATE","SEARCH BY DATE",DTOC(DATE())))
SET DEFA TO (UPPERPATH)
USE CASH_TRA
COPY TO CASH_OLD FOR DATE < CTOD(DDATE)
 
Steve,

If you don't mind my jumping in ...

do I need to throw that DDATE into a cursor somehow?

No. The code that you posted should work fine (assuming DATE is a field within CASH_TRA).

Keep in mind that by copying the table in this way, you are creating a new table, which will remain on the disk until it is deleted or overwritten. If your aim is simply to show the users the old data, it might be better to query it into a (temporary) cursor:

Code:
DDATE = CTOD(INPUTBOX("ENTER A DATE","SEARCH BY DATE",DTOC(DATE())))

SELECT * FROM CASH_TRA ;
  WHERE CASH_OLD FOR DATE < CTOD(DDATE) ;
  INTO CURSOR Cash_Old

Another point: If the user enters an invalid date, DDATE will be empty, so the query will return no records (which might be want you want).

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Actually in this case I did want to create a new table.. I am trying to create a partial purge while maintaining customer balances and credits. This is a very small part of a really primitive script. (due to my lack of knowledge)

Is there any way to force a valid date, rather than allowing them to erase 01/01/01 and type in "Jan/01-whynot"

By the way, the code I posted did not work. "Function argument, value, type or count is invalid
 
oops ok, I just had to remove the CTOD, I realized it was redundant.. But it only copied one line from the file wheras it should have copied about 200..
 
ok, that works now..

Along similar lines.. Why will the second line not work after I have converted the column from character to numeric?
I assume it has something to do with DTOS.. but what does the "S" in dtoS stand for?

Code:
ALTER TABLE INVOICE_NEW ALTER COLUMN INVOICE_NO NUMERIC (6)
INDEX ON INVOICE_NO+DTOS(DATE) TAG INVOICE
 
Steve,

Is there any way to force a valid date

Sure.

Code:
IF EMPTY(DATE)
  DATE = {^2001-01-01} && or whatever default
                       && date you want
ENDIF

INDEX ON INVOICE_NO+DTOS(DATE) TAG INVOICE

No good. Invoice_No is numeric, DOTS() returns a string. You would have to do something this:

Code:
INDEX ON STR(INVOICE_NO,10)+DTOS(DATE) ;
  TAG INVOICE

what does the "S" in dtoS stand for?

Probably "string". But the S is really to distinguish it from DTOC() which also converts to a string, but a different format.

One other point: It might be too late to change this, but DATE is not an ideal name for a field, as it's also a data type and a function. It probably won't do any harm, but in general it's best to avoid these so-called keywords for your field and variable names.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Code:
INDEX ON STR(INVOICE_NO,10)+DTOS(DATE) ;
  TAG INVOICE

what does the ",10" signify?
 
The index expression has to be a fixed length. Mike is converting the invoice number into a ten-character string so that all invoices with numbers from 1 to 9999999999 will be of the same length.

Geoff Franklin
 
Steve,

Geoff has given you the answer. But, come to think of it, I didn't really need to include the ,10, since that's the default value for STR(). It's just that I always include a second param to STR() -- just habit, I suppose.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top