473,472 Members | 2,155 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding 2 variables together

12 New Member
Hi

I am trying to add 2 variables together but I think the computer see's the numbers as a string instead of an integer.

I have looked for help with this but all I can see is ASP doesn't allow the user to define a variable as an int or a string

My code is very simple (I hope). I retrieve a 4 digit code from my database which I call var_Pin. I then split it to var_LowPin and var_HighPin and I think it is at this point the computer sees the number as a string instead of an integer.

I have added ***** beside the line that is also partly the fault. If I change var_HighPin to a number (eg) 20, it works fine.

<%
dim var_Pin
var_Pin = (rsSampleRequest.Fields.Item("PinsPerRow").Value)
dim var_LowPin
var_LowPin = (Left(var_Pin,2))
dim var_HighPin
var_HighPin = (Right(var_Pin,2))
dim var_CurrentPin
var_CurrentPin = var_LowPin

Do While var_CurrentPin < var_HighPin *****
response.Write(var_CurrentPin)
var_CurrentPin = var_CurrentPin + 1
Loop
%>

Any ideas?

Thank you

Dave
Mar 7 '08 #1
4 3638
idsanjeev
241 New Member
Hi begoddendave
you are getting any error
if you have problems to read data as interger then you can do it with vbscripts function

Tips

but your question is over to my head need more clearity.
thanks
Mar 7 '08 #2
DrBunchman
979 Recognized Expert Contributor
Hi Dave,

If you call the CInt(var) function on your variables like so:

var_LowPin = CInt(Left(var_Pin,2))

It will cast them to integers if possible.

Hope this helps,

Dr B
Mar 7 '08 #3
begoddendave
12 New Member
Dr B

THANK YOUUUUUUU

That is perfect. It has worked. I am going to look up what the CInt actually does as I didn't think 'one' could define integers in ASP

Thank you again


Dave
Mar 7 '08 #4
DrBunchman
979 Recognized Expert Contributor
My pleasure.

In VBScript all variables are variants which means that at any point in the code they can be of one type or another. Although you can't explicitly define a variable as an integer, string or whatever they are implicitly defined by the values you assign to them or the actions you take on them.

So saying x = 1 makes x an integer but saying x = "Hello" makes x a string.

This is why you can cast from one data type to another as long as the value stored in the variable allows it.

I'm sure you'll find a clearer and more thorough explanation via the magic of google.

Happy coding,

Dr B
Mar 7 '08 #5

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

Similar topics

3
by: Brian Dumas | last post by:
I would like to do something like the following class TMyClass { ...... } TMyClass* mc1 = new TMyClass; TMyClass* mc2 = new TMyClass; TMyClass* mc3=mc1+mc2;
6
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
2
by: Paul M | last post by:
Hi, This is on an AS/400 which can be a little strange but I think the basic question is portable. I have a (non-C) program that needs to make series of calls to some C programs/functions....
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
5
by: Troy | last post by:
Hello, I have a dumb question. I have two array objects of type double with 12 elements in each object. I'd like to add the two objects but dont know how to. Any ideas? thanks
6
by: Hareth | last post by:
Scenerio: label1.text = 0 textbox1.text = 0 textbox2.text = textbox1.text + label1.text It turns out it isnt adding the numbers, it attaches the new number next to the old number
6
by: Mangler | last post by:
Say I have to different recordsets that have the fields: rsA.Fields.Item("A").Value ,rsB.Fields.Item("B").Value How would I add those to fields? It may be my inexperience but when I tried...
6
by: santiago | last post by:
I guess one cannot do this: arraytot = arraytot + arraydet; So, what's the trick to adding arrays like this? Thanks.
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
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...
0
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...
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
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...
1
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...
0
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.