Solved

VBScript - CInt Type Mismatch When Using String Function

Posted on 2013-05-21
5
586 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now