Convert Excel cell to integer

excel

#1

Hi,

Im trying to read a cell from Excel, and printing it to the screen using Message box.
I tried to convert the variable to int32 using the assign activity, but it is not working as intended.

I tried the following:

1: Read Cell
2: Assign activity: variable = convert.toInt32(variable As Integer)
3: Message Box: variable.ToString

But I get this message saying something like: Comma or valid expression continuation expected. Am I typing something wrong in the Assign activity?
I have found one similar question on this forum, but did not find a precise answer.

Could somebody help me out?


#2

Hi,

Are you putting the “As Integer” in there too or are you just showing it’s an integer for us, cause removing that should fix it.

Also, you shouldn’t need to Assign it to a string like that and can do it straight in the Message Box if you wanted.

variable.ToString
CStr(variable)
Convert.ToInt32(variable)

All those will convert your variable to a string in order to output it.


#3

Allright, I removed the “As Integer”, but it stil lwould not work and gave me the error message “int32 Converter cannot convert from System.Double” and refers to the Read Cell activity. The output of that activity is stored in Variable with type int32. Is the variable type wrong? The cell in excel contains a number and not text, so therefore i chose int32.


#4

try to change the variable type with “System.Double” and then in message box use same like variable.Tostring().


#5

Changed the variable type to System.Double. Now it works, but I dont know why, and I had to make a new sequence with a new variable. First I tried to change the existing variable to type System.Double, but then I got error " StringConverter cannot convert from System.Double". But after I made a new sequence it works. Confusing :stuck_out_tongue:


#6

#7

Allright, I see! Thank you :slight_smile: