473,786 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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!Addre ssDescription) Then fail = 2
If (IsNull(Me!Addr essDescription) Or Me!AddressDescr iption = "Main") And _
IsNull(Me!Addre ss1) And _
IsNull(Me!Addre ss2) And _
IsNull(Me!Addre ss3) And _
IsNull(Me!City) And _
IsNull(Me!State ) And _
IsNull(Me!Zipco de) And _
IsNull(Me!Count ry) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogE rr (Me.Form.Name)
Resume Exit_Here
End Select
End Sub
Nov 12 '05 #1
5 1795
-----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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQBGCTYechKq OuFEgEQKutACgwZ C8x4rrgvR6iOIky I6XG1r8hXcAnAwR
CalVNm+9YyHBEAe 793Wn+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!Addre ssDescription) Then fail = 2
If (IsNull(Me!Addr essDescription) Or Me!AddressDescr iption = "Main") And _
IsNull(Me!Addre ss1) And _
IsNull(Me!Addre ss2) And _
IsNull(Me!Addre ss3) And _
IsNull(Me!City) And _
IsNull(Me!State ) And _
IsNull(Me!Zipco de) And _
IsNull(Me!Count ry) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogE rr (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******** ***********@new sread1.news.pas .earthlink.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:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQBGCTYechKq OuFEgEQKutACgwZ C8x4rrgvR6iOIky I6XG1r8hXcAnAwR
CalVNm+9YyHBEAe 793Wn+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!Addre ssDescription) Then fail = 2
If (IsNull(Me!Addr essDescription) Or Me!AddressDescr iption = "Main") And _ IsNull(Me!Addre ss1) And _
IsNull(Me!Addre ss2) And _
IsNull(Me!Addre ss3) And _
IsNull(Me!City) And _
IsNull(Me!State ) And _
IsNull(Me!Zipco de) And _
IsNull(Me!Count ry) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogE rr (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!Addre ssDescription) Then fail = 2
If (IsNull(Me!Addr essDescription) Or Me!AddressDescr iption = "Main") And _
IsNull(Me!Addre ss1) And _
IsNull(Me!Addre ss2) And _
IsNull(Me!Addre ss3) And _
IsNull(Me!City) And _
IsNull(Me!State ) And _
IsNull(Me!Zipco de) And _
IsNull(Me!Count ry) _
Then fail = 3
Exit_Here:
Exit Sub
HandleErr:
Select Case Err.Number
Case Else
modHandler.LogE rr (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 CustomersDataEr ror
cdeCouldNotOpen Connection
cdeCouldNotOpen Recordset
cdeNoRecords
cdeCouldNotFind Record
End Enum

Public Event CustomersError( error As CustomersDataEr ror)
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( CustomersDataEr ror.cdeNoRecord s)
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.Connectio n

Const adModeRead = 1
Member of ADODB.ConnectMo deEnum

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******* ***********@new ssvr27.news.pro digy.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
3365
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 numarray, help gives unhelpful responses:
1
1981
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). However, if the application is opened up on different monitors (e.g.; 17" or 19"), the relative location of the opened form is not the same (i.e.; on the bigger monitor the opened form is too far over to the right and too high). What I want to...
18
4750
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 class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class instance. However, the 'indexof' is never calling my overloaded, overrides Equals method. Here is the...
1
1978
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 statement. Help.ShowHelp(Parent:=Me, url:=Me.HELP_URL_PRE & Me.myWorker.HelpFile) How do I get it to go away when the program exits? Now when I quit the program that I called it form the help file is sill displayed. Is there a way to get a handle...
0
7282
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 aborted: The request was canceled" after about 7 MB. For example, I might be uploading a 73MB file. After about 11% done the upload aborts. :shake: It works great for files < 5MB. I can upload those every time.
0
1325
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 programme starts but does not execute. The program below runs ok right down to shut down call then fails, any help will be gratefully received Imports System
1
2335
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, but if I leave one of the integer fields(ie StateID) empty if errors out. I tried to make the parameters optionally but it says thats not possible with a webmethod. How do you handle empty integer fields. I put the code below. Thanks
2
3389
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 checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
9
3877
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 vargraphic input parameters along the following lines in i_vargraphic100 vargraphic(100) and they are populated from String's in java.
4
1584
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; String rows_cols = null; try { line = br.readLine(); rows_cols = line.split("\\s+"); } catch (IOException e) {
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.