2015-03-28 1 views

Répondre

1

Vous pouvez analyser une telle chaîne de temps avec le code ci-dessous, mais la vraie question est:
Qui utilise encore QBasic en 2015 !?

CLS 
s$ = "PT1H28M26S" 

' find the key characters in string 
posP = INSTR(s$, "PT") 
posH = INSTR(s$, "H") 
posM = INSTR(s$, "M") 
posS = INSTR(s$, "S") 

' if one of values is zero, multiplying all will be zero 
IF ((posP * posH * posM * posS) = 0) THEN 
    ' one or more key characters are missing 
    nummins = -1 
    numsecs = -1 
ELSE 
    ' get values as string 
    sHour$ = MID$(s$, posP + 2, (posH - posP - 2)) 
    sMin$ = MID$(s$, posH + 1, (posM - posH - 1)) 
    sSec$ = MID$(s$, posM + 1, (posS - posM - 1)) 

    ' string to integer, so we can calculate 
    iHour = VAL(sHour$) 
    iMin = VAL(sMin$) 
    iSec = VAL(sSec$) 

    ' calculate totals 
    nummins = (iHour * 60) + iMin 
    numsecs = (iHour * 60 * 60) + (iMin * 60) + iSec 
END IF 

' display results 
PRINT "Number of minutes: "; nummins 
PRINT "Number of seconds: "; numsecs 
PRINT "QBasic in 2015! w00t?!" 
0

façon plus simple de saisir minutes de chaîne dans qbasic

REM Simpler way to grab minutes from string in qbasic 
S$ = "PT1H28M26S" 
S$ = MID$(S$, 3) ' 1H28M26S 
V = INSTR(S$, "H") ' position 
H = VAL(LEFT$(S$, V - 1)) ' hours 
S$ = MID$(S$, V + 1) ' 28M26S 
V = INSTR(S$, "M") ' position 
M = VAL(LEFT$(S$, V - 1)) ' minutes 
PRINT "num_mins ="; H * 60 + M