473,396 Members | 1,918 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,396 software developers and data experts.

When to use integer, when to use string?

I've heard it said that you only want to use a number (e.g. integer, long, etc.)
if you are going to do calculations or some kind of math with it. Is this true?
For example, I run a validate routine that checks an address entry - if
something's missing in the entry, the code does different things based on what
is missing, indicated my a 2 or a 3 - integer values. Should I use string data
types here? Does it matter?

Public Sub Validate()
Dim fail As Integer
On Error GoTo HandleErr
fail = 1
If IsNull(Me!AddressDescription) Then fail = 2
If (IsNull(Me!AddressDescription) Or Me!AddressDescription = "Main") And _
IsNull(Me!Address1) And _
IsNull(Me!Address2) And _
IsNull(Me!Address3) And _
IsNull(Me!City) And _
IsNull(Me!State) And _
IsNull(Me!Zipcode) And _
IsNull(Me!Country) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub
Nov 12 '05 #1
5 1768
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Usually, numeric values process faster than strings.

In your code you have Fail = x. The question would be what are you
going to do with the final Fail value? Display to a user? What sense
will a number mean to a user? Use in a lookup of an error message?
Makes sense 'cuz of faster processing of numeric values - hopefully,
to find the error string for the error number (Fail value).

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQBGCTYechKqOuFEgEQKutACgwZC8x4rrgvR6iOIkyI6XG1 r8hXcAnAwR
CalVNm+9YyHBEAe793Wn+3As
=80Fw
-----END PGP SIGNATURE-----
deko wrote:
I've heard it said that you only want to use a number (e.g. integer, long, etc.)
if you are going to do calculations or some kind of math with it. Is this true?
For example, I run a validate routine that checks an address entry - if
something's missing in the entry, the code does different things based on what
is missing, indicated my a 2 or a 3 - integer values. Should I use string data
types here? Does it matter?

Public Sub Validate()
Dim fail As Integer
On Error GoTo HandleErr
fail = 1
If IsNull(Me!AddressDescription) Then fail = 2
If (IsNull(Me!AddressDescription) Or Me!AddressDescription = "Main") And _
IsNull(Me!Address1) And _
IsNull(Me!Address2) And _
IsNull(Me!Address3) And _
IsNull(Me!City) And _
IsNull(Me!State) And _
IsNull(Me!Zipcode) And _
IsNull(Me!Country) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub


Nov 12 '05 #2
Add on top of that lower memory overhead, smaller storage requirements and
the fact that most of the functions you'll come across and constants use
them in some way. Using strings primarily would require a whole lot of
conversions to accomplish most tasks.

Mike Storr
www.veraccess.com

"MGFoster" <me@privacy.com> wrote in message
news:jn*******************@newsread1.news.pas.eart hlink.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Usually, numeric values process faster than strings.

In your code you have Fail = x. The question would be what are you
going to do with the final Fail value? Display to a user? What sense
will a number mean to a user? Use in a lookup of an error message?
Makes sense 'cuz of faster processing of numeric values - hopefully,
to find the error string for the error number (Fail value).

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQBGCTYechKqOuFEgEQKutACgwZC8x4rrgvR6iOIkyI6XG1 r8hXcAnAwR
CalVNm+9YyHBEAe793Wn+3As
=80Fw
-----END PGP SIGNATURE-----
deko wrote:
I've heard it said that you only want to use a number (e.g. integer, long, etc.) if you are going to do calculations or some kind of math with it. Is this true? For example, I run a validate routine that checks an address entry - if
something's missing in the entry, the code does different things based on what is missing, indicated my a 2 or a 3 - integer values. Should I use string data types here? Does it matter?

Public Sub Validate()
Dim fail As Integer
On Error GoTo HandleErr
fail = 1
If IsNull(Me!AddressDescription) Then fail = 2
If (IsNull(Me!AddressDescription) Or Me!AddressDescription = "Main") And _ IsNull(Me!Address1) And _
IsNull(Me!Address2) And _
IsNull(Me!Address3) And _
IsNull(Me!City) And _
IsNull(Me!State) And _
IsNull(Me!Zipcode) And _
IsNull(Me!Country) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub

