| | |
Help needed with VB Assignment
![]() |
•
•
Join Date: Apr 2004
Posts: 5
Reputation:
Solved Threads: 0
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.
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
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)
Private Sub cmdDisplayPrice_Click() Dim Product As Tyre Dim Company As Companies Dim Car As Cars Dim CompanyName As String Dim Stocklist As String Dim Discount As Currency Discount = lblDiscount.Caption CompanyName = lblCustomer.Caption Stocklist = "C:\Documents and Settings\Jack\My Documents\Project\Files\Stocklist.txt" If CompanyName = "FranksCars" Then Discount = "£15.00" ElseIf CompanyName = "MotorsRus" Then Discount = "£10.00" Else Discount = "£0.00" End If Open Stocklist For Random As #1 Len = Len(Product) Do While (Not EOF(1)) And (Found = False) RecordNumber = RecordNumber + 1 Get #1, RecordNumber, Product If Product.TyreName = TyreType Then Found = True TotalNoVAT = Product.TyrePrice * TyreNo lblTotalNoVAT.Caption = TotalNoVAT End If Loop Close #1 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
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
Try this
Just a suggestion... I really hope you get it working, good luck!
Slade :p
Instead of
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
If CompanyName = "FranksCars" Then Discount = "£15.00" ElseIf CompanyName = "MotorsRus" Then Discount = "£10.00" Else Discount = "£0.00" End If
Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Select Case CompanyName Case "FranksCars" Discount = "£15.00" Case "MotorsRus" Discount = "£10.00" Case Else Discount = "£0.00" End select
Just a suggestion... I really hope you get it working, good luck!
Slade :p
Formerly known as Slade.
•
•
•
•
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)
If CompanyName = "FranksCars" Then Discount = "£15.00" ElseIf CompanyName = "MotorsRus" Then Discount = "£10.00" Else Discount = "£0.00" End If
Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Select Case CompanyName Case "FranksCars" Discount = "£15.00" Case "MotorsRus" Discount = "£10.00" Case Else Discount = "£0.00" 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?
•
•
Join Date: Apr 2004
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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)
If CompanyName = "FranksCars" Then Discount = "£15.00" ElseIf CompanyName = "MotorsRus" Then Discount = "£10.00" Else Discount = "£0.00" End If
Try this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Select Case CompanyName Case "FranksCars" Discount = "£15.00" Case "MotorsRus" Discount = "£10.00" Case Else Discount = "£0.00" End select
Just a suggestion... I really hope you get it working, good luck!
Slade :p
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Open Stocklist For Random As #1 Len = Len(Product) Do While (Not EOF(1)) And (Found = False) RecordNumber = RecordNumber + 1 Get #1, RecordNumber, Product If Product.TyreName = TyreType Then Found = True TotalNoVAT = Product.TyrePrice * TyreNo lblTotalNoVAT.Caption = TotalNoVAT End If Loop 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
•
•
Join Date: Apr 2004
Posts: 5
Reputation:
Solved Threads: 0
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
Kind Regards
JCD
![]() |
Similar Threads
- Needed help on assignment (C++)
- Help needed with assignment (C++)
- help needed with my assignment (C)
- Help Needed on C++ assignment (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: using variable in datasource in visual basic 6
- Next Thread: Need Help With Problem please
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





