Computing.Net > Forums > Programming > vb array using a text file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb array using a text file

Reply to Message Icon

Name: allLanguagesIn68Day
Date: February 15, 2003 at 10:53:35 Pacific
OS: all
CPU/Ram: all
Comment:

Here's what I want to do:
* I want to store 3 fields(Item#,Item Name,Unit Price) in a text file. The details should be read into three parallel arrays.

* I want to be able to read user input from the keyboard(i.e. not from a text file) using inputbox. The program should ask
CustomerName:
Item#:
Quantity:

* Finally the program should display something like the following:

Customer Name: Mr.Bla Bla
Item# | Quantity | Price |SubTotal
007 4 2.00 $8.00
010 1 4.00 $4.00

Total: $12.00

I think I need a while statement with a rouge here.
I'd like to tackle this with pure VB not active x. You know--just simple!



Sponsored Link
Ads by Google

Response Number 1
Name: allLanguagesIn68Days
Date: February 15, 2003 at 22:27:58 Pacific
Reply:

==========================================
Option Explicit
Dim fItemNumber(100) As Integer
Dim fItemName(100) As Integer
Dim fUnitPrice(1000) As Integer
Dim fNumRecs As Integer
Dim fCustomerName As String
Dim fQuantity As Integer

Private Sub cmdChoose_Click()

Dim i As Integer
i = 0

fCustomerName = InputBox("What's your name?")
fItemNumber = InputBox("What's the item number?")
fItemName = InputBox("What's the item name?")
fQuantity = InputBox("How much quantity do you need?")
Open "a:\list.txt" For Input As #1


While Not EOF(1)
i = i + 1
fItemNumber (i), fItemName(i), fUnitPrice(i)
Wend
Close #1
fNumRecs = i

End Sub

Private Sub cmdPrint_Click()
Dim i As Integer
Dim total As Single


For i = 1 To fNumRecs
Print fCustomerName(i), fItemNumber(i), fItemName(i), fUnitPrice(i),
Print fUnitPrice * fQuantity
Next i
End Sub
==========================================
need help/hints/comments or whatever.....anything appriciated!
===========================================


0

Response Number 2
Name: allLanguagesIn68Days
Date: February 16, 2003 at 21:49:37 Pacific
Reply:

I'm getting there....any help is accepted
=================================================
Option Explicit
Dim fItemNumber(10) As Integer
Dim fItemName(10) As Integer
Dim fUnitPrice(10) As Single

Private Sub cmdChoose_Click()
Dim Customer As String
Dim i As Integer
Dim found As Integer
Dim itemNumber As Integer


i = 0
found = False
'fNumRecs = 1

Open "a:\list.txt" For Input As #1


While Not EOF(1)
i = i + 1
Input #1, fItemNumber(i), fItemName(i), fUnitPrice(i)
Close #1

Customer = InputBox("What's your name?")
Print
Print (Customer)
Print "=================================="

itemNumber = InputBox("What's the item number? (Choose 1-10 inclusive)")
While itemNumber -999
If itemNumber = fItemNumber(i) Then
found = True
Else
i = i + 1
End If
Wend
If found = True Then
Print fItemNumber(i), fItemName(i), fUnitPrice(i)
Else
Print "Item Not On Stock"
End If

Wend


End Sub
====================================
in my a:\list , i only have 10 records.
for eg.
1,"coke",1.00
2,"pepsi",1.00
3,"sprite",1.00
.
..
...
10,"dr.pepper",1,00
==============================
also,My while statement seems to be unending.
While itemNumber -999
If itemNumber = fItemNumber(i) Then
found = True
Else
i = i + 1
End If
wend

It prompts me subscript out of range.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: vb array using a text file

Help browsing a text file www.computing.net/answers/programming/help-browsing-a-text-file/9929.html

How to create a text file using FSO www.computing.net/answers/programming/how-to-create-a-text-file-using-fso/10319.html

splitting a text file www.computing.net/answers/programming/splitting-a-text-file/14804.html