If so, you can change the format by right-clicking on the field and selecting "Format Field". Click on the "Time" tab and select the appropriate option from the list displayed.
If the field is a number field the following will work:
umberVar T := 1845; //change to your field
NumberVar H := tonumber(left(totext(t),2));
NumberVar M := tonumber(totext(t) [3 to 4]);
time(h,m,0)
//field will be returned as time. After placing on report
//right click and choose format field and select the format
//you want.
If the field is a string, then the following will work:
StringVar ST := '1845'; //change to your field
NumberVar H := tonumber(left(ST,2));
NumberVar M := tonumber(ST [3 to 4]);
time(h,m,0)
//field will be returned as time. After placing on report
//right click and choose format field and select the format
//you want.
I am sure there is probably an easier way, but that works.
Thankyou! My mistake was only testing 4 digit numbers. I believe that the following corrected formula will work for you.
NumberVar T := {HMN_UNSHDDAY.S_START};
numbervar l := len(totext(tonumber(t)));
numbervar c := select(l)
case 0 : 0
case 1 : 0
case 2 : 0
case 3 : 1
case 4 : 2;
NumberVar H := tonumber(left(totext(t),c));
NumberVar M := tonumber(right(totext(t),2));
time(h,m,0)
Basically, we don't select the first 2 characters, it depends upon the length of the converted string. Will you test the modified formula and let me know if it works for you?
Sorry, but I am getting an error message saying "the remaining text does not appear to be part of the formula" inbetween the bottom two lines. Is this in crystal syntax?
case 4 : 2;
NumberVar H := tonumber(left(totext(t),c));
I am sorry to be so much trouble. Here is what I have:
NumberVar T := {HMN_UNSHDDAY.S_START};
numbervar l := len(totext(tonumber(t)));
numbervar c := select(l)
case 0 : 0
case 1 : 0
case 2 : 0
case 3 : 1
case 4 : 2;
NumberVar H := tonumber(left(totext(t),c));
NumberVar M := tonumber(right(totext(t),2));
time(h,m,0)
I think you will remember this, since I think I first learned this from you. In 8.0 and 8.5, you need an extra semi-colon after the last case statement--for no rhyme or reason. If you are using select case in a series of clauses connected by "and" (instead of in a variable as above), you need an extra close paren.
Just so that you have the entire formula correct, copy this:
NumberVar T := {HMN_UNSHDDAY.S_START};
numbervar l := len(totext(tonumber(t)));
numbervar c := select(l)
case 0 : 0
case 1 : 0
case 2 : 0
case 3 : 1
case 4 : 2;;
NumberVar H := tonumber(left(totext(t),c));
NumberVar M := tonumber(right(totext(t),2));
time(h,m,0)
//note the extra semicolorn on the case 4 : 2;; line.
Here is a new and much simpler formula. The problem I was having (besides driving down the rosy path) was that when the number was transformed to text it wasn't keeping the padded 0s. Now it does. Now this formula works as follows:
If any number is entered that is less than a 4 digit string then it will padd with 0s to the left to make it a 4 digit string. So 21 would be perceived as 0021 and not 2100.
NumberVar T := {HMN_UNSHDDAY.S_START};
T := if isnull({HMN_UNSHDDAY.S_START})
then 0 else T;
stringvar n := totext(T,'0000');
//the format string '0000' is required!
numbervar Hs := ToNumber(left(n,2));
numbervar Ms := toNumber(right(n,2));
time(hs,ms,0)
//formula end
//don't forget to format the field for the time display
//format that you want
Please keep in mind that if the field is null I am setting it to 0 which will return midnight. If this is a possibility you will want format the field to suppress if the field is null so that it doesn't display.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.