0

I'm trying to write code to print out "Row (0 to 3): ".

Here's my code:

ReadOnly gridSize As Integer = 4
Dim s1 As String
s1 = "Row (0 to " & (gridSize - 1) & "): "
WriteLine(s1)

I'm getting an InvalidCastException with the following error at the last line, when the machine tries to print out the string:

Conversion from string "Row (0 to 3): " to type 'Integer' is not valid.

Voyna
  • 33
  • 6

1 Answers1

0

Integer is not a String. How about using gridSize.ToString() ?

  • Or suitable for you: (xxxx - xxx).ToString() –  Jul 28 '16 at 15:28
  • Like this? `s1 = "Row (0 to " & (gridSize - 1).ToString() & "): "` I get the same error sadly – Voyna Jul 28 '16 at 15:31
  • Hm should work (in C# anyway), try & CStr(gridsize - xx) & –  Jul 28 '16 at 15:47
  • Tried that too - no luck. It seems that the error occurs on the WriteLine(s1) line, is there maybe a way to specify that you want it to input a String? – Voyna Jul 28 '16 at 15:50
  • Hm... do you have any specification of the WriteLine method? Is it Writing to the console? –  Jul 28 '16 at 16:07
  • No you were right; I just had to write Console.WriteLine rather than just WriteLine. It fixed my problem :) – Voyna Sep 16 '16 at 09:51