Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,086 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,781 people online right now. Registration is fast and FREE... Join Now!




Need a very little help

 
Reply to this topicStart new topic

Need a very little help

maptiger
4 Jun, 2008 - 04:03 AM
Post #1

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 8






Hi all

I m not familiar with Javascript coding however i m converting one algorithm from javascript to vb.net class. i m stuck at a function for which i m unable to guess what it meant so please just elaborate a little bit that what the following functions does so i would be able to correct it.

CODE
hours = (hours+ 12 -1)% 12+ 1;


The main problem is the % sign that what it does actually.

I would be so thankful for your kind help.

MAP Tiger
VB.NET Programmer & Developer
User is offlineProfile CardPM
+Quote Post

fahlyn
RE: Need A Very Little Help
4 Jun, 2008 - 04:10 AM
Post #2

New D.I.C Head
*

Joined: 3 Nov, 2007
Posts: 43


My Contributions
% means modulus (division remainder).

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Need A Very Little Help
4 Jun, 2008 - 05:18 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
As already pointed out % in JavaScript is the Modulus function, a similar VB.Net conversion of that line of code would be


vb

hours = (hours + (12 -1)) Mod (12 + 1)


Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

maptiger
RE: Need A Very Little Help
4 Jun, 2008 - 08:23 AM
Post #4

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 8

QUOTE(PsychoCoder @ 4 Jun, 2008 - 06:18 AM) *

As already pointed out % in JavaScript is the Modulus function, a similar VB.Net conversion of that line of code would be


vb

hours = (hours + (12 -1)) Mod (12 + 1)


Hope that helps smile.gif


Thanks buddy but actually the code u given isnt working as if i place 16 for hours like this
CODE
hours = (12 + 1) Mod (16 + (12 - 1))


Result should be 4 but it is calculating it to 1 which is not correct of course.

I m still trying the wayouts but if u cud provide me some solution to this then it would be so great.

Thanks fahlyn too for the help.

MAP Tiger
VB.NET Programmer & Developer

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Need A Very Little Help
4 Jun, 2008 - 09:37 AM
Post #5

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Well this line

vb

hours = (12 + 1) Mod (16 + (12 - 1))


looks nothing like the line offered


vb

hours = (hours + (12 -1)) Mod (12 + 1)



If you want to calculate for 16 hours then the variable hours should have the value of 16, not the way you're doing this. Now Im moving this to the VB.NET Forum where it belongs smile.gif
User is offlineProfile CardPM
+Quote Post

maptiger
RE: Need A Very Little Help
4 Jun, 2008 - 09:56 AM
Post #6

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 8

QUOTE(PsychoCoder @ 4 Jun, 2008 - 10:37 AM) *

Well this line

vb

hours = (12 + 1) Mod (16 + (12 - 1))


looks nothing like the line offered


vb

hours = (hours + (12 -1)) Mod (12 + 1)



If you want to calculate for 16 hours then the variable hours should have the value of 16, not the way you're doing this. Now Im moving this to the VB.NET Forum where it belongs smile.gif


Well, sorry buddy i just copy pasted my workout to get correct value.

But the error mentioned occurs If i just place 16 instead of hour with the same syntax u gave then it is resulting 1

vb.net
(16 + (12 - 1)) Mod (12 + 1)


Thanks for the time u r giving me but actually the conversion is done but probably this statement is not giving me desired results. I m just stuck in it.

MAP Tiger
VB.NET Programmer & Developer

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Need A Very Little Help
4 Jun, 2008 - 10:53 AM
Post #7

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Try this line, this is exactly what you posted, only using VB.Net


vb

hours = (hours + 12 - 1) Mod (12 + 1);

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Need A Very Little Help
4 Jun, 2008 - 03:04 PM
Post #8

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
QUOTE(maptiger @ 4 Jun, 2008 - 10:56 AM) *

But the error mentioned occurs If i just place 16 instead of hour with the same syntax u gave then it is resulting 1

vb.net
(16 + (12 - 1)) Mod (12 + 1)


The correct answer is 1. So if that is the result you are getting, then everything is working just fine.

(16 + (12 - 1)) Mod (12 + 1)
(16 + (11)) Mod (13)
(27) Mod (13)
13 goes into 27 twice with a remainder of 1.

User is offlineProfile CardPM
+Quote Post

maptiger
RE: Need A Very Little Help
5 Jun, 2008 - 02:36 AM
Post #9

New D.I.C Head
*

Joined: 3 Jun, 2008
Posts: 8

QUOTE(PsychoCoder @ 4 Jun, 2008 - 11:53 AM) *

Try this line, this is exactly what you posted, only using VB.Net


vb

hours = (hours + 12 - 1) Mod (12 + 1);



Well, i m doing the same which is resulting to 1 which is not correct.

QUOTE(jayman9 @ 4 Jun, 2008 - 04:04 PM) *

QUOTE(maptiger @ 4 Jun, 2008 - 10:56 AM) *

But the error mentioned occurs If i just place 16 instead of hour with the same syntax u gave then it is resulting 1

vb.net
(16 + (12 - 1)) Mod (12 + 1)


The correct answer is 1. So if that is the result you are getting, then everything is working just fine.

(16 + (12 - 1)) Mod (12 + 1)
(16 + (11)) Mod (13)
(27) Mod (13)
13 goes into 27 twice with a remainder of 1.


No, buddy the requirement is to get 4 as 16 is represented as 4 PM so it should be converted to 4 then another function in this sub adds 'PM' to it.

Well, hopefully i will get the fix myself or by u guys soon.

Thanks a lot for helping.


MAP Tiger
VB.NET Programmer & Developer

This post has been edited by maptiger: 5 Jun, 2008 - 02:36 AM
User is offlineProfile CardPM
+Quote Post

rgfirefly24
RE: Need A Very Little Help
5 Jun, 2008 - 04:19 AM
Post #10

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 335



Thanked: 5 times
Dream Kudos: 150
My Contributions
they have tried to show you that the 1 IS correct the way you have the code right now. Let me break something down

MOD: Divide the part after mod into the part before it. Display the remainder.

now lets get into the actual math of it again:

hours = 16

16+12-1 = 28-1 = 27


12+1 = 13

so 27 /13 = 2 with a remainder of 1 so the output is 1. I don't understand how you think this is wrong. From a coding logic it is right, and from a mathematical standpoint it is right, what you have on your hands is wrong code.

Go back and rethink the way you have your code.


hours = (16 + 12 - 1) Mod (12+1) will never = 4. Sorry bud.

now, i think there is some loss in translation stuff going on here. Please describe exactly what you are trying to do so that we might be able to understand your problem a bit better.

what i am thinking:

you want to be able to convert 24 hour time to 12 hour time I.E

take 22 hundred hours and change it to 10PM. am i correct in this thinking?

This post has been edited by rgfirefly24: 5 Jun, 2008 - 04:29 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:47PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month