Results 1 to 16 of 16

Thread: Coding Help Again Please

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23

    Question Coding Help Again Please

    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.

    JAZ

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sounds like homework, post what you have so far and we'll take a look at it.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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.
    Attached Files Attached Files

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. Public Function TimeDifferenceInMins(ByVal Hours1 As Integer, ByVal Min1 As Integer, ByVal Hours2 As Integer, ByVal Min2 As Integer) As Integer
    2.         Dim minin1 As Integer = MinutesIn(Hours1, Min1)
    3.         Dim minin2 As Integer = MinutesIn(Hours2, Min2)
    4.         Return minin1 - minin2
    5.     End Function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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???

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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.

    JAZ

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.
    VB Code:
    1. Private Sub Test()
    2.         Dim str As String = "Starter"
    3.         ByValTest(str)
    4.         MsgBox(str) 'will be 'Starter'
    5.         ByRefTest(str)
    6.         MsgBox(str) 'will be 'ByRefChanged'
    7.     End Sub
    8.  
    9.     Private Sub ByValTest(ByVal str As String)
    10.         str = "ByValChanged"
    11.     End Sub
    12.  
    13.     Private Sub ByRefTest(ByRef str As String)
    14.         str = "ByRefChanged"
    15.     End Sub

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    The other thing I am not catching is how to code calling a function within a button click. I tried just putting

    Call TimeDifferenceInMins ()

    the computer wanted more information than that. So I have no idea as the examples in the book do not show anything like that.

    Thank you for your time.

    JAZ

  12. #12
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 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.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Sep 2003
    Posts
    23
    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.

    JAZ

  14. #14
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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.

  15. #15
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Don't listen to these C# fanatics C# will just confuse you with crazy syntax and case sensitivity not to mention all the ;;;; and {{}{}{}{}}}.

  16. #16
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width