Groups | Blog | Home
all groups > sql server (alternate) > april 2005 >

sql server (alternate) : VBScrip Type Mismatch Error


mychevworld NO[at]SPAM yahoo.com
4/21/2005 11:02:37 AM
I'm getting a type mismatch error on the mid(strRecord,1,1)="H" line. I
used to do this all of the time, but I haven't done any VBScript for
awhile, so I'm sure I'm forgetting something.

While not objResults.EOF
strRecord=String( 333 ,32 )
IF TicketID<>objResults.Fields("ticket").Value then
Mid(strRecord,1,1)="H"
mid(strRecord,2,5)=objResults.Fields("cust").Value 'cust
mid(strRecord,7,30)=objResults.Fields("ship1").Value 'ship1
mid(strRecord,37,30)=objResults.Fields("ship2").Value 'ship2
mid(strRecord,67,30)=objResults.Fields("ship3").Value 'ship3
else
mid(strRecord,1,1)="D"
END IF
objStream.WriteLine(strRecord)
TicketID=objResults.Fields("ticket").Value
objResults.Movenext


Wend
mahajan.sanjeev NO[at]SPAM gmail.com
4/21/2005 12:54:15 PM
I think you have messed up with the Mid function. Mid return a string
and it cannot be used the way you are using it. I would approach the
whole script differently:

While not objResults.EOF
IF TicketID<>objResults.Fields("t=ADicket").Value then
strRecord =3D "H"
strRecord =3D strRecord +
objResults.=ADFields("cust").Value 'cust
strRecord =3D strRecord +
objResults=AD.Fields("ship1").Value 'ship1
strRecord =3D strRecord +
objResult=ADs.Fields("ship2").Value 'ship2
strRecord =3D strRecord +
objResult=ADs.Fields("ship3").Value 'ship3
strRecord =3D strRecord + Space(333 -
Len(strRecord))
else
strRecord=3D"D"
strRecord =3D strRecord + Space(333 -
Len(strRecord))
END IF
objStream.WriteLine(strRecord)
TicketID=3DobjResults.Fields("ti=ADcket").Value
objResults.Movenext=20


Wend
Alex
4/22/2005 4:01:00 AM
you can only use mid(string,1,1) = "h" in VBA + VB6 etc

you can not use this construct in VBScript
AddThis Social Bookmark Button