Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript - CInt Type Mismatch When Using String Function

Posted on 2013-05-21
5
Medium Priority
?
639 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

A short article about problems I had with the new location API and permissions in Marshmallow
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Simple Linear Regression
Introduction to Processes

610 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