Solved

VBScript - CInt Type Mismatch When Using String Function

Posted on 2013-05-21
5
602 Views
Last Modified: 2013-07-25
Why do I get a type mismatch error on the first CInt function in the code below.  The input file is formatted as follows.

00001,REBOOT,01-01-13,01:01
00002,REBOOT,01-01-13,01:02
00003,REBOOT,01-01-13,01:03

etc...


Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objShell = Wscript.CreateObject("Wscript.Shell")

	Const ForReading = 1, ForWriting = 2, ForAppending = 8

	Set InputFile = objFSO.OpenTextFile("\STORETEMP\REBOOTS\REBOOTS_DETAIL.CSV", ForReading)
	
	Do While Not InputFile.AtEndOfStream
	
		InRecord = Split(InputFile.ReadLine, ",")
		
		StoreNbr1 = InRecord(0)
		Message1 = InRecord(1)
		RBDate1 =  InRecord(2)
		RBTime1 = InRecord(3)

		StoreNbr2 = "00300"
		Message2 = "REBOOT"
		RBDate2 =  "01-01-13"
		RBTime2 = "15:15"
	
		WScript.Echo(CInt(StoreNbr1) & vbTab & Message1 & vbTab & RBDate1 & vbTab & RBTime1)
		WScript.Echo(CInt(StoreNbr2) & vbTab & Message2 & vbTab & RBDate2 & vbTab & RBTime2)

	Loop

Open in new window

0
Comment
Question by:gnchq
  • 2
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 39187053
On a quick look try relacing lines 12 - 15 with:

            StoreNbr1 = replace(InRecord(0), """", "")
            Message1 = InRecord(1)
            RBDate1 =  InRecord(2)
            RBTime1 = replace(InRecord(3), """", "")


As far as I can see you are getting strings within strings returned and the changes to the first and last parts removes all quotes in order to allow the cint to work as expected.

Chris
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 39187283
Hi,

Can you check your file (\STORETEMP\REBOOTS\REBOOTS_DETAIL.CSV)? There is a possibility that there is a row with empty StoreNbr.

If you try the following:
Create a new vbs
In the vbs write only:
WScript.Echo(CInt(""))

Open in new window

or
WScript.Echo(CInt(" "))

Open in new window


you will get the same error.

Giannis
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39187306
do you have an empty line at the end or beginning of the file?
0
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 250 total points
ID: 39187326
I had thought of an empty line existing too, but if he did have one then it would error before the echo line, on trying to access item 1 of the array, as in :

Message1 = InRecord(1)

Open in new window


It would have thrown an index out of bounds exception....

Giannis
0
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 39187923
Please try this
CStr(CInt(StoreNbr1))

Open in new window


You are concatenating the value after casting it as a number.  Maybe you need to recast it back into a string before it becomes eligible for concatenation, which is a string operation.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question