Help needed with VB Assignment

Reply

Join Date: Apr 2004
Posts: 5
Reputation: JCD is an unknown quantity at this point 
Solved Threads: 0
JCD JCD is offline Offline
Newbie Poster

Help needed with VB Assignment

 
0
  #1
Apr 18th, 2004
Hello, i have been working on a VB Assignment which needs to be completed. However i have been experiencing some difficulties. I am not particularly experienced with VB, and so forgive me if these problems seem nooby..

Basically so far, i have a form where Data of a Customer and Car is stored in a Random Access File. This form is working fully correctly. I also have a stocklist form which is also working fully correctly, detailing Tyres name, ID , Quantity and Price. Anyhow the problem lies in a 3rd form. An Invoice. Im bring the data back from the Random Access Files ok, so it displays all data on my form. However the problem lies with calculating the price and discount. I have two problems, and i have tried all i can think of to get them working.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdDisplayPrice_Click()
  2. Dim Product As Tyre
  3. Dim Company As Companies
  4. Dim Car As Cars
  5. Dim CompanyName As String
  6. Dim Stocklist As String
  7. Dim Discount As Currency
  8.  
  9. Discount = lblDiscount.Caption
  10. CompanyName = lblCustomer.Caption
  11. Stocklist = "C:\Documents and Settings\Jack\My Documents\Project\Files\Stocklist.txt"
  12.  
  13. If CompanyName = "FranksCars" Then
  14. Discount = "£15.00"
  15. ElseIf CompanyName = "MotorsRus" Then
  16. Discount = "£10.00"
  17. Else
  18. Discount = "£0.00"
  19. End If
  20.  
  21.  
  22. Open Stocklist For Random As #1 Len = Len(Product)
  23. Do While (Not EOF(1)) And (Found = False)
  24.  
  25. RecordNumber = RecordNumber + 1
  26. Get #1, RecordNumber, Product
  27. If Product.TyreName = TyreType Then
  28. Found = True
  29. TotalNoVAT = Product.TyrePrice * TyreNo
  30. lblTotalNoVAT.Caption = TotalNoVAT
  31. End If
  32. Loop
  33. Close #1
  34.  
  35. End Sub

Is the code i currently have. Neither works unfortunately. The first bit to calculate the discount, is entering £0.00 everytime, even if i enter one of the Companys Specified to have a discount. The second one isn't giving any response whatsoever, and i have absolutely no clue how to go about fixing these.

If anyone can help i would be most grateful.

Thanks and Kind Regards

JCD
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 634
Reputation: Slade has a spectacular aura about Slade has a spectacular aura about 
Solved Threads: 7
Slade's Avatar
Slade Slade is offline Offline
Practically a Master Poster

help?

 
0
  #2
Apr 18th, 2004
Just a suggestion, I'm not particularly skilled with vb either so my suggestion may seem ridiculous but I thought I'd try to help anyways. Have you tried replacing the if statements with case statements? Like this?

Instead of
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. If CompanyName = "FranksCars" Then
  3. Discount = "£15.00"
  4. ElseIf CompanyName = "MotorsRus" Then
  5. Discount = "£10.00"
  6. Else
  7. Discount = "£0.00"
  8. End If

Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Select Case CompanyName
  3. Case "FranksCars"
  4. Discount = "£15.00"
  5. Case "MotorsRus"
  6. Discount = "£10.00"
  7. Case Else
  8. Discount = "£0.00"
  9. End select

Just a suggestion... I really hope you get it working, good luck!

Slade :p
Formerly known as Slade.
Reply With Quote Quick reply to this message  
Join Date: Feb 2003
Posts: 793
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Solved Threads: 27
Team Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: help?

 
0
  #3
Apr 20th, 2004
Originally Posted by slade
Just a suggestion, I'm not particularly skilled with vb either so my suggestion may seem ridiculous but I thought I'd try to help anyways. Have you tried replacing the if statements with case statements? Like this?

