Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

declare a variable 1

Status
Not open for further replies.

aarellano

MIS
Oct 22, 2007
168
US
Hello,

I have a couple of declared variables
Code:
mo= rs("month")
dy= rs("day")
dpt= rs("dptno")
tbc= rs("tbcod")
runlab = rs("runlabor")
what I am trying to do now is to declare a new variable
with an if statement
I have tried
Code:
hrs = if tbc= 3 then runlab/1000 elseif tbc=4 then runlab/10000 elseif tbc="P" then 1/runlab end if
but that gives me an error
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/myfile.asp, line 54, column 6
hrs = if tbc= 3 then runlab/1000 elseif tbc=4 then runlab/10000 elseif tbc="P" then 1/runlab end if
-----^

any help is greatly appreciated!!!!!
 
try this:

Code:
if tbc= 3 then 
    hrs = runlab/1000 
elseif tbc=4 then 
    hrs = runlab/10000 
elseif tbc="P" then 
    hrs = 1/runlab 
end if


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
thank you that works pretty well the only problem that I have is
Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/xmldata/empeff.asp, line 58, column 11
elseif tbc=&"P"& then
----------^

I believe is because an alpha character?
 
I believe is because an alpha character?

That's probably true.

Instead, you could try....

Code:
if tbc= "3" then
    hrs = runlab/1000
elseif tbc="4" then
    hrs = runlab/10000
elseif tbc="P" then
    hrs = 1/runlab
end if

This actually leads to one of my biggest gripes about ASP. I can't stand that every variable is a variant data type. I would much rather be able to set real data types.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I hear you, can be a bit confusing at times.

Now I get
Code:
Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
myfile.asp, line 61
lines 56 through 62
Code:
56 if tbc= "3" then
57    hrs = runlab/1000
58 elseif tbc="4" then
59    hrs = runlab/10000
60 elseif tbc="P" then
61    hrs = 1/runlab
62 end if
 
got it

Code:
if tbc= "'3'" then
    hrs = runlab/1000
elseif tbc="'4'" then
    hrs = runlab/10000
elseif tbc="'P'" then
    hrs = 1/runlab
end if
 
no sorry that did not work my asp page load but I get no data in the hrs field
 
This actually leads to one of my biggest gripes about ASP. I can't stand that every variable is a variant data type. I would much rather be able to set real data types.

A. What do you normally program in?


A general good rule of thumb (which I always try to use) is to use a prefix for variables that define the type - that way, these type of issues can be avoided more often than not.

Instead of:

firstName = "Bob"
use
strFirstName = "Bob"

or
age = "30" or age = 30
use
strAge = "30" or intAge = 30 or fltAge = 30 ...etc



--------
GOOGLE is a great resource to find answers to questions like "how do i..."

If you don't know exaclty what you want to do or what to search on, try Google Suggest: --------
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javasc
 
so in my case it would be

Code:
if tbc= "'3'" then
    strhrs = runlab/1000
elseif tbc="'4'" then
    strhrs = runlab/10000
elseif tbc="'P'" then
    strhrs = 1/runlab
end if
 
I do most of my programming in VB6 and T-SQL. I know that VB6 "can" have variants, but I never use them.

Try this:

Code:
if tbc= "3" then
    hrs = cDbl(runlab)/1000
elseif tbc="4" then
    hrs = cDbl(runlab)/10000
elseif tbc="P" then
    If cDbl(runlab) = 0 Then
       hrs = 0
    Else
       hrs = 1/cDbl(runlab)
    End If
end if

Notice that I am converting the runlab variable to the double data type. This will work as long as the runlab variable CAN be converted to a double. If runlab = "Seven" you will have problems with this code. Also note that I added a 0 check to prevent a possible divide by zero error. If I had to guess, I would say that the runlab variable is actually a string data type. In fact, it may be best to do this....

Code:
If IsNumeric(runlab) Then
  if tbc= "3" then
    hrs = cDbl(runlab)/1000
  elseif tbc="4" then
    hrs = cDbl(runlab)/10000
  elseif tbc="P" then
    If cDbl(runlab) = 0 Then
       hrs = 0
    Else
       hrs = 1/cDbl(runlab)
    End If
  end if
Else
  Response.Write "There is a problem with the runlab variable"
End If


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
gmmastros!!!!!!!!!

I don't care what anybody says!!!! YOU ROCK!!!!

I ended up using your code
Code:
if tbc= "3" then
    hrs = cDbl(runlab)/1000
elseif tbc="4" then
    hrs = cDbl(runlab)/10000
elseif tbc="P" then
    If cDbl(runlab) = 0 Then
       hrs = 0
    Else
       hrs = 1/cDbl(runlab)
    End If
end if

Thank you!! yet Again!!!
 
I don't care what anybody says!!!!

Really? What are they saying? Who are "they"? [wink]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top