473,385 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Setting Data Types

31
I am a veteran of Access, but new to VBA. Why is it neccessary to to set data types, and do you need to do it always? I feel that if the info is already in a table or query, that it is already defined.

Thank you in advance.
Sep 9 '08 #1
2 1587
Stewart Ross
2,545 Expert Mod 2GB
Hi, and Welcome to Bytes!

It's possible to write books on data types, so in this answer I will just skim the surface a bit.

VBA is a programming environment which provides facilities not generally provided by the SQL-based database itself (sequential processing instead of set processing, loop processing, asynchoronous event generation and response for example).

VBA and the database engine are entirely separate, albeit complementary, systems, and work in entirely different ways. That the database engine has data stored in tables with particular types is really not known at all to VBA. Although the type of a database field can be determined by VBA, through querying the properties of the table definition concerned, this has no bearing on what you do with VBA.

Programming languages work by assigning space for variables in memory then processing these variables using a sequence of assignment and conditional statements. Unlike database fields, which persist in value after use through being stored in a physical medium such as a disk file, variables are volatile - created for the current code module and destroyed after use.

The use of types defines the range of values variables will accept, and the range of operations that the variable can participate in. Assigning types explicitly is a way of ensuring that programmers make fewer mistakes. Untyped variables (which are called Variants in VBA) have no protection whatsoever from incorrect usage - attempts to add boolean values as numbers, for example.

Languages which enforce the use of data types strictly are known as strongly-typed. VBA is not a strongly-typed language, because it does not of itself enforce data typing, although a compiler directive called Option Explicit will ensure that no variable can be used unless it is defined first (it still does not need to have an assigned type even so).

Typed variables are also much easier to understand when reading code, and are a useful aid for documenting what a routine does.

That's about all I can tell you at present without invoking texts on Software Engineering.

-Stewart
Sep 9 '08 #2
apank
31
Thank you very much for the quick and thorough reply. You really explained it well. You got me the answer that my Dummies book did not(though that has been helpful as well)
Sep 10 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Scott Kelley | last post by:
Is there a way to reset all elements of an array with a single instruction? I want to set all elements to zero. Currently looping to do so. thx, Scott Kelley
13
by: Shailesh Humbad | last post by:
I wrote a short page as a quick reference to c++ integer data types. Any feedback welcome: http://www.somacon.com/blog/page11.php
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
2
by: Jonathan Trevor | last post by:
Hi, For the last couple of releases of a product we're developing we've been running to very wierd behavior from IE and our ASP.NET web application which serves up various types of files and I'm...
8
by: Nils Magnus Englund | last post by:
Hi, I have a production, test and development environment for my web application and a web service (The test web application connects to the test web service, and so on). Is it possible to...
4
by: michael sorens | last post by:
I have successfully bound an XmlDocument to a DataGridView but all fields seem to be strings. I want to retrofit appropriate datatypes on some of the fields. Let me take this in 2 parts. Part...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
6
by: Spoon | last post by:
Hello everyone, Consider a class with many integer members. I want to set every bit in all members to 0 in the constructor. struct Foo { Foo() { memset(this, 0, sizeof *this); } int a, b,...
6
by: DippyDog | last post by:
This is an old old post that I'm referencing regarding what happens when you set an integer variable to Nothing. It gets set to zero, not "Nothing." ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.