I need to write a VB program which takes customer type, number of books purchased and cost of each book as an input.Then calculate the total sum after deducting discount that is to be paid by customer. Note that it needs to show both the total before discount and after discount.

There are 2 types of customers:
Individual and Educational.

if customer is individual then disc is as follows
If (numberbooks < 5) Then discount = 0
If (numberbooks > 4 And numberbooks < 25) Then discount = 15
If (numberbooks > 24) Then discount = 25

If customer is educational then
If (numberbooks < 5) Then discount = 5
If (numberbooks > 4 And numberbooks < 15) Then discount = 10
If (numberbooks > 14 And numberbooks < 25) Then discount = 15
If (numberbooks > 24 And numberbooks < 50) Then discount = 20
If (numberbooks > 49) Then discount = 30

Recommended Answers

All 20 Replies

did you use any backend file? like access or other. or you want to do it one time? just input customer type, number of books purchased and cost of each book and then get the result?

thanks for your reply.

the task says that i have to write a program in vb and then link it to the excel sheet so i assume that it is one time.....yes....

Is the excel sheet used for input? Meaning does the excel sheet contain the names of the books and the prices? If so then it is not one time.

Good Luck

Is the excel sheet used for input? Meaning does the excel sheet contain the names of the books and the prices? If so then it is not one time.

Good Luck[/QUOTe

the excel sheet i made has as an input from the user :
the customer type, the number of books he purchased and the price........any help would be appreciated.

thanks

Okay, so your doing this programming inside of excel? Then you need a vba forum and not a vb6 forum.

Good Luck

Okay, so your doing this programming inside of excel? Then you need a vba forum and not a vb6 forum.

Good Luck

thank u for yr reply but im still struggling how to do so?

Refer to your Student Working Model Book, page 236. It gives all the code.

Refer to your Student Working Model Book, page 236. It gives all the code.

i dnt know which book you are referring to....could u give me aname....plz....thanx

Okay, can you post what you have done so far?

What type of job do you normally do for you to want this program?

Okay, can you post what you have done so far?

What type of job do you normally do for you to want this program?

hi ....im a student....HND......and im struggling with this ...the tutor wants me to write the function and i tried ,,,,but its giving me errors.....

You should have said this from the start. I cannot help with writing functions. Perhaps you could give us what you wrote and maybe I can modify it or a forum member might help out?

A function is different to a sub routine.

Otherwise ask a fellow student or your teacher for some help.

Functions can be easy to create as much as they can be hard to write

You should have said this from the start. I cannot help with writing functions. Perhaps you could give us what you wrote and maybe I can modify it or a forum member might help out?

A function is different to a sub routine.

Otherwise ask a fellow student or your teacher for some help.

this is what i thought of....i dont know whether it is right or wrong?

Option Explicit

Dim numberbooks As Integer
Dim Customertype As Integer
Dim Subtotal As Double
Dim discount As Double
Dim totalprice As Double
Dim button As DialogSheetView
'Convert the user input to Integer'
'Ask whether the customertype is Individual or Educational'
button = MsgBox.Show(Customertype)
         MsgBox Title:
         MsgBox Buttons - individual - educational
         MsgBox Icon.Exclamation
'calculate the total before any discount
'Subtotal=convert to double(numberbooks)*price
'If Customer is Individual use appropriate discount according to number of books purchased
If button = Windows.forms.DialogSheetView Is individual Then
 
If (numberbooks < 5) Then discount = Subtotal * 0
 If (numberbooks > 4 And numberbooks < 25) Then discount = Subtotal * 15
If (numberbooks > 24) Then discount = Subtotal * 25
Else
If button = Windows.form.DialogSheetView Is educational Then

If (numberbooks < 5) Then discount = Subtotal * 5
If (numberbooks > 4 And numberbooks < 15) Then discount = Subtotal * 10
 If (numberbooks > 14 And numberbooks < 25) Then discount = Subtotal * 15
If (numberbooks > 24 And numberbooks < 50) Then discount = Subtotal * 20
 If (numberbooks > 49) Then discount = Subtotal * 30
End If
End If
'Calculate and display total price
Total Price = Subtotal - discount
Total PriceLabel.Text = totalprice.To String(' ',' ')
Display discount
MessageBox.show(DiscountMessage &-
Discount to String('c2') & "." -
Message Box Title.-
Message Box Buttons.Ok.-
Message Box Icon.Information)
End Sub
End Function


    
End If
End Function

You cannot do write a function within a sub routine. A function is the "sub routine". A sub routine can call a function that refers to a logic problem.

To insert a function. - On the toobar id a heading called Tools.
Tools > Add Procedure
Put in a name for the function, what you want to call it. Something descriptive like "CalcMyBooks"
Select option Function and Private. click OK.

The empty Function routine can be found at the bottom of the page
Write you function into it

You are using VB.Net which is different to VB6. Or perhaps a later version of VB, maybe vb7 or 8?

thanks Jupiter2...il try wht u advised me and will keep u updated

You are using VB.Net which is different to VB6. Or perhaps a later version of VB, maybe vb7 or 8?

thanks 4 the help...will try it and get back 2 u

I do not discuss or try to solve questions privately. My answers are not always correct and its good to get feedback from others. In certain circumstances where a Private answer is required I may do so.

Were you required to actually write a Function? Or just create a userform with textboxes and buttons with code to perform the input actions? I know you are a student, probably at a learning institute like TAFE and are a little confused about what you are actually supposed to do. There is no shame in asking a teacher to explain in more detail what is actually required. You will find the best programmers are the ones who ask the most questions.

To anyone who reads this, please feel free to join in.

See my next reply for the code that was sent privately.

This is the Function.
I think you should only have the logic problems in a Function. A Function basically works out the function.
In a sub routine you call function -
txtTotal.text= CalcMybooks(discount * Total)

Private Function calcmybooks()
MsgBox = vbYes("enter customertype", vbApplicationModal, customertype)
If customertype Is individual Then

If (numberbooks < 5) Then discount = Subtotal * 0
MsgBox ("discount")
If (numberbooks > 4 And numberbooks < 25) Then discount = Subtotal * 15
MsgBox ("discout")
If (numberbooks > 24) Then discount = Subtotal * 25
MsgBox ("discout")
Else
If customertype Is educational Then
MsgBox ("discout")
If (numberbooks < 5) Then discount = Subtotal * 5
MsgBox ("discout")
If (numberbooks > 4 And numberbooks < 15) Then discount = Subtotal * 10
MsgBox ("discout")
If (numberbooks > 14 And numberbooks < 25) Then discount = Subtotal * 15
MsgBox ("discout")
If (numberbooks > 24 And numberbooks < 50) Then discount = Subtotal * 20
MsgBox ("discout")
If (numberbooks > 49) Then discount = Subtotal * 30
MsgBox ("discout")
End If
End If
'calculate the total before any discount
Subtotal = (numberbooks) * Price
MsgBox = vbYes("enter price", vbApplicationModal, Subtotal = (numberbooks) * Price)
'Calculate and display total price
TotalPrice = Subtotal - discount
MsgBox=
End Function

This is the Function.
I think you should only have the logic problems in a Function. A Function basically works out the function.
In a sub routine you call function -
txtTotal.text= CalcMybooks(discount * Total)

Thanks for your help....i really appreciate it....
i amended the function as you advised me and emailed the tutor for some help....

Asking for help, even for simple questions wil make you one of the best programmers in the business.

Good Luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.