Nov 12 '05 #3
deko wrote:
I've heard it said that you only want to use a number (e.g. integer, long, etc.)
if you are going to do calculations or some kind of math with it. Is this true?
For example, I run a validate routine that checks an address entry - if
something's missing in the entry, the code does different things based on what
is missing, indicated my a 2 or a 3 - integer values. Should I use string data
types here? Does it matter?

Public Sub Validate()
Dim fail As Integer
On Error GoTo HandleErr
fail = 1
If IsNull(Me!AddressDescription) Then fail = 2
If (IsNull(Me!AddressDescription) Or Me!AddressDescription = "Main") And _
IsNull(Me!Address1) And _
IsNull(Me!Address2) And _
IsNull(Me!Address3) And _
IsNull(Me!City) And _
IsNull(Me!State) And _
IsNull(Me!Zipcode) And _
IsNull(Me!Country) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogErr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub


Are you referring to your flag FAIL? I so, I doubt it matters much more than am
gnat on a summer day.

Do you add phone numbers? No. Make it text
Do you add social security numbers? No. Make it text
Do you add zip codes? No. Make it text

Do you add the dollar amounts in a checkbook. Make it a number, usually currency.

However, as a flag? Who cares. Use common sense to determine the type of storage
value for a flag.


Nov 12 '05 #4
great... that's what I was curious about.

I find myself needing to pass a variable to other subs to indicates count,
yes/no, or some other condition... I will start using byte data type instead of
string.
Nov 12 '05 #5
Why don't you use constants and enums rather than

if this then
fail = 2
else
fail = 3
end if

'whatever else you want to return

'put in a class mode
Option Compare Database

Public Enum CustomersDataError
cdeCouldNotOpenConnection
cdeCouldNotOpenRecordset
cdeNoRecords
cdeCouldNotFindRecord
End Enum

Public Event CustomersError(error As CustomersDataError)
Public Function GetCustomerName(ByRef CustomerId As Long) As String

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

rs.Open "Customers", CurrentProject.Connection

rs.Filter = "Customerid = " & CustomerId

If rs.EOF Then
RaiseEvent CustomersError(CustomersDataError.cdeNoRecords)
End If
End Function

Not a perfect example but enums are easier to use and remember than
number like 2, 3 etc and less error prone to spelling mistakes like
string and will be picked up by the compiler if you are going out of
bounds. The are also displayed in the Intellisense to make matters
even sweeter.

Hit F2 in the code window and check out all the enums and how they are
used.

eg

Property Mode As ConnectModeEnum
Member of ADODB.Connection

Const adModeRead = 1
Member of ADODB.ConnectModeEnum

Enums can be very useful to make your code more readible and logically
organised IMO (anyone else got a differing opinion?)

Peter

"deko" <dj****@hotmail.com> wrote in message news:<JZ******************@newssvr27.news.prodigy. com>...
great... that's what I was curious about.

I find myself needing to pass a variable to other subs to indicates count,
yes/no, or some other condition... I will start using byte data type instead of
string.

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
1
by: Susan Bricker | last post by:
Greetings. I am trying to position opened forms so that they are cascaded on the screen. I have discovered the movesize action (for the DoCmd) and Move property of a form (for Acc 2002/2003). ...
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
1
by: Michael D. Reed | last post by:
I am using the help class to display a simple help file. I generated the help file using Word and saving it as a single page Web page (.mht extension). I show the help file with the following...
0
by: Alex | last post by:
my app was working fine in VB.NET 2003 (and framework 1.1). Now with VB.NET 2005 (framework 2.0) the uploading to an http server (ie. www.sharebigfile.com) stops with the error "The request was...
0
by: Neil | last post by:
I am trying shut down work stations that are left on over night. This works great when a user is logged in or the machine is locked but fails miserably when no body is using the work station, the...
1
by: =?Utf-8?B?RG9u?= | last post by:
Hello, I'm creating a web service that will allow people to enter their contact information into a SQL Server table. I get it to work when I enter all of the fields and press the invoke button,...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
9
by: weirdwoolly | last post by:
Hopefully someone will be able to help. I have written a stored procedure in C++ called from a Java test harness to validate the graphic data types in C++ and their use. I have declared the...
4
oll3i
by: oll3i | last post by:
public void wczytajPlik(String sciezka) throws FileNotFoundException { wczytaneDane.setText(""); BufferedReader br = new BufferedReader(new FileReader(sciezka)); String line = null; ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.