Home > Archive > Visual Basic > January 2006 > .dat retrieval and display
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
.dat retrieval and display
|
|
| Mick Whyte 2006-01-31, 6:55 pm |
| 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
| |
| Norm Cook 2006-01-31, 6:55 pm |
| 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
"Mick Whyte" <mick.whyte@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
>
| |
| Mick Whyte 2006-01-31, 6:55 pm |
| 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
| |
| Rick Rothstein [MVP - Visual Basic] 2006-01-31, 6:55 pm |
| > 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
| |
| Mick Whyte 2006-01-31, 6:55 pm |
| 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!
|
|
|
|
|