CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    8

    Question Str function in VB

    Hi,

    I'm a beginner in VB. I tried to change an integer to string using str as below

    Dim z As Integer
    Dim s As String

    z = 100
    s = Str(z)
    Combo2.AddItem (s)

    when 100 is converted to string there is a space added in the start of the string.

    it is " 100" instead of 100. Please let me know if there are any other functions for changing integer 100 to "100"

    Regards,
    Carol.

  2. #2
    Join Date
    Oct 2005
    Posts
    158

    Re: Str function in VB

    try:
    Code:
    s = trim(str(z))

  3. #3
    Join Date
    Jan 2001
    Posts
    486

    Re: Str function in VB

    I believe this is the correct syntax:

    Dim z As Integer
    Dim s As String

    z = 100
    s = CStr(z)
    If kids were left to their own devices, would they ever come up with a thing like war?......The Wheel / Todd Rundgren

    Do canibals not eat clowns because they taste funny?

  4. #4
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Str function in VB

    Right.
    The str() function takes in account that there might be a negative number, preceded by a '-'. Str() precedes positive numbers with a blank and will thus result in equal length strings to positive and negative numbers. (Str(-100) has the same length as str(100))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured