Results 1 to 12 of 12

Thread: [RESOLVED] Hiding file extentions in a file list box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Resolved [RESOLVED] Hiding file extentions in a file list box

    Sets the FileListBox path...
    Code:
    File2.Path = App.Path & "\ncaateams\"
    Loads the .dat file into the appropriate places...
    Code:
    Private Sub Command2_Click()
    File2.Path = App.Path & "\ncaateams\"
    If File2.FileName = "" Then
    yourmsg = MsgBox("Please select a team to load", 0, "Home Error")
    Else
    Open File2.Path & "\" & File2.FileName For Input As #2
    Input #2, hname, hoff, heff, hdef, hhfa, hpic
    Close #2
    Home.Caption = (hname)
    hOffense.Caption = (hoff)
    hEfficiancy.Caption = (heff)
    hDefense.Caption = (hdef)
    homepic2.Picture = LoadPicture(File2.Path & "\" & hpic)
    End If
    Home.Visible = True
    File1.Visible = False
    File2.Visible = False
    Command1.Visible = False
    Command2.Visible = False
    hOffense.Visible = True
    hDefense.Visible = True
    Label15.Visible = True
    hrolls = hoff + vdef + hhfa
    End Sub
    So all that being shown, I'm looking to hide the ".dat" next to the file names because it's ugly.

    Any help would be great and I only want to use a file list box and not switch to a list box or drop down menu.

    Thanks guys!

  2. #2
    Hyperactive Member
    Join Date
    Jan 2006
    Location
    Pakistan
    Posts
    388

    Re: Hiding file extentions in a file list box

    Here is the method you can use.
    First declare an array of strings. The number of items should be "enough". You are going to need to save your list in this array.
    Now load all of your list in your array.
    Finally start a for loop from 0 to File2.ListCount - 1
    Now check for every item data if it has the "." in it. If it does then remove the original data and add the data without the "." Mid(Data,Instr(Data,".")+1) would do for this.
    And you are done.

  3. #3
    Hyperactive Member Quiver318's Avatar
    Join Date
    Sep 2007
    Posts
    260

    Re: Hiding file extentions in a file list box

    This may be over simplified, but why not rename the files so that they don't have any extention?

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Re: Hiding file extentions in a file list box

    Quote Originally Posted by Quiver318
    This may be over simplified, but why not rename the files so that they don't have any extention?
    Because of the way that the filelistbox finds the files, they automatically are added to the end of the name, I don't add the .dat into the name.

    The first response was a great one, but sadly my coding falls a little short of being able to write that out -- I'll do some research on my own to figure out what you wrote but if you could post even just a tidbit of what you where explaining I would be in great debt to you.

    Thanks again.

  5. #5
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Hiding file extentions in a file list box

    IIF(Post.Rate > 0 , , )

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Re: Hiding file extentions in a file list box

    Quote Originally Posted by zeezee
    I found the first link in a quick google search a while ago (two weeks) but wasn't able to really glue together what the code was explaining I'll test it out as soon as possible, though -- Guess I thought there was an easier way.

    Thanks.

  7. #7
    Member Senacharim's Avatar
    Join Date
    Feb 2008
    Posts
    56

    Re: Hiding file extentions in a file list box

    You just need to filter it. Try something like
    Code:
    MyFileNameString = Left(MyFileNameString, Len(MyFileNameString - 4))
    Working on the assumption that all listed files have the same ".xyz" (4 characters) extension...
    _____________________________
    . Error Code 34: There is no error .

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Re: Hiding file extentions in a file list box

    Quote Originally Posted by Senacharim
    You just need to filter it. Try something like
    Code:
    MyFileNameString = Left(MyFileNameString, Len(MyFileNameString - 4))
    Working on the assumption that all listed files have the same ".xyz" (4 characters) extension...
    What does "MyFileNameString" actually pertain to?

  9. #9
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: Hiding file extentions in a file list box

    Hi Evan, did you try that code in the first link?

    It should do what you wanted to do.
    And there is an easier way.

    Hide your File List box.
    View a List box
    After Loading the files to the file list box, add the file names to the List box without the Extension.

    eg:
    Code:
    Private Sub File2_PathChange()
        Dim i As Long
        List1.Clear
        
        For i = 0 To File2.ListCount - 1
            List1.AddItem Left$(File2.List(i), InStrRev(File2.List(i), ".", , vbTextCompare) - 1)
        Next
        
        
    End Sub
    
    Private Sub Form_Load()
        File2.Path = App.Path
        File2.Visible = False
        File2_PathChange
    
    End Sub
    when you need to load the files, use the ListBox's ListIndex to get path and filename from the File List Box. They should match.
    (For reliabilty, you can search the list Box for FileName and retrieve Path and Correct Name. but if there are two files with same name and different extensions, you are in trouble )


    Last edited by zeezee; May 1st, 2008 at 09:50 PM.
    IIF(Post.Rate > 0 , , )

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Re: Hiding file extentions in a file list box

    Quote Originally Posted by zeezee
    Hi Evan, did you try that code in the first link?

    It should do what you wanted to do.
    And there is an easier way.

    Hide your File List box.
    View a List box
    After Loading the files to the file list box, add the file names to the List box without the Extension.

    eg:
    Code:
    Private Sub File2_PathChange()
        Dim i As Long
        List1.Clear
        
        For i = 0 To File2.ListCount - 1
            List1.AddItem Left$(File2.List(i), InStrRev(File2.List(i), ".", , vbTextCompare) - 1)
        Next
        
        
    End Sub
    
    Private Sub Form_Load()
        File2.Path = App.Path
        File2.Visible = False
        File2_PathChange
    
    End Sub
    when you need to load the files, use the ListBox's ListIndex to get path and filename from the File List Box. They should match.
    (For reliabilty, you can search the list Box for FileName and retrieve Path and Correct Name. but if there are two files with same name and different extensions, you are in trouble )



    Thanks for the help, I've been working on my project for almost three hours today and I have finals coming up so I'm going to pull myself away from the computer to study (for once) before I try the code. Most of the code makes sense to me though, which is a good sign.

    Ironically, One of the earlier posted links allowed me to figure out how to select a random .dat file from the file list box which is fantastic because I've been trying to implement a 'random simulation' button into my simulator for a looong time now.

    Thanks for the well thought out responses and all the effort you put into helping. I'm glad I found this site because as a very novice and self-taught VB addict who usually just pieces code together from old applications -- I've learned a lot.

    Peace out and consider this resolved.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    16

    Re: [RESOLVED] Hiding file extentions in a file list box

    I know I resolved this, but stubborn old me has a question for zeezee.

    Your code worked great! I've got the Files showing up in the list box without the extensions but now I'm not sure how to load them.

    I know that this is the what I need to convert but when I'm changing the direction to look for the file I keep getting errors. This is the code that needs modified:

    Code:
    Open File2.Path & "\" & File2.FileName For Input As #2
    Input #2, hname, hoff, heff, hdef, hhfa, hpic
    Close #2
    End If
    I thought I might be able to use an Open command with List1.Index but it's not working, heh.

    Thanks for your patience -- you've all been a big help with me.

  12. #12
    Frenzied Member
    Join Date
    Jul 2007
    Posts
    1,306

    Re: [RESOLVED] Hiding file extentions in a file list box

    I assume you are using the code I gave in Post #9.

    This should be the code

    Code:
    Open File2.Path & "\" & File2.List(List1.ListIndex) For Input As #2
    Input #2, hname, hoff, heff, hdef, hhfa, hpic
    Close #2
    End If
    try and see.
    I didnt test the code

    You should do validations before the Open command. like the file exists, or list1.Listindex >= 0 , or List1.ListCount > 0 etc ...

    IIF(Post.Rate > 0 , , )

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