Date-Type textbox problem

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Date-Type textbox problem

Post by ROBROS »

Hi friends,
I played around with a date-type textbox and need help. See the code:

Code: Select all

#include "hmg.ch"

set century on
set date to german
set date format to "DD.MM.YYYY"

FUNCTION Main()

local cDat, cDatum

 DEFINE WINDOW Date_1 ;
 AT 120,120 ;
 WIDTH 400 ;
 HEIGHT 150 ;
 TITLE "Textbox Date" ;
 MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 

 @ 50,50 LABEL datum ;
 PARENT Date_1 ;
 VALUE "Datum" ;

 @ 50,160 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   date 
   inputmask "99.99.9999" 
   VALUE Date()
   
 ACTIVATE WINDOW Date_1
 RETURN NIL
 
 function showdat
 cDat:=dtoc(Date_1.date.value)
 cDatum:=right(cDat,4)+substr(cDat,4,2)+left(cDat,2)
 
 MsgInfo(cDat)
 MsgInfo(cDatum)

return 
It seems inputmask does not work with date-textbox, and the date format setting is ignored too.
Btw: Why do I not get a syntax error because of the semicolon at value of label datum and why do I get a syntax error at the date statement in textbox?

Thank you for your help

Robert

PS: How can I append a screenshot to show you the result of my code?
Attachments
TextboxDate1.png
TextboxDate1.png (106.38 KiB) Viewed 6817 times
TextboxDate.png
TextboxDate.png (81.6 KiB) Viewed 6823 times
Last edited by ROBROS on Thu May 10, 2018 1:45 pm, edited 2 times in total.
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: Date-Type textbox problem

Post by ROBROS »

As you can see from the attached screen shot, the typed in date is not validated, but the MsgInfo shows nothing (blank).

The sequence of the attached files is wrong. Sorry for that.
Last edited by ROBROS on Thu May 10, 2018 1:47 pm, edited 1 time in total.
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Date-Type textbox problem

Post by mustafa »

Hello Friend ROBROS :
write with this order and it works

Code: Select all

#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum

set century on
set date to german
set date format to "DD.MM.YYYY"

 DEFINE WINDOW Date_1 ;
 AT 120,120 ;
 WIDTH 400 ;
 HEIGHT 150 ;
 TITLE "Textbox Date" ;
 MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 

 @ 50,50 LABEL datum ;
 PARENT Date_1 ;
 VALUE "Datum" ;

 @ 50,160 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   VALUE dtoc( Date() ) ;
   inputmask "99.99.9999" 


 ACTIVATE WINDOW Date_1
 RETURN NIL
 
 function showdat
  cDat:= (Date_1.date.value)    //dtoc(Date_1.date.value)        
 cDatum:=right(cDat,4)+substr(cDat,4,2)+left(cDat,2)
 
 MsgInfo(cDat)
 MsgInfo(cDatum)

return 

Regards
Mustafa
Attachments
date.jpg
date.jpg (5.94 KiB) Viewed 6816 times
edk
Posts: 909
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Date-Type textbox problem

Post by edk »

ROBROS wrote: Thu May 10, 2018 11:57 am Hi friends,
I played around with a date-type textbox and need help. See the code:

Code: Select all

#include "hmg.ch"

set century on
set date to german
set date format to "DD.MM.YYYY"

FUNCTION Main()

local cDat, cDatum

 DEFINE WINDOW Date_1 ;
 AT 120,120 ;
 WIDTH 400 ;
 HEIGHT 150 ;
 TITLE "Textbox Date" ;
 MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 

 @ 50,50 LABEL datum ;
 PARENT Date_1 ;
 VALUE "Datum" ;

 @ 50,160 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   date 
   inputmask "99.99.9999" 
   VALUE Date()
   
 ACTIVATE WINDOW Date_1
 RETURN NIL
 
 function showdat
 cDat:=dtoc(Date_1.date.value)
 cDatum:=right(cDat,4)+substr(cDat,4,2)+left(cDat,2)
 
 MsgInfo(cDat)
 MsgInfo(cDatum)

return 
It seems inputmask does not work with date-textbox, and the date format setting is ignored too.
Btw: Why do I not get a syntax error because of the semicolon at value of label datum and why do I get a syntax error at the date statement in textbox?

