Solved

VBScript - CInt Type Mismatch When Using String Function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Explain Unit of Work pattern 2 54
java  and programming certification ? 4 86
Base1 Encode/Decode 3 67
Problem to open text file 11 67
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
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…

932 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

14 Experts available now in Live!

Get 1:1 Help Now