3

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.

  • The answer will be the same here, but i want to point that VBA and VB6 are two distinct languages with their own particularities. Please try to not mix them – litelite May 25 '16 at 21:38
  • 2
    @litelite As programming languages VB6 and VBA are virtually *identical* (same grammar, same variable types, same constructs, same loops, same approach to classes, etc, all running using the same DLLs). See this: http://stackoverflow.com/q/993300/4996248 They run in different contexts so there are definitely differences you need to be aware of. It is VB6/VBA vs. VB.Net where the real differences lie. – John Coleman May 25 '16 at 22:07
  • 1
    @JohnColeman I do understand your point, but i still believe that posts should be properly tagged. – litelite May 26 '16 at 02:08
  • I interpreted it as a VB6 question, which it was tagged on -- unless the tags were edited. – John Coleman May 26 '16 at 03:02

1 Answers1

7

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.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
  • Thank you! I know this was very simple but I couldn't find a direct reference to it anywhere. The string value contains a floating point so this is exactly what the program was trying to do. – LittleBachman May 25 '16 at 21:45
  • @LittleBachman If you are going to be looking at a lot of old VB6 code, I recommend the O'Reilly Book "VB & VBA in a Nutshell" by Paul Lomax. It is a very well-written reference book, with a fair amount of short snippets illustrating on how various language features work. Even though I've been using VBA for 15+ years, I still consult it 2 or 3 times per month. – John Coleman May 25 '16 at 21:52
  • 1
    +1 It is also worth knowing that the string will be converted to a number using the regional settings of the executing PC. This can matter if you need your code to run in different countries – MarkJ May 27 '16 at 12:33