Results 1 to 7 of 7

Thread: Stepping backward using Input #n[resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    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:
    1. Private Sub cmdCompare_Click()
    2. Dim arrX As Integer
    3.  
    4. cmdCompare.Enabled = False
    5.  
    6. If n = 0 Then n = 1
    7.  
    8.  
    9. If n = 1 Then
    10.     Open strinfile For Input As #1
    11. End If
    12.  
    13.         For arrX = 0 To UBound(myArray)
    14.        
    15.         Input #1, LineIn
    16.        
    17.             If LineIn = myArray(arrX) Then
    18.                 With shpGreenLight(arrX)
    19.                     .Visible = True
    20.                     .BackColor = &HC000&
    21.                     .FillColor = &HC000&
    22.                 End With
    23.             Else
    24.                 With shpGreenLight(arrX)
    25.                     .Visible = True
    26.                     .BackColor = &HFF&
    27.                     .FillColor = &HFF&
    28.                 End With
    29.                 'need to do something here
    30.                 Exit Sub
    31.             End If
    32.                
    33.         Next
    34.  
    35. If n = intfileLen Then
    36.     Close #1
    37. End If
    38.  
    39.     doCheckCards
    40.  
    41. 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

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    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

  4. #4
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    what if you open it for Random rather than Input and use Seek?

  5. #5

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    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

  6. #6

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    Ok, now I'm going daft. Take a look at this:

    nb. infilearray() is declared in the general declarations

    VB Code:
    1. Private Sub Form_Load()
    2.    
    3.     lblcustname.Caption = strcustomer
    4.     Open strinfile For Input As #1
    5.    
    6.     intfileLen = 0
    7.         Do While Not EOF(1)
    8.    
    9.             Input #1, LineIn
    10.            
    11.             ReDim infilearray(intfileLen)
    12.  
    13.             infilearray(intfileLen) = LineIn
    14.            
    15.             MsgBox infilearray(intfileLen) 'correct value contained...
    16.            
    17.             intfileLen = intfileLen + 1
    18.        
    19.         Loop
    20.    
    21.         intfileLen = (intfileLen / 5)
    22.    
    23.         lblboxno.Caption = intfileLen
    24.  
    25.         Close #1
    26.        
    27.         MsgBox infilearray(0) 'empty...
    28. 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

  7. #7

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358
    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
  •  



Click Here to Expand Forum to Full Width