2 Replies - 548 Views - Last Post: 15 November 2012 - 01:39 PM Rate Topic: -----

#1 Prino33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-November 12

Function Related Question.

Posted 15 November 2012 - 11:46 AM

I'm having some trouble converting a program I did to a function based program. I did well on the assignment when I did it without functions so my code is good. I just haven't figured out how to convert old loops to functions.

My teacher isn't very good at explaining this stuff. The class average grade on the last assignment was a 62, he did curve it but I'm not really learning much and I'm afraid when the exam comes around I'm not going to do well.

Any help would be greatly appreciated.

Thanks,

Joe

P.S. I attached my old code and what have to do with it now. If anyone was wondering exactly what type of function we have to do. Anyways, thanks again.

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Function Related Question.

#2 Psyguy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 75
  • View blog
  • Posts: 323
  • Joined: 12-January 11

Re: Function Related Question.

Posted 15 November 2012 - 12:08 PM

From what your post states, it appears that what you are trying to do is refactor the code into functions. If that is correct, here is an example of where you might do that (taken from your previous code):

'old code in the btnCalculate click event handler
If rbSingleRoom.Checked Then
     ExtraGuestSurcharge = (cintSingleRoomSurcharge * (mintNumberOfGuests - 1)) * LengthOfStay
ElseIf rbDoubleRoom.Checked Then
     ExtraGuestSurcharge = (cintDoubleRoomSurcharge * (mintNumberOfGuests - 2)) * LengthOfStay
ElseIf rbSuite.Checked Then
     ExtraGuestSurcharge = (cintSuiteRoomSurcharge * (mintNumberOfGuests - 3)) * LengthOfStay
End If

'possible function based code which would replace the above code
ExtraGuestSurcharge = CalculateSurCharge(LengthOfStay)


'**********function code*****************
Private Function CalculateSurCharge(ByVal lenOfStay as Integer) as Double
Dim ret as Double

If rbSingleRoom.Checked Then
     ret = (cintSingleRoomSurcharge * (mintNumberOfGuests - 1)) * lenOfStay
ElseIf rbDoubleRoom.Checked Then
     ret = (cintDoubleRoomSurcharge * (mintNumberOfGuests - 2)) * lenOfStay
ElseIf rbSuite.Checked Then
     ret= (cintSuiteRoomSurcharge * (mintNumberOfGuests - 3)) * lenOfStay
End If

GetSurCharge = ret
End Function




Also, i think you posted this in the wrong forum as it is .NET not VB6.
Was This Post Helpful? 1
  • +
  • -

#3 Prino33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-November 12

Re: Function Related Question.

Posted 15 November 2012 - 01:39 PM

Thanks for the reply. You definitely got me on the right track. I think I'm going to try a select case function for the late charge fee. Not exactly sure how to do a sub procedure to display the results but I haven't really messed with it.

Anyways thanks for the help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1