Home All Groups Group Topic Archive Search About

.dat retrieval and display

Author
31 Jan 2006 5:52 PM
Mick Whyte
Hi am working on an app that uses .dat file to store and retrieve.
Sending to the file is fine, but the retrieval won't. Code is:

Private Sub cmdDisplayFile_Click()
Dim index As Integer
Dim DataToDisplay As String
Dim Quantity As String * 4
Dim Price As String * 6
Dim reOrderLevel As String * 3
Dim product As OneProduct
filename = txtFileName.Text
lstDisplayFile.Clear
Open filename For Random As #1 Len = Len(product)



For index = 1 To NumberofRecords
'Numberofrecords declared in general section and passed:
'NumberofRecords = LOF(1) / Len(product)
Dim index As Integer
Dim DataToDisplay As String
Dim Quantity As String * 4
Dim Price As String * 6
Dim reOrderLevel As String * 3
Dim product As OneProduct
filename = txtFileName.Text
lstDisplayFile.Clear
Open filename For Random As #1 Len = Len(product)



For index = 1 To NumberofRecords

Get #1, , product
Quantity = product.QuantityinStock
Price = Format(product.Price, "currency")
reOrderLevel = product.reOrderLevel

DataToDisplay = product.productID & " " & product.Description _
& " " & Quantity & " " & Price & " " & reOrderLevel


Next index


Close #1

Get #1, , product
Quantity = product.QuantityinStock
Price = Format(product.Price, "currency")
reOrderLevel = product.reOrderLevel

DataToDisplay = product.productID & " " & product.Description _
& " " & Quantity & " " & Price & " " & reOrderLevel


Next index


Close #1

End Sub


No error is thrown just no return to the listbox (hace checked props,
is set to visible and enabled)

Any help greatly appreciated

Mick

Author
31 Jan 2006 6:09 PM
Norm Cook
Is this your cut 'n' pasted code?  For instance, I see these two lines

> Close #1
followed by
> Get #1, , product

which would surely raise an error.  Further, I see no reference to the
listbox other than > lstDisplayFile.Clear, i. e. there is no

lstDisplayFile.AddItem

Paste your code into your post.  Also show the definition for OneProduct

Show quoteHide quote
"Mick Whyte" <mick.wh***@gmail.com> wrote in message
news:1138729940.594338.73410@o13g2000cwo.googlegroups.com...
> Hi am working on an app that uses .dat file to store and retrieve.
> Sending to the file is fine, but the retrieval won't. Code is:
>
> Private Sub cmdDisplayFile_Click()
> Dim index As Integer
> Dim DataToDisplay As String
> Dim Quantity As String * 4
> Dim Price As String * 6
> Dim reOrderLevel As String * 3
> Dim product As OneProduct
> filename = txtFileName.Text
> lstDisplayFile.Clear
> Open filename For Random As #1 Len = Len(product)
>
>
>
> For index = 1 To NumberofRecords
> 'Numberofrecords declared in general section and passed:
> 'NumberofRecords = LOF(1) / Len(product)
> Dim index As Integer
> Dim DataToDisplay As String
> Dim Quantity As String * 4
> Dim Price As String * 6
> Dim reOrderLevel As String * 3
> Dim product As OneProduct
> filename = txtFileName.Text
> lstDisplayFile.Clear
> Open filename For Random As #1 Len = Len(product)
>
>
>
> For index = 1 To NumberofRecords
>
> Get #1, , product
> Quantity = product.QuantityinStock
> Price = Format(product.Price, "currency")
> reOrderLevel = product.reOrderLevel
>
> DataToDisplay = product.productID & " " & product.Description _
> & " " & Quantity & " " & Price & " " & reOrderLevel
>
>
> Next index
>
>
> Close #1
>
> Get #1, , product
> Quantity = product.QuantityinStock
> Price = Format(product.Price, "currency")
> reOrderLevel = product.reOrderLevel
>
> DataToDisplay = product.productID & " " & product.Description _
> & " " & Quantity & " " & Price & " " & reOrderLevel
>
>
> Next index
>
>
> Close #1
>
> End Sub
>
>
> No error is thrown just no return to the listbox (hace checked props,
> is set to visible and enabled)
>
> Any help greatly appreciated
>
> Mick
>
Author
31 Jan 2006 6:18 PM
Mick Whyte
Private Type OneProduct
productID As Integer
Description As String * 18
Price As Currency
QuantityinStock As Integer
reOrderLevel As Integer
End Type

Dim filename As String
Dim NumberofRecords As String

Is the definition of OneProduct


and

Private Sub cmdDisplayFile_Click()
Dim index As Integer
Dim DataToDisplay As String
Dim Quantity As String * 4
Dim Price As String * 6
Dim reOrderLevel As String * 3
Dim product As OneProduct
filename = txtFileName.Text
lstDisplayFile.Clear
Open filename For Random As #1 Len = Len(product)



For index = 1 To NumberofRecords

Get #1, , product
Quantity = product.QuantityinStock
Price = Format(product.Price, "currency")
reOrderLevel = product.reOrderLevel

DataToDisplay = product.productID & " " & product.Description _
& " " & Quantity & " " & Price & " " & reOrderLevel
'Assignment to list box here?

Next index


Close #1







End Sub

is the full button code. Dat file exists

Thanks a lot
Author
31 Jan 2006 6:42 PM
Rick Rothstein [MVP - Visual Basic]
> DataToDisplay = product.productID & " " & product.Description _
> & " " & Quantity & " " & Price & " " & reOrderLevel
> 'Assignment to list box here?

Use the ListBox's AddItem method to put the DataToDisplay into the list...

     List1.AddItem DataToDisplay

Rick
Author
31 Jan 2006 8:22 PM
Mick Whyte
Thanks a lot - I really appreciate the help. Have one more problem with
another app but will wait a couple of days - don't want to take up all
your time!