|
-
Jun 16th, 2004, 08:22 PM
#1
Thread Starter
New Member
Variable Problems
My code reads a file to a report and prints inventory#, quantity, & price in separate columns. The inventory# is printing out just fine but my quantity and price variables are equating to zeros
____________________________________________________
Private Sub cmdEnter_Click()
'Write Data to File
Open "C:\Frank's VBstudent files\Tut06\la3.dat" For Append As #1
Write #1, txtItem.Text, txtQuan.Text, txtPrice.Text
Close #1
lblTprice.Caption = txtQuan.Text * txtPrice.Text
intValue = lblTprice.Caption
End Sub
Private Sub cmdPrint_Click()
Dim strPS As String * 5, strPS1 As String * 5, strPS2 As String * 6
Dim strPS3 As String * 6, strItem As String, intX As Integer, sngTprice As Single, intQuantity As Integer
Dim intPrice As Integer, intTcounter As Integer, intAvg As Integer
Dim intB As Integer
Dim intC As Integer
'Declare Variables
strItem = txtItem.Text
intB = Val(txtQuan.Text)
intC = Val(txtPrice.Text)
'Open sequential file
Printer.Print Tab(20); "Inventory #"; Tab(40); "Quantity"; Tab(60); "Item Price"
Open "C:\Frank's VBstudent files\Tut06\la3.dat" For Input As #1
Do While Not EOF(1)
Input #1, strItem, intB, intC
sngTprice = Val(intB) * Val(intC)
intTcounter = intTcounter + Val(sngTprice)
RSet strPS = strItem
RSet strPS1 = Format(intB, "General number")
RSet strPS2 = Format(intC, "Currency")
Printer.Print Tab(22); strPS; Tab(42); strPS1; Tab(62); strPS2
intX = intX + 1 'updater
Loop
intAvg = intTcounter / intX
Close #1
Printer.Print
Printer.Print
RSet strPS3 = Format(intAvg, "Currency")
Printer.Print Tab(55); "Average"; Tab(62); strPS3
Printer.EndDoc
End Sub
-
Jun 17th, 2004, 01:05 AM
#2
Junior Member
hi buddy, I know how to solve your problem
the error comes from he line
VB Code:
Input #1, strItem, intB, intC
in fact datas in your .dat file are stored as string and VB doesn't wanna make the conversion from string to integer in the Input statement
add this to your code will solve the problem
VB Code:
' ...
Dim strB As String
Dim strC As String
Input #1, strItem, strB, strC
intB = Val(strB)
intC = Val(strC)
' ...
have fun
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|