|
-
Mar 31st, 2004, 06:23 AM
#1
Thread Starter
Hyperactive Member
Stepping backward using Input #n[resolved]
Here's the deal. I have some code which, to cut a long story short, reads some values from a barcode scanner into an array and compares them with values in a text file.
I have a problem in that if I get a mismatch I want to halt the process and allow the user to re-scan the barcode and compare it against the corresponding value in the text file.
To do this, I think I need to step back in the text file (comma delimited) to ensure that the correct value is being compared.
Here's the code I have, which works great if all values match. There is more to it but here's the bit I'm concentrating on..
VB Code:
Private Sub cmdCompare_Click()
Dim arrX As Integer
cmdCompare.Enabled = False
If n = 0 Then n = 1
If n = 1 Then
Open strinfile For Input As #1
End If
For arrX = 0 To UBound(myArray)
Input #1, LineIn
If LineIn = myArray(arrX) Then
With shpGreenLight(arrX)
.Visible = True
.BackColor = &HC000&
.FillColor = &HC000&
End With
Else
With shpGreenLight(arrX)
.Visible = True
.BackColor = &HFF&
.FillColor = &HFF&
End With
'need to do something here
Exit Sub
End If
Next
If n = intfileLen Then
Close #1
End If
doCheckCards
End Sub
Any clues?!
Cheers
Last edited by thebloke; Mar 31st, 2004 at 09:06 AM.
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Mar 31st, 2004, 07:11 AM
#2
Why don't you read in the entire file at the start, into an array or whatever. Then you can just compare the values in each array, instead of worrying about going back through the file.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 31st, 2004, 07:15 AM
#3
Thread Starter
Hyperactive Member
Yeah, kinda thinking that way, the thing I'm having a problem getting my head around is that there are 5 items in myArray whereas there are multiples of 5 in the Input file, if you get my drift. If I read the whole file in then I may have 15 values in one array and 5 in another. I'm going to tie my brain up in knots.
I'm pretty sure that it's really quite simple but my head is beginning to hurt!
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Mar 31st, 2004, 07:27 AM
#4
Frenzied Member
what if you open it for Random rather than Input and use Seek?
-
Mar 31st, 2004, 07:31 AM
#5
Thread Starter
Hyperactive Member
Ooh, now you're confusing me (not hard! ha ha).
Learning on my feet here, any example would be super.
What I've just done is read the infile into an array as suggested. Still, an example of using random and seek would be good!
Last edited by thebloke; Mar 31st, 2004 at 07:34 AM.
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Mar 31st, 2004, 08:51 AM
#6
Thread Starter
Hyperactive Member
Ok, now I'm going daft. Take a look at this:
nb. infilearray() is declared in the general declarations
VB Code:
Private Sub Form_Load()
lblcustname.Caption = strcustomer
Open strinfile For Input As #1
intfileLen = 0
Do While Not EOF(1)
Input #1, LineIn
ReDim infilearray(intfileLen)
infilearray(intfileLen) = LineIn
MsgBox infilearray(intfileLen) 'correct value contained...
intfileLen = intfileLen + 1
Loop
intfileLen = (intfileLen / 5)
lblboxno.Caption = intfileLen
Close #1
MsgBox infilearray(0) 'empty...
End Sub
Between the code exiting the loop, closing the input file and the final msgbox, the array values disappear.
Any ideas why?
Cheers
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
-
Mar 31st, 2004, 09:08 AM
#7
Thread Starter
Hyperactive Member
Ah, good old ReDim Preserve eh?
The Bloke
www.blokeinthekitchen.com
making cooking cool for blokes
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|