I have a locked edit box with a date (format: yyyy-mm-dd). Clickin the editbox opens a MonthView. Clicking a date closes the MonthView and the formated date appears in the edit box. My problem is how to get the editbox date to be marked when the MonthView is opend. I suppose i have to send MCM_SETCURSEL message but I don't know how to convert the edit string date to systime date. Does sombody know?

I attach a test example.

Best regards
Posted on 2004-01-15 16:04:32 by minor28
Why don't you use the DateTimePicker control, it is essentially the same but you already have an edit box and you can send it formatting strings (DTM_SETFORMAT). The conversion will be automatic.
Posted on 2004-01-15 16:12:21 by donkey
Hi donkey

I didn't know about the DateTimePicker. It works alwright, but I want the editbox locked. No writing. The date is fetched from an database in string format and shown in the editbox. To do that in the datetimepicker window you must send the message in systime format, as far as i could read from sdk. So I have to convert anyway.

Best regards
Posted on 2004-01-15 16:36:32 by minor28
The conversion wasn't difficult.
invoke GetDlgItemText,hDlg,IDC_EDT1,addr buffer,sizeof buffer

mov byte ptr [buffer+4],0
invoke atodw,addr buffer
mov systime.wYear,ax
mov byte ptr [buffer+7],0
invoke atodw,addr [buffer+5]
mov systime.wMonth,ax
invoke atodw,addr [buffer+8]
mov systime.wDay,ax
mov systime.wDayOfWeek,0
mov systime.wHour,0
mov systime.wMinute,0
mov systime.wMinute,0
mov systime.wMilliseconds,0
invoke SendMessage,hMvi,DTM_SETSYSTEMTIME,GDT_VALID,addr systime
invoke ShowWindow,hMvi,SW_SHOW
Posted on 2004-01-16 01:13:04 by minor28
Come to think of it, the above is valid only for date format "yyyy-mm-dd". If somebody know a general way to convert a string date to systemtime i would appreciate the information.
Posted on 2004-01-16 05:31:09 by minor28
hi minor



/CALL to GetDlgItemInt from MonthVie.00401089
|hWnd = 00110108 ('2004-05-18',class='Edit',parent=007300B8)
|ControlID = 3EA (1002.)
|pSuccess = NULL
\IsSigned = FALSE



the hWnd you pass is wrong you have to pass the hwnd of the dialog box not control
this returns ERROR_CONTROL_ID_NOT_FOUND (0000058D)
btw what format will the date be like in the edit box originally
and what will be the seperators etc
21st december 1992 can be written in many ways like 21/12/1992 12/21/1992
21-12-1992 ,21-12-92 21/12/92 or as you have written 1992/12/21
are you looking for a conversion for a specific format or any format
Posted on 2004-01-16 10:03:56 by bluffer
A date from MonthView to editbox converts from sysemtime to string formated acording to local user. Local user format is "yyyy-mm-dd". This i done with
.if [edi].code==MCN_SELECT

invoke SendMessage,hMvi,MCM_GETCURSEL,0,addr systime
invoke GetDateFormat,LOCALE_USER_DEFAULT,DATE_SHORTDATE,addr systime,\
0,addr pDateStr,sizeof pDateStr
invoke SendMessage,hEdt,WM_SETTEXT,0,addr pDateStr
invoke ShowWindow,hMvi,SW_HIDE
.endif
.
The other way to send a string format date to MonthView is done by converting the string to systemtime with
.else

invoke GetDlgItemText,hDlg,IDC_EDT1,addr buffer,sizeof buffer
mov byte ptr [buffer+4],0
invoke atodw,addr buffer
mov systime.wYear,ax
mov byte ptr [buffer+7],0
invoke atodw,addr [buffer+5]
mov systime.wMonth,ax
invoke atodw,addr [buffer+8]
mov systime.wDay,ax
mov systime.wDayOfWeek,0
mov systime.wHour,0
mov systime.wMinute,0
mov systime.wMinute,0
mov systime.wMilliseconds,0
invoke SendMessage,hMvi,DTM_SETSYSTEMTIME,GDT_VALID,addr systime
invoke ShowWindow,hMvi,SW_SHOW
.endif

This conversion only works with this specific format. What I want is a general conversion like the first code snippet but the other way. I have found no functions and my question is if somebody else know anything about it.

REgards
Posted on 2004-01-16 14:28:07 by minor28
Hi minor28,

I can't see what the big problem here is. Just convert the string to a set of numbers in an array then whatever format they're in doesn't matter, you just change the indices :


.data

array DD 3 DUP (?)
String DB "1234-56-78",0
dlm DB "-",0

.code
invoke ScanNum,OFFSET String,OFFSET array,OFFSET dlm

mov eax,0 ; index for year
mov ecx,1 ; index for month
mov edx,2 ; index for day

PrintDec array[eax*4]
PrintDec array[ecx*4]
PrintDec array[edx*4]

; if the order changes just change the index in eax,ecx,edx

ScanNum PROC pString,pArray,pDelimt

invoke lstrlen,pString
mov ecx,eax
add ecx,1
mov eax,[pDelimt]
mov al,[eax]
mov esi,[pArray]

mov ebx,ecx
add ebx,[pString]
jmp L2
L1:
mov edi,[pString]
repne scasb
mov BYTE PTR [edi-1],0
push ecx
push eax
push edi
invoke atodw,[pString]
mov [esi],eax
add esi,4
pop edi
pop eax
pop ecx
mov [pString],edi
L2:
cmp [pString],ebx
jl L1


RET
ScanNum ENDP
Posted on 2004-01-16 15:07:40 by donkey
The problem is not coding the conversion. The problem is that I don't know how the date is formated. It could be short like "yyyy-mm-dd" or "dd-mm-yy" or "yyyy/mm/dd" or it could be long like "den 16 januari 2004" or something else. How it is formated is dependent on the user's settings. No problem to fetch the string from database and show the string in the editbox whatsoever the formatation. But how do I send the date to MonthView.

I can't explain. I think we stop the discussion here. I will take another way by storing the date in database in systemtime format. The date is always created from the MonthView control and therefor could be stored in database as systemtime. Then the app will be independent of user's date settings.

Thanks for your help
Posted on 2004-01-16 16:28:41 by minor28
Hi minor28,

I thought that the user could not imput the date except with the month view ? If the user is inputting with the month view the output is always formatted, how it is displayed is fine for a user setting but you keep the date in SYSTEMTIME format no matter what. After all it is only to display a date, it makes no difference how the date is stored in memory. If you need any more than that, though I can't see why, you will have to write a rather complicated parser that will work on the basis of a formatting string.
Posted on 2004-01-16 16:46:17 by donkey
It is a database to which more than one user have access. If the first user store a date in the database the second user have access to the date only through the database. You can only get hold of the date in memory as long as the user runs the app. But next day when he turns on his computer he have to fetch the date from database. I can't explain it in a better way because of my poor english.
Posted on 2004-01-16 17:05:32 by minor28
That's not the point. Do you think that Access allows you to store a date how you like. No, it stores it in a predefined format then the user sets the view and the date is formatted from the static structure for that particular user. So say you stored the date only in a system time structure, every user could access the date and you would only have one type of structure to parse and you can display it how you wish.
Posted on 2004-01-16 18:44:53 by donkey
Yes donkey, you were right. I have made some testings and my first conversion works unindependent of user settings. I made it a greater problem than it was, thanks.
Posted on 2004-01-17 09:03:31 by minor28