|
Home > Archive > SQL server exams > June 2002 > Visual Basic.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| tsigam 2002-05-31, 12:35 pm |
| If anyone know VB, Please help me write the calculations in VB. I have created the inetrface for the program, I'm having a hard time coding the calculations so that it displays the percentage for each soft drink brand.
The problem is to find the advertising expenditure percentage for each soft drink, cola-cola and Pesi for 1995 and 1996 expenditure and display the percentage for each.
1995 Cola-cola=$60.7 and 1996=$121.6
1995 Pepsi-cola=$94.8 and 1996=$83.0
the book says to use this formula to caculate:100 *([1996 expenditure]-[1995 expenditure])/1995 expenditure.
please help!!!!! | |
|
| Ummm... I'm not sure I see what it is you're trying to achieve - do you want to show changes (e.g. Coke 1996 was 200,32% of 1995 sales; Pepsi 1996 was 87,55% of 1995 sales)? Or are you trying to show how big market share Pepsi had vs Coke? | |
| tsigam 2002-06-01, 2:25 am |
| I am trying to show the percentages for each soft drink brand using those figure and formula on my previous thread. I am not comparing the changes...it's just displaying the figures once you code. I have tried to pull the information from a txt file and I still can't display anything....help!!! | |
|
| Why don't you post the relevant code, and I'll take a look at it. | |
| tsigam 2002-06-01, 2:09 pm |
| Here is the actaully question from the book.
Advertising expenditures (in millions of dollars) for the 4 most advertised soft drink brands during the first 9 months of 1995 and 1996. Write a prgram that displays the percentage change in advertsing for each brand. Sub procedures should be used for input and ouput and the percentage change should be computed with function procedure.
The percentage change is 100 * ([1996 expenditure] - [1995 expenditure])/ [1195 expenditure].
Table:
Coca-cola 1995 exp = 60.7, 1996 exp = 121.6
Pepsi-cola 1995 exp = 94.8, 1996 exp = 83.0
I don't know if this will help. | |
|
| (Assuming this is VB6-I forgot to ask...) I threw together the following code snippet, which calculates the expenditure using the formula you provided. Just create a new Standard EXE, paste the following code in the code window, run it and check the immediate pane:
Option Explicit
Private Sub Form_Load()
Dim Pepsi95 As Double, Pepsi96 As Double, Coke95 As Double, Coke96 As Double
Coke95 = 60.7
Coke96 = 121.6
Pepsi95 = 94.8
Pepsi96 = 83#
Debug.Print "Expenditure Change for Pepsi: " & CalcExpenditureChange(Pepsi96,
Pepsi95) & "%"
Debug.Print "Expenditure Change for Coke: " & CalcExpenditureChange(Coke96, Coke95) & "%"
End Sub
Private Function CalcExpenditureChange(ExpCurrY
ear As Double, ExpPrevYear As Double) As Double
CalcExpenditureChange = 100 * (ExpCurrYear / ExpPrevYear) / ExpPrevYear
End Function | |
|
| Note, the code lines got cut off when I pasted them, so you'll have to format the code... also, if you have any questions on the code, give me a shout. | |
| tsigam 2002-06-02, 2:16 pm |
| Yes, it's VB 6.0. I will copy and paste the program and run it.. thanks a lot, I will let you know. | |
| tsigam 2002-06-02, 2:29 pm |
| Thanks, man. I checked the immediate pane and it's running. Now I just have to create an interface for the program. Is there an easier way to craete an interface so that the percentages display.....Thanks | |
|
| The absolutely easiest way to display it though is by using a normal Label control to display the values (and Textboxes for the users to input values).
Shame the values are so low; normally when you're showing 0-100% status, a ProgressBar is always handy. In this case though you're dealing with very low percentages so maybe it won't be very visible at all. | |
| 2lazybutsmart 2002-06-03, 9:25 pm |
| Who can write -in the most condensed and simplified form, a piece of code that dumps into a List Box Control all Primary Numbers from 1 To 1000
If you guys get this right. then your on the quaterfinals, (ANOTHER ONE IS ON IT'S WAY). | |
| RichardJW 2002-06-19, 5:08 pm |
| tsigam, you already posted this Q up on the MCSD forum. Got no joy there?? If you can't create the interface - which is a single form with a couple of controls stuck in the middle of it - then I think it's a fair criticism to say that you're not a VB heavyweight. (Is there such a thing ?? ) Funny thing is, this is what you had to say in the MCSD forum: quote: I have created the inetrface for the program
So no problem!
Anyway, here's my code from the MCSD forum:
Private Sub Form_Load()
MsgBox CalcExpenditure(60.7, 121.6) & "%"
MsgBox CalcExpenditure(94.8, 83) & "%"
End Sub
Private Function CalcExpenditure(ByVal y1 As Long, ByVal y2 As Long) As Long
CalcExpenditure = 100 * (y2 - y1) / y1
End Function
And here's J-Ho's:
Option Explicit
Private Sub Form_Load()
Dim Pepsi95 As Double, Pepsi96 As Double, Coke95 As Double, Coke96 As Double
Coke95 = 60.7
Coke96 = 121.6
Pepsi95 = 94.8
Pepsi96 = 83#
Debug.Print "Expenditure Change for Pepsi: " & CalcExpenditureChange(Pepsi9
6, Pepsi95) & "%"
Debug.Print "Expenditure Change for Coke: " & CalcExpenditureChange(Coke96
, Coke95) & "%"
End Sub
Private Function CalcExpenditureChange(ExpCur
rYear As Double, ExpPrevYear As Double) As Double
CalcExpenditureChange = 100 * (ExpCurrYear / ExpPrevYear) / ExpPrevYear
End Function
Unfortunately CalcExpenditureChange is incorrect but that's probably just an oversight. Yes you could use double as the variable type or maybe single - in any case it's your choice tsigam, because last time I looked you were an MCSD.
hmm, 2lazybutsmart, P45 of "Programming in Modula-2" by Niklaus Wirth will provide you with a decent prime number generation algorithm. I have better things to do though than translate to VB. How about PI to the 10 millionth digit? Much more fun and also just as useless. | |
| ngo_28 2002-06-19, 5:14 pm |
| This project is DONE already...never mind...sorry | |
| RichardJW 2002-06-19, 5:22 pm |
| quote: This project is DONE already...never mind...sorry
What are you talking about may I ask?  |
|
|
|
|