Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Random File and VB

Posted on 1998-07-16
10
Medium Priority
?
201 Views
Last Modified: 2010-05-03
I am trying to write a small check program.  I want it to request information (payee, check number, and amount) for each check and store this
information in a random file. I need it to display the information for a check by reading the file when
user input a check number. And I would like the program to dislplay the total amount of all issued checks after every transaction.

Any ideas?
Thanks
0
Comment
Question by:dhill10358
[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
10 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1465989
Considering the ease of using databases with VB, I would suggest you use a database instead of a random access file.
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1465990
The essential method for doing this lies in the fundamental FIle I/O provided with VB, which came along relatively unchanged from Quick  Basic and Professional basic.  Generally, your random file is a fixed length record file.  You can create it by writing records to it sequentially, of by using binary file i/o (open "myfile" for binary as #1, etc).  The only trick is placing the relative record number of the record written into your related record.  Then when you read through your related (master) records you do the following to get your random related record:

dim x$, pos as long, relrec as long, lrecl as integer
'prelims
Open "RandomFileName" for binary as #1
lrecl=320  'whatever your fixed length is for each record
x$=space$(lrecl) ' make buffer

'then to get a record
relrec= <relative record pointer value from master record>
'in one statement
get #1,((relrec-1)*lrecl)+1,x$

'or seprate seek
 seek #1,((relrec-1)*lrecl)+1
 get #1,,x$

'your random record is in x$.  TO get bunches, read down through your master, reading all related random records & summing? whatever you want.

This is a very fast method and quite useable if your random file does not have a lot of update activity (deletes, etc), otherwise you need more sophisticated processes to preserve file space over time.

Of course, you could always use a database.  

And, if you are trying to write your own version of Quicken (that's what it sounds like from your question) you really need to get into methods of indexing and handling deleted records, etc.   In this case, a real database will save you a lot of grief.
0
 

Author Comment

by:dhill10358
ID: 1465991
I don't need anything complex like quicken, ect.  I just need a very basic program that will request information (payee, check number, and amount) for each check and display the information when I input the check number.  Also I want it to total the number of all checks when I input the check number.

I am new to VB.  I use Access97. Random files are new to me.  I am talking about maybe 5 to 10 checks.  I need to see an example so I can learn how to do this.  If I can get this example, I will apply it to other projects.

thanks,





 
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:HenryChanE
ID: 1465992
Pls. put the code below into approiate position:

1) Declare your field in a module (*.BAS) :
   Type MyCheck
     Payee as String * X (X=Max. len. for this field)
     Chk_No as Long
     Amount as Currency
   End Type

2) Declare the variables in your form :
   Dim gMyCheck as MyCheck
   Dim MaxRec as Long
   Dim TotAmt as Currency
   Dim I as Long  

3) To open your file:
   Open "Filename" For Random As #1 Len=(X+4+8)
   MaxRec=FileLen("Filename") / Len(X+4+8)

4) To search and display record:
   For I = 1 to MaxRec
     Get #1,I, gMyCheck
     If gMyCheck.Chk_No = (Check No you want to display) then
       ControlA.text= gMyCheck.Payee
       ControlB.text= gMyCheck.Amount
       Exit For
     End If
   Next I

5) To add your record:
       gMyCheck.Payee = ControlA.text
       gMyCheck.Amount = CCur(ControlB.text)
       gMyCheck.Chk_No = CLng(ControlC.text)
       Put #1,MaxRec+ 1, gMyCheck
       MaxRec =MaxRec + 1

6) To sum the amount:
   TotAmt=0
   For I = 1 to MaxRec
     Get #1,I, gMyCheck
     TotAmt= TotAmt +gMyCheck.Amount
   Next I
   ControlD.text=TotAmt

Remember to close to file using Close #1 after use.
0
 

Author Comment

by:dhill10358
ID: 1465993
Henry,

Thank you for you response.  I am getting error messages.  such as "invalid outside procedure".  VB is new to me.  If you can be so kind, would you edit the code you gave me so it works as close as possible to the directions listed in my description?  I have tried to fix it myself, but I don't know what I am doing.  


Thank you
0
 

Author Comment

by:dhill10358
ID: 1465994
Adjusted points to 125
0
 
LVL 1

Expert Comment

by:HenryChanE
ID: 1465995
It's not easy to write a complete list of code inside this text box. Can you post your e-mail so that I can send the source code to you directly ?
0
 
LVL 2

Expert Comment

by:seahpc
ID: 1465996
try this :
' text1 = Payee
' text2 = CheckNumber
' text3 = Amount

'********************************
'This will write teh record into a file
'Each field are delimted by a comma
'********************************
Open FileName for append as #1
   Print #1, text1 & "," & text2 & "," & text3
Close #1

' text4 = CheckNumberForSearch
open FileName for input as #1
do until eof(1)
  line input #1, record
  if instr(1,record,text4.text) then
           msgbox record
  end if
loop
Close #1
0
 

Author Comment

by:dhill10358
ID: 1465997
My Email Address is Dhill10358@aol.com.   If you send me the code, please make sure you lock the question, so I can give you credit for it.

thanks,

David
0
 

Accepted Solution

by:
HenryChan earned 560 total points
ID: 1465998
David,
  I've sent the code to you, it's written in VB4-32bit. It shows the most important feature for radom access file, you should modify the code for a real apps..

Henry
 

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 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