1

The code i am trying to run is a simple one. get text from a Textbox and display that via MsgBox. now i probably have done this a million times but i get a strange error. The Code is :

 Dim s As String = FromDateTEX.Text.ToString
 MsgBox(s)

I get this error from second line :

System.InvalidCastException: 'Specified cast is not valid.'

Here is the strange part : Debugger shows value for s which is correct. here is the screenshot : screenshot

What am i doing wrong here ?

Edit :

Even this code gets the same error :

 MsgBox(“hello”)
Ali Hanifi
  • 408
  • 1
  • 5
  • 18
  • The error much more likely occurs on the line _above_ that, since if it was caused by the `s` variable it would've happened already on: `Dim s As String = FromDateTEX.Text.ToString`. The debugger isn't always 100% accurate. – Visual Vincent May 10 '18 at 17:17

2 Answers2

0

One line above, you access the property EditValue of control DomainLUE. If LUE stands for LookUpEdit, do you happen to be using a 3rd party component library from a company like DevExpress?

If that is the case, is FromDateTEX a textbox (TextEdit) control from this library too? In that case, FromDateTEX might also expose an EditValue property. Then you might try to convert that value to a string:

Dim s As String = FromDateTEX.EditValue?.ToString()

I am not sure why the Text property is problematic here. I would expect it to work just fine. Very strange.

Oh, by the way, sometimes Visual Studio goes a little bit berserk. Closing Visual Studio, optionally deleting the .suo file, restarting Visual Studio and reopening the solution might help too...

Bart Hofland
  • 3,700
  • 1
  • 13
  • 22
  • Yes both are from DevExpress. But it has nothing to do with third party component. I even tried ‘Msgbox(“hello”)’ and got the same error. I am really running out of ideas. – Ali Hanifi May 11 '18 at 06:32
  • Very strange. It smells like a Visual Studio quirk. Have you tried to delete all non-essential files from your projects/solutions, like the projects' bin and obj folders, the the project user files and the solution's .suo file prior to loading the solution in Visual Studio? (You may want to create a backup copy of your solution before you try to do so.) If that does not help, I am out of ideas too... – Bart Hofland May 11 '18 at 11:26
0

Turns out the error was from the above line. LookupEdit 's EditValue was in fact a Short and it needed a Convert to Integer.

Ali Hanifi
  • 408
  • 1
  • 5
  • 18