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!

Can you tell me what is wrong with this statement 1

Status
Not open for further replies.

kiwieur

Technical User
Apr 25, 2006
200
GB
Hi,

I am trying to use this code

Code:
<%
Dim CStock = 0
Dim OStock=0
Dim Stock = 0
%>

However I keep getting this error message


Microsoft VBScript compilation error '800a0401'

Expected end of statement

/Sales/AllocatedStockBySpec.asp, line 88

Dim CStock = 0
-----------^

Could someone please explain what I am doing wrong


Regards

Paul

 
Declaration and assignment are in separate statements in VBScript.

Dim CStock
Dim OStock
Dim Stock

CStock = 0
OStock = 0
Stock = 0
 
guitarzan,

thanks for the quick reply and help

Regards

Paul

 
guitarzan,

A little bit more help if you dont mind please

I changed my code to this as suggested

Code:
 <%
Dim CStock
Dim OStock
Dim Stock
Dim SType

CStock = Recordset1.Fields.Item("TotalStock").Value
OStock = RSallocate.Fields.Item("QtyOrdered").Value
SType = "Call Off" 
%>

And that is OK now however I also added this code to try and add a calculation to another column to my output.

Code:
  <% 
While ((Repeat1__numRows <> 0) AND (NOT RSallocate.EOF)) 
%>
<%
If RSallocate.Fields.Item("OrderType").Value = SType Then
[b][red]Stock = CStock - OStock[/red][/b]
else
Stock = CStock + OStock
end if
%>
    <tr><td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("spec_number").Value)%></font></div></td>
      <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("customer_name").Value)%></font></div></td>
    <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("date_ordered").Value)%></font></div></td>
    <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("due_date").Value)%></font></div></td>
    <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("QtyOrdered").Value)%></font></div></td>
    <td><div align="center"><font size="2" face="Arial, Helvetica, sans-serif"><%=(RSallocate.Fields.Item("OrderType").Value)%></font></div></td>
    <td><%=Stock%></td>
    </tr>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RSallocate.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
RSallocate.Close()
Set RSallocate = Nothing
%>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

however i now get this error message

Microsoft VBScript runtime error '800a000d'
Type mismatch

/Sales/AllocatedStockBySpec.asp, line 102

[red]I have highlighted row 102 in bold red text[/red]

any help you can give me is much appreciated

Regards

Paul

 
All variables in VBScript are variants, but they have subtypes based on the datatype of the value being assigned to them. If your database fields are text fields, then the variables will be variants of subtype "string", and you cannot perform arithmetic on them.

You have to use conversion functions to coax your data into the appropriate datatype, such as CLng() (which convert values to long), CInt() (which converts values to Integer), etc.

There is also a function called IsNumeric(), which will return true or false based on whether the string data is actually numeric or not.


If you know your database fields are numeric strings, this should work:
Stock = CLng(CStock) - CLng(OStock)
 
guitarzan ,

Thank you, the code you gave me works great

Regards

Paul

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top