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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WTF is wrong w/ this code...it''s driving me NUTZ!

Status
Not open for further replies.

frogjumps

IS-IT--Management
Aug 10, 2001
14
0
0
US
HELP.... I cannot get this to work..wtf am I doing wrong?

<code snip>

Dim iLastRMA
Dim sLastRMA

'** get iLastRMA from the database

iLastRMA = rsLastRMAnum_last

'** trim all the alpha characters from the returned value

'** ie.. 020102AH1 trimmed to &quot;1&quot;

iLastRMA = mid(iLastRMA, 8)

'** convert the string to an int and add &quot;1&quot; to the value

sLastRMA = CStr(CInt(iLastRMA + 1))

</code snip>

I keep getting VBScript runtime error:

Type mismatch: '[string: &quot;&quot;]'

What am I doing wrong.....

FrOg 8) FrOg 8)
 
frogjumps,

iLastRMA = &quot;020102AH1&quot;
iLastRMA = mid(iLastRMA, 8)
msgbox iLastRMA

returns &quot;H1&quot;

fengshui_1998
 
also, i think you need to convert to numeric BEFORE you increment by 1:

'** convert the string to an int and add &quot;1&quot; to the value

sLastRMA = CStr(CInt(iLastRMA) + 1)
 
Here's the CODE I have got so far:

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;../../Connections/rma.asp&quot; -->
<%
set rsLastRMAnum = Server.CreateObject(&quot;ADODB.Recordset&quot;)

rsLastRMAnum.Source = &quot;SELECT RMAnum FROM RMA_Entry&quot;

rsLastRMAnum.Open()

Dim iLastRMA
Dim sLastRMA

'** get iLastRMA from the database

rs.Movelast
iLastRMA = rs(&quot;RMAnum_last&quot;)
iLastRMA = mid(iLastRMA, 9)
sLastRMA = CStr(CInt(iLastRMA + 1))

I am at a LOSS...

FrOg 8) FrOg 8)
 
unless you have another recordset that you're not showing, you need to access the same recordset that you created in your code. and the only field you selected in that recordset is RMAnum, so you have to use the same field name. unless, as i said, there's more code that you aren't displaying....


try these changes:

'** get iLastRMA from the database

rsLastRMAnum.Movelast
iLastRMA = rsLastRMAnum(&quot;RMAnum&quot;)
iLastRMA = mid(iLastRMA, 9)
sLastRMA = CStr(CInt(iLastRMA) + 1)

if that doesn't work, what is/is not happening, or what errors are you receiving?
 
Here is ALL my code: It only returns the value of &quot;1&quot;, it never adds &quot;1&quot; to the returned value. I can have the number 20 returned but it will not add 1 to it..!!???

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;../../Connections/rma.asp&quot; -->
<%
set rsLastRMAnum = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rsLastRMAnum.ActiveConnection = MM_rma_STRING
rsLastRMAnum.Source = &quot;SELECT RMAnum FROM RMA_Entry&quot;
rsLastRMAnum.CursorType = 3
rsLastRMAnum.CursorLocation = 2
rsLastRMAnum.LockType = 3
rsLastRMAnum.Open()
rsLastRMAnum_numRows = 0
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables

' set the record count
rsLastRMAnum_total = rsLastRMAnum.RecordCount

' set the number of rows displayed on this page
If (rsLastRMAnum_numRows < 0) Then
rsLastRMAnum_numRows = rsLastRMAnum_total
Elseif (rsLastRMAnum_numRows = 0) Then
rsLastRMAnum_numRows = 1
End If

' set the first and last displayed record
rsLastRMAnum_first = 1
rsLastRMAnum_last = rsLastRMAnum_first + rsLastRMAnum_numRows - 1

' if we have the correct record count, check the other stats
If (rsLastRMAnum_total <> -1) Then
If (rsLastRMAnum_first > rsLastRMAnum_total) Then rsLastRMAnum_first = rsLastRMAnum_total
If (rsLastRMAnum_last > rsLastRMAnum_total) Then rsLastRMAnum_last = rsLastRMAnum_total
If (rsLastRMAnum_numRows > rsLastRMAnum_total) Then rsLastRMAnum_numRows = rsLastRMAnum_total
End If
%>

<%
' *** Recordset Stats: if we don't know the record count, manually count them

If (rsLastRMAnum_total = -1) Then

' count the total records by iterating through the recordset
rsLastRMAnum_total=0
While (Not rsLastRMAnum.EOF)
rsLastRMAnum_total = rsLastRMAnum_total + 1
rsLastRMAnum.MoveNext
Wend

' reset the cursor to the beginning
If (rsLastRMAnum.CursorType > 0) Then
rsLastRMAnum.MoveFirst
Else
rsLastRMAnum.Requery
End If

' set the number of rows displayed on this page
If (rsLastRMAnum_numRows < 0 Or rsLastRMAnum_numRows > rsLastRMAnum_total) Then
rsLastRMAnum_numRows = rsLastRMAnum_total
End If

' set the first and last displayed record
rsLastRMAnum_first = 1
rsLastRMAnum_last = rsLastRMAnum_first + rsLastRMAnum_numRows - 1
If (rsLastRMAnum_first > rsLastRMAnum_total) Then rsLastRMAnum_first = rsLastRMAnum_total
If (rsLastRMAnum_last > rsLastRMAnum_total) Then rsLastRMAnum_last = rsLastRMAnum_total

End If
%>

<%

Dim iLastRMA
Dim sLastRMA

'** get iLastRMA from the database

rsLastRMAnum.Movelast
iLastRMA = CStr(rsLastRMAnum(&quot;RMAnum&quot;))
iLastRMA = Mid(iLastRMA, 9)
sLastRMA = CStr(CInt(iLastRMA) + 1)

%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
<input type=&quot;text&quot; name=&quot;textfield&quot; value=&quot;<%=iLastRMA%>&quot;>
</form>
</body>
</html>
<%
rsLastRMAnum.Close()
%> FrOg 8)
 
your result ends up in sLastRMA, but you set the value of your formfield to iLastRMA.......

try changing

<input type=&quot;text&quot; name=&quot;textfield&quot; value=&quot;<%=iLastRMA%>&quot;>

to

<input type=&quot;text&quot; name=&quot;textfield&quot; value=&quot;<%=sLastRMA%>&quot;>

if you still have problems, start adding

response.write &quot;iLastRMA = &quot; & iLastRMA & &quot;<br>&quot;

(and response.write other variable fields also) to determine what the value of each of the fields are at certain points in your process..... great t-shooting tool.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top