//flex table opened by JP

Click to See Complete Forum and Search --> : Any VB programmers here? HELP!


narayan
03-10-2001, 06:50 PM
I have this school project that I've been fooling with for several hours now, mostly just reading our crappy book and trying to understand Random Access Files. But, I just don't get it, the book is rather vague. I need to create and access a file that keeps a record of a person's first name, last name, etc......... I'm stumped. Can someone help?

And another thing, I don't get the "option explicit" statement.

(it's a good thing this isn't my major! http://www.sysopt.com/forum/wink.gif)


[This message has been edited by narayan (edited 03-10-2001).]

Lebo
03-10-2001, 07:47 PM
I am just getting into VBA at the moment and although I can't help you with the Random Access Files I may be able to explain "Option Explicit"

What option explicit does is force you to define (give a value to) all variables that you have declared. Option explicit is the first thing that you enter in you project.

Option Explicit
Dim mystr as String 'This declares a variable "mystr" as a string of text

If later in your code you try to use this variable without having declared a value for it the code will not run. I think it comes up with a compile error. You must at some stage in the code say something like

mystr = "How are you?" 'If you do this you will be fine

If you don't include Option Explicit the code will run and you will have difficulty tracking down the problem, especially if you have declared several variables and the code is lenghty.

As I say I am a bigginer as far as VBA is concerned so I hope you can follow my explanation.

captpete
03-10-2001, 09:12 PM
Just a note to clarify the Option Explicit statement. When this statement is in your program/procedure it requires you to declare the variable type that you want to assign to a variable. A variable assigns a location in memory of a specific size reserved for that variable. If you do not assign a type to a variable, it is by default a variant type. A variant variable can be 16 to 23 bytes in size, whereas a string variable is 10 bytes, an integer is 2, a single is 4 and so on. Thus by declaring your variables, you reduce the size of your program, saving space in memory.

A random access file is a data file, like an Excel spread sheet for instance, where you can access any particular record (any row in Excel, or any line in a text file) at will. Thus you can go to the 3rd record or 15th, etc. Whereas in a sequential data file, you start with the first line or record and proceed from there until you reach the end of the file; you can not skip lines (records).

Check this site for learning VB: http://www.kather.net/VisualBasicSource/

It's a gold mine.

Lebo
03-10-2001, 10:28 PM
Thanks for that link, I for one will be following it.

narayan
03-11-2001, 03:14 PM
Thanks for clearing up the Option Explicit thing, I understand it now. The books we are using have a tutorial in them, and the instructions for coding are very specific to what the tutorial is in the book, so there is a little confusion as to what is specific to the tutorial, and what is not.

I understand what the random access file is, but I am not understanding how to code it. I'll see what's at the other end of the link. Thanks http://www.sysopt.com/forum/smile.gif

gyoung
03-12-2001, 05:09 AM
About Random File Access, just do a search for "Random File Access" in VB help and it should give you examples.

captpete is correct about the purpose of random file access and since you understand the point of it, all you have to do to code for it is define what a record looks like (use the Type function). Then use the reserved functions: Put, Get, and Open.

Another note, be careful of the Variant datatype. It is going away with Visual Studio .Net.

Also using the Option Explicit statement forces you to define your variables, making your code much easier to read for the next guy!

voogru
03-12-2001, 08:49 AM
I have VB6 but i cant figure out how too use it http://www.sysopt.com/forum/frown.gif

How do i make a button do sumthing other than press down?

i can make the layout and all BUT i cant make the prog do beans its all just cosmetic things that i can do.

at least its fools my friends that i made a prog! http://www.sysopt.com/forum/wink.gif

-voogru

gyoung
03-12-2001, 10:09 AM
voogru,

You should take a look at the help. VB is an event oriented langauge. To code for a button click you need to write code within the cmdButton_Click event. What code you write is up to you! http://www.sysopt.com/forum/smile.gif