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

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

vb array using a text file

Reply to Message Icon

Original Message
Name: allLanguagesIn68Day
Date: February 15, 2003 at 10:53:35 Pacific
Subject: vb array using a text file
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!


Report Offensive Message For Removal


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

==========================================
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!
===========================================


Report Offensive Follow Up For Removal

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

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.


Report Offensive Follow Up For Removal







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








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software