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.

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

If CompanyName = "FranksCars" Then
		Discount = "15.00"
	ElseIf CompanyName = "MotorsRus" Then
		Discount = "10.00"
	Else
		Discount = "0.00"
	End If

Try this

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

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

If CompanyName = "FranksCars" Then
		Discount = "15.00"
	ElseIf CompanyName = "MotorsRus" Then
		Discount = "10.00"
	Else
		Discount = "0.00"
	End If

Try this

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?

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

If CompanyName = "FranksCars" Then
		Discount = "15.00"
	ElseIf CompanyName = "MotorsRus" Then
		Discount = "10.00"
	Else
		Discount = "0.00"
	End If

Try this

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

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

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

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

sorry didnt mean to post anything here

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.