Jump to content
Macro Express Forums

Converting Military Time To Fractional Hours


Recommended Posts

Ok, so this is my problem. Im trying to convert standard military time into a fractional hour time and I'm having a hell of a time with it. Example: 1020hrs would need to equal 103 (or 10.3 if that helps explain it) 1930hrs would equal 105 (or again 10.5 if that helps) The problem I've run into is that I have a big IF / ELSE statement that checks the last 2 digits of the military time, i then have the macro feed that integer into my desired text position in my program, BUT, each of the next IF/ELSE statements also is true so it keeps going through the macro and it keeps feeding in additional characters into text fields where I don't want anything filled in.

 

Example:

 

if the integer is <=05, i want the macro to feed me a 0, and stop checking

if the integer is <=10, i want the macro to feed me a 1

if the integer is <= 55, i want the macro to feed me a 9

 

The IF/ELSE statment I have sees the 05 is <=6 so it gives me a 0, the problem lies in the next statement where the IF/ELSE statement checks to see if the number is <=12, which it also is, so it follow through and adds more text i dont want...I want it to STOP after it has done it first TRUE if statement. Im a hardware tech at heart, so this feels too much like programming to me...any pointers in the right direction would be greatly appreciated.

 

Stek

 

P.S> I have a sneaking suspicion there is a between statment im just missing...if the integer is BETWEEN 0-6 give me a 0, BETWEEN 7-12 give me a 1, BETWEEN 13-18 give me a 3....

Link to comment
Share on other sites

Stek -

 

Without seeing the code, I would suggest reversing the IF/ENDIF test. Test for the higher value (55) first, then the next lower value (10), and then the lowest value (05).

 

There is no BETWEEN statement, however you can accomplish the same thing using the AND statement:

// BETWEEN 0-6 give me a 0
// BETWEEN 7-12 give me a 1
// BETWEEN 13-18 give me a 3....
If Variable %N1% >= 0
 AND
If Variable %N1% <= 6
 Variable Set Integer %N2% to 0
End If
If Variable %N1% >= 7
 AND
If Variable %N1% <= 12
 Variable Set Integer %N2% to 1
End If
If Variable %N1% >= 13
 AND
If Variable %N1% <= 18
 Variable Set Integer %N2% to 3
End If

<REM2:BETWEEN 0-6 give me a 0><REM2:BETWEEN 7-12 give me a 1><REM2:BETWEEN 13-18 give me a 3....><IFVAR2:2:01:5:0><AND><IFVAR2:2:01:6:6><IVAR2:02:01:0><ENDIF><IFVAR2:2:01:5:7><AND><IFVAR2:2:01:6:12><IVAR2:02:01:1><ENDIF><IFVAR2:2:01:5:13><AND><IFVAR2:2:01:6:18><IVAR2:02:01:3><ENDIF>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...