Search code examples
stringvb6integermultiplication

VB6: What does "string = string * integer" do?


I am trying to rewrite some old VB6 legacy programs to C# and just encountered this. I am still a little new to Visual Basic and I have no idea what this means or what it's function is. Here is the exact format:

strMyString = strMyString * 100

Its not related to a variable declaration so I don't think it has to do with the string length but I am not sure. Any advice is appreciated.


Solution

  • If strMystring holds a string representing a number, the right hand side will coerce it to be a number, multiply it by 100, after which the assignment will coerce the result back to a string.

    A simple test:

    Sub test()
        Dim s As String
        s = "50"
        s = s * 100
        Debug.Print s
    End Sub
    

    The above code prints 5000, as expected.