CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2008
    Location
    DC
    Posts
    37

    Does VBS have a to string method?

    If it does not, how would I go about converting ints, doubles, longs, etc to a string? Thanks.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Does VBS have a to string method?

    Yes, VBScript has conversion methods for variable types.

    • CBool() - Convert to Boolean Type
    • CByte() - Convert to Byte Value
    • CCur() - Convert to Currency Type
    • CDate() - Convert to Date Value
    • CDbl() - Convert to a Double Value
    • CInt() - Convert to Integer Value
    • CLng() - Convert to Long Integer Value
    • CSng() - Convert to a Single Value
    • CStr() - Convert to String Value
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2008
    Location
    DC
    Posts
    37

    Re: Does VBS have a to string method?

    Ok thanks.
    What would happen if I used CDbl or CInt on a string without any numbers in it?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Does VBS have a to string method?

    It should return 0.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Does VBS have a to string method?

    Quote Originally Posted by dizou View Post
    Ok thanks.
    What would happen if I used CDbl or CInt on a string without any numbers in it?
    IMHO, you could test whether or not a number is present first, before converting it. - Call me old fashioned, but to me, it just makes a bit more sense.

  6. #6
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    304

    Re: Does VBS have a to string method?

    Quote Originally Posted by PeejAvery View Post
    It should return 0.
    Shouldn't it be type mismatch? To be honest I don't do VBS but they should be similar to VB6.0 and the following code raises an error.

    Code:
    Private Sub Command1_Click()
        MsgBox CInt("x")
    End Sub

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: Does VBS have a to string method?

    Quote Originally Posted by dee-u View Post
    Shouldn't it be type mismatch?
    Yes, it does. I was confusing it with an old basic language.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Jan 2006
    Location
    Pearl of the orient
    Posts
    304

    Re: Does VBS have a to string method?

    Quote Originally Posted by PeejAvery View Post
    Yes, it does. I was confusing it with an old basic language.
    Thanks for the clarification, in my part and for the OP's sake also.

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