none
loop condition in vb.net

    Question

  • I try to copy data from excel in textbox and from textbox this automatically convert to grid i try this

    
                            If value= "" Then
                                value= "0"
                            
    this shows error input string was not in correct format
    Thursday, April 27, 2017 12:22 PM

All replies

  • when there is empty cells between data e.g. if def_col is empty in cell then this paste 0 in grid but then problem is if last cell is empty then this cannot paste 0 this shows empty whereas i want to show 0 also when last column is empty ..

    Insert a breakpoint at
                            If cell = "" Then
    and when the code stops at that point find out what the value of 'cell' is. You may need to adjust that test.  For instance you may need to use Trim to remove spaces before testing for an empty string.  It depends on how the original document file has been formatted.

    Thursday, April 27, 2017 10:31 PM
  • and this shows error .. Input string was not in a correct format.Couldn't store < > in Col15 Column.  Expected type is Decimal.
    Friday, April 28, 2017 6:02 AM
  • and this shows error .. Input string was not in a correct format.Couldn't store < > in Col15 Column.  Expected type is Decimal.
    Same thing.  Insert a breakpoint at that point, run it until it stops there, and have a look at the value.  In that case you will see that the value cannot be converted to a decimal number. You will need to decide what to do with it - fix it in the source document, insert a default value, report it as an error, etc. 
    Friday, April 28, 2017 6:05 AM
  • when i enter any other value instead of "" then this works fine but when i leave this cell as empty then this shows error
    Friday, April 28, 2017 6:36 AM
  • ok when i debug this shows " " instead of "" ? how is this possible ?
    Friday, April 28, 2017 6:47 AM
  • ok when i debug this shows " " instead of "" ? how is this possible ?
    It appears that you need to Trim the value before testing it for "".  See:
    https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.strings.trim(v=vs.110).aspx
    Friday, April 28, 2017 7:46 AM
  • I'd guess your problem is with this piece of code:

    If someString = "" then

    you should better use :

    If String.IsNullOrEmpty(someString) Then
    or
    If someString = String.Empty Then


    Friday, April 28, 2017 7:48 AM
  • i tried this .. this also shows like this in cell " "
    Friday, April 28, 2017 9:25 AM
  • i tried this .. this also shows like this in cell " "

    You tried what?

    When the debugger stopped at the new line of code where you are removing the spaces, and you then stepped it on one line of code at a time, what was the subsequent path through the code?  Did it take the 'If' path or the 'Else' path?

    • Edited by AcamarMVP Friday, April 28, 2017 9:52 AM sp
    Friday, April 28, 2017 9:51 AM
  • and this shows error .. Input string was not in a correct format.Couldn't store < > in Col15 Column.  Expected type is Decimal.

    You are using characters "" (is an empty character) while the computer expects a numeric value (likewise zero).

    If nothing helps than make your code likewise it is called in so many other languages dynamic by putting Option Strict Off in top of your code. 

    Be aware, while "dynamic" sounds sophisticated, you can compare it as this in the eyes of a kid. 

     

     

    Success
    Cor

    Friday, April 28, 2017 12:37 PM
  • Hello,

    You can use this:

    If Value.Trim() = "" Then
                Value = 0
            Else
                Value = Convert.ToInt32(Value)
            End If

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, May 4, 2017 7:46 AM
    Moderator