Results 1 to 3 of 3

Thread: Type Conversion

  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Unanswered: Type Conversion

    I have input boxes that I use to input the selection data that I want (numbers/dates).

    My macro opens the template that corresponds to my selection, then saves the file as Date_Block.xls.

    The problem that I am running into is that when i do a type conversion to convert my number to a string so that I can use it in a filename, it adds a space to the beginning of the data.

    I.E. If I have "SS = 1", then I convert it, it comes out " 1".

    Is there a simple way to have it not add the space? Or a simple way to eliminate it? I could add a case structure that would set the string based on the number, but it would have ~60 cases.

    Here is the code I am using:

    -------------------------------------
    Sub Run_Access_Macro()
    Dim Sensor As String
    Dim StartDate As String
    Dim EndDate As String
    Dim Block As String
    Dim File As String
    Dim Template As String

    Dim B As Double
    Dim S As Double
    Dim SS As Double
    Dim ES As Double

    'Prompt for Block, StartDate, and EndDate
    B = InputBox("Please enter block number:", "Access Query")
    StartDate = InputBox("Please enter Start Date:", "Access Query")
    EndDate = InputBox("Please enter End Date:", "Access Query")

    Block = Str(B)

    'Set Filename and Template
    File = StartDate + "_" + Block + ".xls"
    Template = "Template_" + Block + ".xls"

    'Open Template
    Workbooks.Open Filename:="C:\Life_Test\" + Template

    ...........

    End Sub

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067

    Re: Type Conversion

    Hi

    Have you tried using the trim comand
    i.e. MyString = Trim(MyString)

    This should get rid of any spaces at the start or end of the string

    Hope this Helps
    David

  3. #3
    Join Date
    Mar 2004
    Posts
    3

    Re: Type Conversion

    Originally posted by DavidCoutts
    Hi

    Have you tried using the trim comand
    i.e. MyString = Trim(MyString)

    This should get rid of any spaces at the start or end of the string

    Hope this Helps
    David
    It worked.

    Thanks!

    Jason

Posting Permissions

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