Results 1 to 15 of 15

Thread: Left$

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759

    Left$

    Hi Everyone,

    Is there any such thing as a left$. I want to capture the first 3 letters of a name but I cannot get the VB program to recognize the Left$ procedure. For example, I want this.

    Name = Inventory

    Code:
    strFile = Left$(" & Text1.Text & ", 3)
    New Name = Inv

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    ???

    VB Code:
    1. strFile = Left$(Text1.Text, 3)

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    Try this:
    Dim strFile as String
    strFile = Left(" " & Text1.Text & " ", 3)

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    If you are lazy like me you can save 3 key presses

    strFile = Left$(Text1, 3)
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    BTW...

    The reason Left$ does not come up with Intellisense is because it sees Left as the Left property for your form. Try it in a module and it works
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759
    Thanks for your reply crptcblade. It still doesn't recognize it though. When I type Left$ and hit the "(" sign, nothing even recognizes that it is doing a left string function. When I try a Right$( I receive a tooltip that says Right$(String As String, Length As Long) As String. Any ideas what may be wrong?

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    funny, not even in a bas module? Hmmm...It works for me
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Works for me..

    Code:
    Private Sub Command1_Click()
      MsgBox Left$(Text1, 3)
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  9. #9
    Matthew Gates
    Guest
    You can also use the Mid function.


    VB Code:
    1. strFile = Mid$(Text1.Text, 1, 3)
    2. MsgBox strFile

  10. #10
    Addicted Member
    Join Date
    Jul 2000
    Location
    FeedMeTown, Ohio
    Posts
    176
    One thing that brings an element of confusion to me, not speaking
    for others, is this:

    VB can create variables on the fly. This is not necessarily a good thing. In real practice, I believe in declaring all variables, i.e., Dim strFile as String.

    Afterwords, call the "Left" function as I've illustrated above. It
    should work OK.

    Redundancy is exposed in the code: strFile = Left$(whatever, how many)

    Declare the variable and call the function as intended:
    Dim MyString as String
    MyString = Left(SomeString, NumberOfPlacesFromTheLeft)

  11. #11
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    Actually, I've noticed this before too. While the Left() function works, it does not display the arguments in a tooltip, whereas the Right and Mid functions do. {VB6 SP5}
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  12. #12
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by crptcblade
    BTW...

    The reason Left$ does not come up with Intellisense is because it sees Left as the Left property for your form. Try it in a module and it works
    here's the reason. You can reference properties/methods of a form without using the form name while your are in that form's code module. Like :
    VB Code:
    1. 'in a form module
    2. Left = Top - 20

    is the same as :
    VB Code:
    1. 'in a form module
    2. Me.Left = Me.Top - 20

    again, use the Left() function in a bas module and you'll see the tooltip

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2001
    Posts
    759
    Hi Everyone,

    Thanks for your advice. I can get the Left$ function to work inside of the bas module and inside of the MsgBox ok, but this is what I am really trying to do. I have inserted the ImgScan.ocx control on my form and have developed some scanner code to work with it. I am trying to save the image as a bitmap file to the following location. I want to save the file with the first 3 letters of the name in Text2.Text plus have the current date at the end. For example, if the name in Text2.Text was INVENTORY. The file would be saved as INV6/6/01.bmp. Make sense? I can get the Left$ function to work ok but I receive a bad file name error when I try to add the date on the end. Any ideas what I am doing wrong? I would appreciate any help. Thank you.

    Code:
    "C:\Scanner Test\Folder1\" & Left$(Text2.Text, 3) & Date & ""

  14. #14
    Matthew Gates
    Guest
    Originally posted by Ace

    Code:
    "C:\Scanner Test\Folder1\" & Left$(Text2.Text, 3) & Date & ""

    Just lettin' you know, you don't need the last three characters .


    Code:
    "C:\Scanner Test\Folder1\" & Left$(Text2.Text, 3) & Date

  15. #15
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I know exactly what is wrong. You cannot have a filename with these characters in it : \ / : * ? > < " |

    try using Replace() to switch the "/" with a valid character.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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