Solved

need help on a search prog

Posted on 2002-04-28
4
146 Views
Last Modified: 2012-05-08
My prog is simple. I need someone to correct the following code. I have a great number of invoives with data such as invoice #, date, amount.etc.
I need code to retrieve by invoice#.

here is the code that WON'T work!


inv2 = Form4.Text1.Text

Dim inv As String * 8
Dim ddate As String * 9
Dim amt As String * 7
Dim amt5 As String * 7
Dim deal As String * 20
Dim paid As String * 3

Open "C:\invoice\dollar.dat" For Input As #1
X1% = 0
Do While (Not EOF(1))
    Input #1, inv, ddate, amt, amt5, deal, paid
     If inv = inv2 Then
         hit$ = "yes"
         MsgBox "Found it", , ib
     Exit Do
     Else
     X1% = X1% + 1
            'nd If
'Loop
If hit$ = "no" Then
MsgBox "invoice not found", , ib
Max% = X1%
End If
    X1% = X1% + 1
   
'oop
'Max% = X1%
'lose 1
'Open "C:\invoice\dollar.dat" For Input As #3
'X1% = 0
'Do While (Not EOF(1))
   ' Input #1, inv, ddate, amt, amt5, deal, paid
        ' If inv = inv2 Then
        ' hit$ = "yes"
        ' MsgBox "Found it", , ib
   ' Exit Do
   ' Else
        X1% = X1% + 1
            End If
Loop
If hit$ = "no" Then
MsgBox "invoice not found", , ib
Max% = X1%
End If

Form4.Visible = False
Form3.Visible = True
Form3.Text1.Text = inv
End Sub


I am using vb4
0
Comment
Question by:hjaycox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 6976194
I've removed the comments and indented for clarity:

Open "C:\invoice\dollar.dat" For Input As #1
X1% = 0

Do While (Not EOF(1))
  Input #1, inv, ddate, amt, amt5, deal, paid
  If inv = inv2 Then
    hit$ = "yes"
    MsgBox "Found it", , ib
    Exit Do
  Else
    X1% = X1% + 1

    If hit$ = "no" Then
      MsgBox "invoice not found", , ib
      Max% = X1%
    End If
    X1% = X1% + 1
   
    X1% = X1% + 1
  End If

Loop

If hit$ = "no" Then
  MsgBox "invoice not found", , ib
  Max% = X1%
End If

===============================================
Comments and questions:

1. you are incrementing X1% too many times
2. what is the ib variable used in msgbox statement?
3. you should initialize hit$ = "no" before you start looping.
4. look at the data and type the inventory number of the first record.  Set a breakpoint in this code and step through it, inspecting the inv value after the Input statement and the inv2 variable.
0
 
LVL 3

Accepted Solution

by:
n_narayanan earned 200 total points
ID: 6976703
Try this,
din inv2 as string * 8
inv2 = left(trim(Form4.Text1.Text),8)
'Make sure that you have set the text1.maxlength
'property to 8
Dim inv As String * 8
Dim ddate As String * 9
Dim amt As String * 7
Dim amt5 As String * 7
Dim deal As String * 20
Dim paid As String * 3
dim hit as string

hit$="no"

Open "C:\invoice\dollar.dat" For Input As #1
X1% = 0
Do While (Not EOF(1))
   Input #1, inv, ddate, amt, amt5, deal, paid
   if eof(1) then
      exit do
   end if
    If trim(inv) = inv2 Then
        hit$ = "yes"
        MsgBox "Invoice Found"
        Exit Do
    Else
        X1% = X1% + 1
    End If
Loop

If hit$ = "no" Then
   MsgBox "invoice not found"
   Max% = X1%
End If
Form4.Visible = False
Form3.Visible = True
Form3.Text1.Text = inv
End Sub

Cheers

Narayanan
0
 
LVL 45

Expert Comment

by:aikimark
ID: 6976946
I guess I should have asked you:

1. Do you really need the fixed lengths on your string variables?
2. Is your file comma-delimited or are you incorrectly trying to do record I/O with an input statement instead of a Get statement?

The answer to 2 will be determined by my diagnostic steps.
0
 

Author Comment

by:hjaycox
ID: 6979152
had to change one code line
if trim(inv)= inv2 then  to  if inv = inv2 and it works

thanks

look for my next question on the same prog
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question