Good Afternoon,
I had posted asking for help before and received much. However, I am still a bit stuck. Can someone please help. I need to create a project with the following:
1. A sub method called InTwo, which accepts two integer arguments that are passed by reference. The code should use two input boxes to input the 2 integers from the user.
2. A function method, which takes in two integers, that represent time in hours and minutes. Call the Function MinutesIn. The function should return the total time in minutes.
3. A second function method TimeDifferenceInMins, with 4 ByVal arguments and an integer return result. The function accepts two times in hours and minutes and returns the difference between them in minutes. Use the InTwo and MinutesIn procedures.
The form cam only have 1 calculate button and 1 exit button. The calculate button must include the code to call the TimeDifferenceInMins Function.
I thought I understood how I was supposed to code this and when I tried it there was a major mess. Any responses are greatly appreciated.
OK, I have erased and changed so much I had to start over so I haven't gotten very far. It seems like it should be really simple, yet there is something I am not catching as I tried asking a question in my class and caused great confusion so I haven't asked again this week. Thank you for your time.
Ok now what parts do you understand and what is giving you trouble? I don't what to just do it for you or you wont learn anything.
It looks like you have the MinutesIn function, what is the point of the InTwo method? I'm also unclear on the TimeDifference one wouldn't you just call MinutesIn for each set and subtract them for the difference:
VB Code:
Public Function TimeDifferenceInMins(ByVal Hours1 As Integer, ByVal Min1 As Integer, ByVal Hours2 As Integer, ByVal Min2 As Integer) As Integer
First let me ask a question about what you posted and then I will gather all of my questions and ask here and hope I don't cause the confusion I did in class. I do want to learn this language so that is why I ask for help here.
How come you put in Public Function instead of Private Function???
Just force of habit I guess. In your case it doesn't really matter but since you don't need it outside of this form then you can make it private instead.
The InTwo method is supposed to accept two integers that are passed by reference. I really do not know why it would have to even be necessary, but it is required. He just put the code should use two input boxes to input the 2 integers, from the user. When he showed us his .exe file when you click on the calculate button 4 input boxes came up one after another that said "Enter the Hours, Enter the Minutes, Enter the Hours, Enter the Minutes. My guess is to try and use two different method types to make one Function Method. I am not quite sure about how to distinguish the hours (each one separately) and the minutes (each one separately)
I started writing
Private Sub InTwo(ByRef intHours As Integer, ByRef intMinutes As Integer) As Integer
intHours = InputBox ("Enter the Hours:,"")
intMinutes = InputBox ("Enter the Minutes:,"")
End Sub
This did not seem to go anywhere so I erased it.
The TimeDifferenceInMins is supposed to work when the calculator button is clicked and have 4 ByVal arguments and an integer return result to the label. I have no clue as to how to use both the InTwo and MinutesIn procedures during this procedure.
I am not even sure about the variables I did declare if they are all necessary or not. Thank you for your help as it has been a VERY long Night and all Day with this.
What is the ByVal and ByRef? I understand that a Function must return a Value (I guess that is what ByVal means). When it comes to declarations at the top I generally do not know for sure what to put so I try and go through my code to find it.
In a nutshell ByRef passes the variable and ByVal passes a copy of the variable or the value only. If something is passed in Byref then it can be changed in the method.
That makes sense. One can be changed and the other is like a read only file. How can I make one button do so many things? I could understand if you had multiple buttons, but only one I do not know how to compile all of the items into one thing.
Well for starters you don't need to use the Call keyword, you can just use the method name. Point two is that with all methods that have parameters you must pass the information into those parameters (unless they are marked as optional). Point three a function differs from a sub in that it returns a value so when calling a function you should be assigning something to its returned value.
VB Code:
dim returnValue as integer=TimeDifferenceInMins(param1,param2,param3,param4)
I don't think I understood your button question. If you want to do several things in the click event then just do several things there.
Thank you for your post. I have gotten farther than the last time, but I am not really sure how to make the return value show up in the LabelBox so I am working on that. I really had no idea you could just say several items of action in the same section. I thought you had to make a new section for a different desired action. Anyway, I now have 4 input boxes coming up and asking for hours and minutes. I just have to do the rest. Thank you for all of your extra effort. I appreciate you answering my questions.
When you are finish with this VB.NET, dont take another one. Continue with C# . VB will confuse the hell out of you if you are a beginner with stuff like ByVal, ByRef Sub and Function among other little quirks that MS left in for backwards compatability.
C# = clean
VB.NET = wordy
Also you might want to do some extra reading.
Originally posted by Edneeis Don't listen to these C# fanatics C# will just confuse you with crazy syntax and case sensitivity not to mention all the ;;;; and {{}{}{}{}}}.
Hey Edneeis, I thought you had come over to our side?