Instead of
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. If CompanyName = "FranksCars" Then
  3. Discount = "£15.00"
  4. ElseIf CompanyName = "MotorsRus" Then
  5. Discount = "£10.00"
  6. Else
  7. Discount = "£0.00"
  8. End If

Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Select Case CompanyName
  3. Case "FranksCars"
  4. Discount = "£15.00"
  5. Case "MotorsRus"
  6. Discount = "£10.00"
  7. Case Else
  8. Discount = "£0.00"
  9. End select

Just a suggestion... I really hope you get it working, good luck!

Slade :p

I agree with Slade, but I ask, have you run through the debug to see what the value is in the CompanyName variable?
Assistant Manager, Pharmacy Informatics
Wordpress Learning Blog
Updated : ASP.Net Login Code
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 5
Reputation: JCD is an unknown quantity at this point 
Solved Threads: 0
JCD JCD is offline Offline
Newbie Poster

Re: help?

 
0
  #4
Apr 21st, 2004
Originally Posted by slade
Just a suggestion, I'm not particularly skilled with vb either so my suggestion may seem ridiculous but I thought I'd try to help anyways. Have you tried replacing the if statements with case statements? Like this?

Instead of
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. If CompanyName = "FranksCars" Then
  3. Discount = "£15.00"
  4. ElseIf CompanyName = "MotorsRus" Then
  5. Discount = "£10.00"
  6. Else
  7. Discount = "£0.00"
  8. End If

Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Select Case CompanyName
  3. Case "FranksCars"
  4. Discount = "£15.00"
  5. Case "MotorsRus"
  6. Discount = "£10.00"
  7. Case Else
  8. Discount = "£0.00"
  9. End select

Just a suggestion... I really hope you get it working, good luck!

Slade :p
Tryed that.. unfortunately i get the same outcome. Im going to experiment later tonight, see if theres another way i can get around this problem. Has anyone any idea regarding my second problem of

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open Stocklist For Random As #1 Len = Len(Product)
  2. Do While (Not EOF(1)) And (Found = False)
  3.  
  4. RecordNumber = RecordNumber + 1
  5. Get #1, RecordNumber, Product
  6. If Product.TyreName = TyreType Then
  7. Found = True
  8. TotalNoVAT = Product.TyrePrice * TyreNo
  9. lblTotalNoVAT.Caption = TotalNoVAT
  10. End If
  11. Loop
  12. Close #1

not working? From what ive read and learned from my limited experience this should work. I've tried adding a
If Not Found Then
MsgBox "" & TyreType & "Not found"

to check if its actually finding the tyre type which unfortunately it isnt. This is weird, since if i open the random access file and import the entire stocklist into a listbox on another form, then the tyretype's searched for are definately there. This leads me to believe there could be a slight error in my code, is there any advanced VB Programmer able to spot what i've done wrong?

Kind Regards

JCD
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 5
Reputation: JCD is an unknown quantity at this point 
Solved Threads: 0
JCD JCD is offline Offline
Newbie Poster

Re: Help needed with VB Assignment

 
0
  #5
Apr 21st, 2004
Ok a slight advancement, i used a MsgBox to determine what CompanyName was and it seemed it was picking up part of the CompanyID which was recorded from the same record in the previous form. I looked at my declared record in the global and can see the record lengths of my strings are at fault. However this has now confused me beyond all belief. Could someone kindly explain how the string lengths should be worked out? If i set the string length of the ID to 1 instead of 3 it then becomes "2FranksCars" or "3MotorsRus", this is really confusing me. A little guidance would be greatly appreciated on this aspect.

Kind Regards

JCD
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 2
Reputation: ardsuggy is an unknown quantity at this point 
Solved Threads: 0
ardsuggy ardsuggy is offline Offline
Newbie Poster

Re: Help needed with VB Assignment

 
0
  #6
Dec 5th, 2007
sorry didnt mean to post anything here
Last edited by ardsuggy; Dec 5th, 2007 at 6:08 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC