943,740 Members | Top Members by Rank

Ad:
Apr 18th, 2004
0

Help needed with VB Assignment

Expand Post »
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
Similar Threads
JCD
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JCD is offline Offline
5 posts
since Apr 2004
Apr 18th, 2004
0

help?

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
Reputation Points: 115
Solved Threads: 7
Practically a Master Poster
Slade is offline Offline
633 posts
since Mar 2004
Apr 20th, 2004
0

Re: help?

Quote 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?
Team Colleague
Reputation Points: 211
Solved Threads: 27
Master Poster
Paladine is offline Offline
793 posts
since Feb 2003
Apr 21st, 2004
0

Re: help?

Quote 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
JCD
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JCD is offline Offline
5 posts
since Apr 2004
Apr 21st, 2004
0

Re: Help needed with VB Assignment

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
JCD
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JCD is offline Offline
5 posts
since Apr 2004
Dec 5th, 2007
0

Re: Help needed with VB Assignment

sorry didnt mean to post anything here
Last edited by ardsuggy; Dec 5th, 2007 at 6:08 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ardsuggy is offline Offline
2 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: using variable in datasource in visual basic 6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Need Help With Problem please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC