formatting - VBA Dateadd Format - Need In Total Minutes -
i have userform in microsoft excel want use stopwatch. format of "hh:mm" not allow go above 23:59 goes 00:00
private sub spinbutton2_spinup() if insertevent.textbox1 = vbnullstring insertevent.textbox1 = "00:00" else insertevent.textbox1.value = format(dateadd("n", 1, insertevent.textbox1.value), "hh:mm") 'insertevent.textbox1.value = timevalue("mm:ss") 'insertevent.textbox1.value = format(insertevent.textbox1.value, "hh:mm") end if end sub
is there anyway format can work clock of total minutes? ideally need go 125 minutes or (125:00) doesn't matter if unlimited.
you can't use built in date/time functions want representation not date/time.
assuming want read spinner value textbox:
private sub spinbutton2_spinup() dim minutes integer: minutes = val(insertevent.spinbutton2.value) dim hh integer: hh = minutes \ 60 dim mm integer: mm = minutes - (hh * 60) insertevent.textbox1.text = format$(hh, "00") & ":" & format$(mm, "00") end sub
to use manually entered value textbox starting up/down point need re-parse "hh:mm" minutes, example in textbox exit event:
private sub textbox1_exit(byval cancel msforms.returnboolean) if (isnumeric(textbox1.text)) '// entering number assumes minutes spinbutton2.value = textbox1.text exit sub end if dim hhmm() string: hhmm = split(textbox1.text, ":") if (ubound(hhmm) = 1) if (isnumeric(hhmm(0)) , isnumeric(hhmm(1))) spinbutton2.value = (hhmm(0) * 60) + hhmm(1) exit sub end if end if spinbutton2.value = 0 end sub
(should add error checking overflow/exceeding spinners .max property)
Comments
Post a Comment