Thank you for your help

Robert

PS: How can I append a screenshot to show you the result of my code?
Wrong syntax of TextBox. When you define a TextBox with the DATE option, you can not use INPUTMASK.
Also, you must set century and date format locate in to FUNCTION Main(), not before.

Code: Select all

#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum

set century on
set date to german
set date format to "DD.MM.YYYY"

 DEFINE WINDOW Date_1 ;
 AT 120,120 ;
 WIDTH 400 ;
 HEIGHT 150 ;
 TITLE "Textbox Date" ;
 MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 

 @ 50,50 LABEL datum ;
 PARENT Date_1 ;
 VALUE "Datum" ;

 @ 50,160 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   VALUE Date();
   DATE
   
 ACTIVATE WINDOW Date_1
 RETURN NIL
 
 function showdat
 cDat:=dtoc(Date_1.date.value)
 cDatum:=right(cDat,4)+substr(cDat,4,2)+left(cDat,2)
 
 MsgInfo(cDat)
 MsgInfo(cDatum)

return 
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: Date-Type textbox problem

Post by ROBROS »

Hi friend Mustafa,

I compiled and of course it works, thank you, but I have not yet found the difference to my code.;)

Anyway: Thank you
Robert
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Date-Type textbox problem

Post by mustafa »

your code with arrangement

Code: Select all

#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum

set century on
set date to german
set date format to "DD.MM.YYYY"

 DEFINE WINDOW Date_1 ;
 AT 120,120 ;
 WIDTH 400 ;
 HEIGHT 150 ;
 TITLE "Textbox Date" ;
 MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 

 @ 50,50 LABEL datum ;
 PARENT Date_1 ;
 VALUE "Datum" ;

 @ 50,160 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   date 
   inputmask "99.99.9999" 
   VALUE Date()

     ACTIVATE WINDOW Date_1
 RETURN NIL
 
 function showdat
 cDat:=dtoc(Date_1.date.value)
 cDatum:=right(cDat,4)+substr(cDat,4,2)+left(cDat,2)
 
 MsgInfo(cDat)
 MsgInfo(cDatum)

return 

Regards
Mustafa
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Date-Type textbox problem

Post by mustafa »

*------------------ Your code -------------------*
#include "hmg.ch"

set century on
set date to german
set date format to "DD.MM.YYYY"

FUNCTION Main()

local cDat, cDatum

DEFINE WINDOW Date_1 ;
.....
*----------------- My code ------------------------*

#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum

set century on
set date to german
set date format to "DD.MM.YYYY"

DEFINE WINDOW Date_1 ;
....
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: Date-Type textbox problem

Post by ROBROS »

One of my replies got lost on the way to the board,

I always looked for the error inside the main function.

@ edk: Thank you.

@ Mustafa: edk's reply showed me the difference.

Thx again.

Robert
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: Date-Type textbox problem

Post by ROBROS »

This post should be removed, the following post is identical, the only difference is, that bbcode is ok. :lol:

Hi friends,
still playing around with dates, once again I found a strange behaviour (at least in my opinion) of the compiler: I use IDE "RUN" to compile. It has to do with the semicolon, telling the compiler, that the following line is not a new line, but the previous one is continued.

How do I know, if a new line in source code is requested? Please see attached source code.

[code)#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum
cName:=GetComputerName()

set language to german
set century on
set date to german
set date format to "DD.MM.YYYY"
set navigation extended

//MsgInfo('Computer-Name: '+ cName)
*************

DEFINE WINDOW Date_1 ;
AT 120,120 ;
WIDTH 600 ;
HEIGHT 400 ;
FONT 'ARIAL' Size 14 ;
TITLE "Wochentag eines Datums" ;
MAIN
END WINDOW

On Key F10 of date_1 action showdat()


//Why no semicolons necessary in the followin labels?
****************************************************************
DEFINE LABEL datum_0
PARENT Date_1
ROW 40
COL 10
width 300
height 50
FONTNAME 'ARIAL'
FONTSIZE 12
autosize .T.
VALUE "Find out the CDOW() of a date"
END LABEL

DEFINE LABEL datum
PARENT Date_1
ROW 150
COL 10
width 300
height 50
FONTNAME 'ARIAL'
FONTSIZE 12
autosize .T.
VALUE "Enter date,go on with RETURN or F-10"
END LABEL

