Results 1 to 4 of 4

Thread: [RESOLVED] message box error

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] message box error

    I try to find the filename in the directory by input the filename in the textbox.
    But When user don't put the anyting in the text1, I got the message MsgBox "File not found" . I don't want to get the message like this.
    I want the message box appear like this MsgBox "please input you filename" . How to do that?

    The message box "File not found" only appear when the filename did not found in the directory

    If Ret = 0 And ret2 = 0 Then MsgBox "File not found"


    Code:
    Private Sub Command1_Click() ' search button. When the file name found.It and display it in the listview
        Dim tempstr As String, Ret As Long
        tempstr = String(MAX_PATH, 0)
        'returns 1 when successfull, 0 when failed
    
    Ret = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".shp", tempstr)
    If Ret <> 0 Then Call Insertsub(tempstr)
    ret2 = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".img", tempstr)
    If ret2 <> 0 Then Call Insertsub(tempstr)
    
    If Ret = 0 And ret2 = 0 Then MsgBox "File not found"
    
    End Sub
    Code:
    Private Sub Insertsub(tempstr As String)
    Dim i As Long
    Dim sName() As String
    Dim sPath As String
    sName = Split(tempstr, "\") 'contains File name'
    
    Dim lvItem As ListItem
    
    Set lvItem = ListView1.ListItems.Add(, , sName(UBound(sName)))
        lvItem.ListSubItems.Add , , "" & Left$(tempstr, InStr(1, tempstr, Chr$(0)) - 1)
        
    'call the for to remove the filename extension for example lot.shp become lot and use to display the legend
    Text2.Text = FileTitleNoExt(sName(UBound(sName)))
    'get the path location from searching file
    Text3.Text = GetDirFromFile(tempstr)
    End Sub

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: message box error

    Code:
    Private Sub Command1_Click() ' search button. When the file name found.It and display it in the listview
        Dim tempstr As String, Ret As Long
        tempstr = String(MAX_PATH, 0)
        'returns 1 when successfull, 0 when failed
    If Trim(Text1.Text) = "" Then
        ' Your message here
        Exit Sub
    End If
    Ret = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".shp", tempstr)
    If Ret <> 0 Then Call Insertsub(tempstr)
    ret2 = SearchTreeForFile("C:\Project\Data\", Text1.Text + ".img", tempstr)
    If ret2 <> 0 Then Call Insertsub(tempstr)
    
    If Ret = 0 And ret2 = 0 Then MsgBox "File not found"
    
    End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Smile Re: message box error

    Thank you martin.It succeed But I have two questions what is the difference between If Trim(Text1.Text) = "" and If Text1.Text = ""

    What is trim function?could you give me some example?

    Code:
    If Trim(Text1.Text) = "" Then
        ' Your message here
        Exit Sub
    End If

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: message box error

    Trim() is exactly that, it "trims" your string...ltrim() and rtrim() trims spaces from the left and right respectively, while trim() trims from both sides.

    His code basically checks to make sure that the string isn't *just* spaces :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

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