Results 1 to 4 of 4

Thread: changing data type

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    What if i wanted to take the integer 2, and turn it into the string "2", how do I do that?

  2. #2
    Fanatic Member Dim's Avatar
    Join Date
    Jul 2000
    Posts
    620
    I'm not sure of what exactly is being asked but:
    Code:
    Dim i As Integer
    Dim newstring As String
    For i = 0 To 60
        If i = 2 Then
            newstring = i
            MsgBox newstring
            Exit Sub
        End If
    Next i

    Hope that helps,
    D!m

    [Edited by Dim on 09-13-2000 at 08:44 PM]
    Dim

  3. #3

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    like if i wanted to do this:

    Dim x as Integer

    then somewhere in my code, do something like this:
    x = 5
    x as String

    so, then x would no longer be 5 , it would be "5"

    how would that get done?? is there a simpler way than the above?

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    You can only do that with Variant

    If you truly want a single variable to first be an Integer then later be a String, you have to think about using Variant type.

    Look in the help about how to tell what the Variant is representing at any one time.

    Code:
    Dim x as Variant
    'Both of the following are valid for a variant
    x = 5
    x = "5"
    But if you are really just wanting to cast (convert) an integer to a string, then use the CStr function (It means Convert To String)

    Code:
    Dim x as Integer
    If CStr(x) = "5" Then Debug.Print "Well this should work!"
    Regards
    Paul Lewis

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