|
|
#1 (permalink) | |
|
Monster Member
Join Date: Jun 2006
Age: 19
Posts: 2,462
Rep Power: 0
|
So basically i'm quite clueless at the syntax and structure of VB (declaring stuff, format etc) so i need some guidance. My task is to convert 24 hour time into 12 hour time so it changes from the form #### to ##:##am or pm (e.g. 1350 to 1:50pm)
What i've done so far probably doesn't make sense so please help! Quote:
Then for the formatting, joining the intHours and intMins and do something to get it into the correct format... |
|
|
|
|
|
|
|
|
#2 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
This is probably a very hacky way of doing this.. but its my 3 minute attempt..
PHP Code:
Stay away from Variant's at all costs. If you start using them for small pieces of code, they'll catch on, and make your programs slower than they already are with VB .. To use it: PHP Code:
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|
|
|
|
|
#4 (permalink) | |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
Quote:
![]() You could even use the Date type if you wanted. I just assume when you said "1350" that you meant an actual number. chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|
|
|
|
|
|
#5 (permalink) |
|
Monster Member
|
My attempt at that wouldn't be quite as professional but I think it would work.
Anything higher than 1200, change am to pm. Put a colon after 2 digits. Check the first 2 digits if it is 13, make it 1, if it is 14, make it 2. With some huge arse pathetic slow case select. I can do it if you want but its pretty unprofessional.
__________________
AMD 5000+BE@3.21GHZ//2GB OCZREAPER//ATI HD3870@850/1301 ANTEC 900//RAZER TARANTULA//TT TAI-CHI M2//SS 5HV2 XFI #GotGames #MelbCSS #s2.au #Reality.Gaming #TRAiNWRECK melb.lan.net.invite - kto_-[1b] |
|
|
|
|
|
#6 (permalink) |
|
Monster Member
Join Date: Jun 2006
Age: 19
Posts: 2,462
Rep Power: 0
|
I did mean an actual number, so i still have to put some "exit functions" or something if the number is invalid. i.e. if the last 2 numbers exceed 59 and if the first 2 numbers exceed 23 etc but that seems easy enough to do
We were supposed to able to use this newly created function in the Excel worksheet so when we type =ConvertTimeTo12(A1) it will return the formatted time |
|
|
|
|
|
#7 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
EDIT: Figured I'd give you the whole function instead of the extra fix:
PHP Code:
![]() chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - Last edited by chemicalNova; 05-05-2007 at 02:02 PM.. |
|
|
|
|
|
#9 (permalink) | |
|
Monster Member
Join Date: Jun 2006
Age: 19
Posts: 2,462
Rep Power: 0
|
Haha chem, you're too good for what my course expects
Instead of having popups etc, would this still be right? (syntax wise) Quote:
Also, the format for the time works for everything apart from times that end in 00 in which it would only display 1 zero in the converted time. i.e. 1500 becomes 3:0pm instead of 3:00pm. Is this where formatting comes in place? I remember the lecturer typing Print.Debug or something and then with some random '&'s everywhere instead of where you placed 'ret'....is this just an alternate method? |
|
|
|
|
|
|
#10 (permalink) | |||
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
Quote:
Quote:
PHP Code:
Quote:
PHP Code:
chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|||
|
|
|
|
|
#11 (permalink) | |
|
Monster Member
|
Quote:
x = "1500" y = InStr(x, "00") z = Mid(x,y) If z > 1 then `change the output end if I tried. >_< EDIT: too slow.
__________________
AMD 5000+BE@3.21GHZ//2GB OCZREAPER//ATI HD3870@850/1301 ANTEC 900//RAZER TARANTULA//TT TAI-CHI M2//SS 5HV2 XFI #GotGames #MelbCSS #s2.au #Reality.Gaming #TRAiNWRECK melb.lan.net.invite - kto_-[1b] |
|
|
|
|
|
|
#12 (permalink) |
|
Pro Member
Join Date: Jun 2006
Age: 19
Posts: 5,593
Rep Power: 8
|
For future reference shirase
![]() Left() Mid() and Right() return variants. Left$() Mid$() and Right$() return strings. If you're working with strings, make sure you use the right functions for better performance ![]() chem
__________________
There are no stupid questions... but there are alot of inquisitive idiots. - |
|
|
|
|
|
#13 (permalink) |
|
Monster Member
|
Awesome I didn't know about that dollar sign thing. =D You know I'm a failure at least I try. Haha.
__________________
AMD 5000+BE@3.21GHZ//2GB OCZREAPER//ATI HD3870@850/1301 ANTEC 900//RAZER TARANTULA//TT TAI-CHI M2//SS 5HV2 XFI #GotGames #MelbCSS #s2.au #Reality.Gaming #TRAiNWRECK melb.lan.net.invite - kto_-[1b] |
|
|
|