@ 200,10 TEXTBOX date ;
PARENT Date_1 ;
WIDTH 120 ;
HEIGHT 30 ;
Font 'ARIAL' SIZE 14 ;
value nil ;
date ;
On Enter showdat()

DEFINE BUTTON showdat
PARENT date_1
ROW 200
COL 140
CAPTION 'F-10'
ONCLICK showdat()
Fontname 'ARIAL'
FontSize 14
WIDTH 60
HEIGHT 30
END BUTTON


ACTIVATE WINDOW Date_1
RETURN NIL
*****************************************************
//CDOW() is shown in German. :-)

function showdat
cDat:=dtos(Date_1.date.value)
cDatum:=dtoc(Date_1.date.value)

if empty(cDat)
MsgInfo('No valid date')
else
// MsgInfo(cDat)
// MsgInfo(cDatum)
MsgInfo(cDatum+' = '+cdow(Date_1.date.value))
endif
Date_1.release
return [/code]

Maybe someone can explain that to me (retiring in 2 weeks) but working on with hmg to keep my brains alive.

Robert
Last edited by ROBROS on Sun Sep 16, 2018 5:09 pm, edited 1 time in total.
ROBROS
Posts: 256
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Location: D 83071 Stephanskirchen

Re: Date-Type textbox problem

Post by ROBROS »

Hi friends,
still playing around with dates, once again I found a strange behaviour (at least in my opinion) of the compiler: I use IDE "RUN" to compile. It has to do with the semicolon, telling the compiler, that the following line is not a new line, but the previous one is continued.

How do I know, if a new line in source code is requested? Please see attached source code.

Code: Select all

#include "hmg.ch"

FUNCTION Main()

local cDat, cDatum
cName:=GetComputerName()

set language to german
set century on
set date to german
set date format to "DD.MM.YYYY" 
set navigation extended

//MsgInfo('Computer-Name: '+ cName)
*************

 DEFINE WINDOW Date_1 ;
  AT 120,120 ;
  WIDTH 600 ;
  HEIGHT 400 ;
  FONT 'ARIAL' Size 14 ;
  TITLE "Wochentag eines Datums" ;
  MAIN 
 END WINDOW
 
 On Key F10 of date_1 action showdat() 


//Why no semicolons necessary in the following labels? 
****************************************************************
 DEFINE LABEL datum_0
  PARENT Date_1 
  ROW 40 
  COL 10 
  width 300
  height 50
  FONTNAME 'ARIAL' 
  FONTSIZE 12
  autosize .T.
 VALUE "Find out the CDOW() of a date" 
 END LABEL  
 
 DEFINE LABEL datum 
  PARENT Date_1 
  ROW 150
  COL 10 
  width 300
  height 50
  FONTNAME 'ARIAL' 
  FONTSIZE 12
  autosize .T.
  VALUE "Enter date,go on with RETURN or F-10" 
 END LABEL 
 
  @ 200,10 TEXTBOX date ;
   PARENT Date_1 ;
   WIDTH 120 ;
   HEIGHT 30 ;
   Font 'ARIAL' SIZE 14 ;
   value nil ;  
   date  ;
   On Enter showdat() 
   
       DEFINE BUTTON showdat
            PARENT date_1
            ROW 200 
            COL 140
            CAPTION 'F-10'  
            ONCLICK showdat()
			Fontname 'ARIAL'
			FontSize 14
            WIDTH 60 
            HEIGHT 30
      END BUTTON
  
    
 ACTIVATE WINDOW Date_1
 RETURN NIL
 *****************************************************
 //CDOW() is shown in German. :-)
 
 function showdat
 cDat:=dtos(Date_1.date.value)
 cDatum:=dtoc(Date_1.date.value)
 
 if empty(cDat)
	MsgInfo('No valid date')
 else
//	MsgInfo(cDat)
//	MsgInfo(cDatum) 
	MsgInfo(cDatum+' = '+cdow(Date_1.date.value))
 endif
 Date_1.release
return 
Maybe someone can explain that to me (retiring in 2 weeks) but working on with hmg to keep my brains alive.

Robert

How can I remove the previous post, bbcode was wrong.
Post Reply