Time 如何在QBasic中解析以年为单位的时间

Time 如何在QBasic中解析以年为单位的时间,time,basic,qbasic,Time,Basic,Qbasic,如何在Microsoft QBasic中解析测试所需的时间(月/日/年) s = 'PT1H28M26S' 我想得到: num_mins = 88 您可以使用下面的代码解析这样的时间字符串,但真正的问题是: 2015年谁还在使用QBasic CLS s$ = "PT1H28M26S" ' find the key characters in string posP = INSTR(s$, "PT") posH = INSTR(s$, "H") posM = INSTR(s$, "M") p

如何在Microsoft QBasic中解析测试所需的时间(月/日/年)

s = 'PT1H28M26S'
我想得到:

num_mins = 88

您可以使用下面的代码解析这样的时间字符串,但真正的问题是:
2015年谁还在使用QBasic

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?!"

在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

你是对的;QBasic肯定有飞蛾。你认为你有飞蛾吗?我们有吱吱作响的老鼠!