?
Solved

VBScript - CInt Type Mismatch When Using String Function

Posted on 2013-05-21
5
Medium Priority
?
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 46

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 750 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 46

Accepted Solution

by:
aikimark earned 750 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

752 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