c.haslam Posted April 12 Share Posted April 12 Here's my code: $tin = "8:00 PM" $vec = StringSplit($tin,": ",0) ; STR_CHRSPLIT $hr = Number($vec[1]) $min = $vec[2] If $vec[3]="PM" Then $hr = $hr + 12 EndIf $ret = $hr + ":" + $min MsgBox(0,"",$ret,15) $ret should be 20:00 but it is actually 20 Ideas? I have tried applying String() Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Solution rsn Posted April 12 Solution Share Posted April 12 Change $ret = $hr + ":" + $min to $ret = $hr & ":" & $min Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 12 Moderators Share Posted April 12 23 minutes ago, c.haslam said: Here's my code: $tin = "8:00 PM" $vec = StringSplit($tin,": ",0) ; STR_CHRSPLIT $hr = Number($vec[1]) $min = $vec[2] If $vec[3]="PM" Then $hr = $hr + 12 EndIf $ret = $hr + ":" + $min MsgBox(0,"",$ret,15) $ret should be 20:00 but it is actually 20 Ideas? I have tried applying String() I'd suggest you actually run that code, there's no $vec[3] so it will certainly crash. As RSN stated, string concatenation is done with an ampersand -> &, we use the + operator only for math. If your strings will look like what you have (eg. "8:00 PM"), then maybe try a regex. Your code: #include <Array.au3> Global $gaArgs = StringSplit("8:00 PM", ":") _ArrayDisplay($gaArgs) Simple approach (keep in mind, the arrays for regular expressions are zero based) #include <Array.au3> Global $gsTime = "8:00 PM" Global $gaArgs = StringRegExp($gsTime, "(.+?)(?:\W|$)", 3) _ArrayDisplay($gaArgs) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
c.haslam Posted April 12 Author Share Posted April 12 Thank you both. I have been away from AutoIt for too long, so I tend to think PerfectScript. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
rsn Posted April 12 Share Posted April 12 @SmOke_N OP's StringSplit does have two delimiters (":" and " ") so $vec[3] is defined. Your explanation is certainly better than mine 🤦♂️ Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 12 Moderators Share Posted April 12 5 minutes ago, rsn said: @SmOke_N OP's StringSplit does have two delimiters (":" and " ") so $vec[3] is defined. Your explanation is certainly better than mine 🤦♂️ Damn these eyes.. I seriously didn't see the space! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
UEZ Posted April 12 Share Posted April 12 (edited) An old thread: www.autoitscript.com/forum/topic/131335-convert-time-in-string-to-time-value Edited April 12 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Nine Posted April 12 Share Posted April 12 Or m23 : “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted April 13 Share Posted April 13 You can also use a one-liner: Local $a = [" 12:0am", "12:12 AM", "2:3 aM", "11:59 am", "12:00 pm", "12:45pm ", "03:15 PM", "11:59 Pm"], $t For $s In $a $t = Execute((StringRegExpReplace($s, "(?i)(\d{1,2}):(\d{1,2})\h*([AP])M", "StringFormat('%02i', Mod(Execute('(( ((''$3'' & ''$1'' = ''A12'') OR (''$3'' = ''P'' AND ''$1'' < 12)) ? 12 : 0) + $1)'), 24)) & ':' & StringFormat('%02i', '$2')"))) ConsoleWrite($s & @TAB & $t & @LF) Next Beware that the OP code (even when fixed) gets 12 AM and 12 PM wrong! This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Nine Posted April 13 Share Posted April 13 (edited) Oh well, another one liner then (less abstruse ) : $t = Mod(StringRegExp($s, "(\d{1,2})", 1)[0], 12) + (StringRegExp($s, "(?i).*([AP]M)", 1)[0] = "AM" ? 0 : 12) & StringRegExp($s, "(:\d{1,2})", 1)[0] Edited April 13 by Nine rsn 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted April 13 Share Posted April 13 Ah yes, HH mod 12 is smarter. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now