#1
  1. No Profile Picture
    http://stealthwd.ca
    Devshed Novice (500 - 999 posts)

    Join Date
    Dec 2005
    Posts
    691
    Rep Power
    200

    Visual Basic variable in string


    Complete VB noob.. I want to increase a date in a for loop, however the date has to be a part of a string. The string is being used in a SQL query....

    How can I add the variable to the string.... for example

    for x=1 to 6

    string="the year is 200'x' "

    next

    So the string keeps increasing the year.
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Moved to VB from Other

    Code:
    Sub ConcatNumber()
        Dim strString As String
        Dim x As Integer
        For x = 1 To 6
            strString = "The year is 200" & x
            MsgBox strString
        Next
    End Sub
    (String is a reserved word you can't use it as a variable name as it is a data type)

    Same thing using Date data type

    Code:
    Sub UseDateType()
        Dim dtDate As Date
        Dim x As Integer
        dtDate = "1/1/2000"
        For x = 1 To 6
            dtDate = DateAdd("yyyy", 1, dtDate)
            MsgBox "The year is " & Format(dtDate, "yyyy")
        Next
    End Sub

    Comments on this post

    • Dameon51 agrees
    Last edited by medialint; April 7th, 2006 at 11:21 AM.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

IMN logo majestic logo threadwatch logo seochat tools logo