Zum Hauptinhalt gehen

Suche

Suche

Incompatible Types Problem While Trying Incrementing Serialnumbers Unsing Vb Scripting

Kommentare

1 Kommentar

  • Avatar
    Legacy Poster

    You cannot add a number to a string. This won't work in VB6 either.

     

    Having a look on your code you can see, that you have a variant that is set to a string. Thus this variant will be allocated as a string in its safearray-structure.

    then you direct cast this test to value. Value is always a string (as far as i have figured it out).

     

    After this you try to add "+1" to a string what is usually made by the ALU. This arithmetical logical unit is not able to add a number to an string but only numbers to numbers and therefore you'll get an invalid cast exception which is in Visual Basic Error 6900.

     

    So the way you can change this is to use a type converstion like

     

    test = cInt(test) + 1

     

    However, Visual Basic is not that intelligent. Having nothing in the Textbox means a conversion of the content "Nothing" to a Number. Which number is representing "Nothing"? Right - nothing. And that is the reason why you get this error.

     

    Simply initialize your textbox with something plausible like "0" and it will work.

    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.