Results 1 to 2 of 2

Thread: Variable Problems

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    7

    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

  2. #2
    Junior Member
    Join Date
    Feb 2002
    Posts
    31
    hi buddy, I know how to solve your problem

    the error comes from he line

    VB Code:
    1. 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:
    1. ' ...
    2. Dim strB As String
    3. Dim strC As String
    4.  
    5. Input #1, strItem, strB, strC
    6.  
    7. intB = Val(strB)
    8. intC = Val(strC)
    9. ' ...

    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
  •  



Click Here to Expand Forum to Full Width