Results 1 to 4 of 4

Thread: Help With an Error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2012
    Location
    Los Angeles, CA
    Posts
    29

    Help With an Error

    From this Sub, what would cause the form to close when I run this code? This code will run when I click on the "Submit" button on my application.

    vb.net Code:
    1. Private Sub bSub_Clicker()
    2.  
    3.         Dim tempDir As String = dir.Text
    4.         Dim lastChar As String
    5.         Dim tempFile As String = file.Text
    6.         Dim response As MsgBoxResult
    7.         Dim checker As String = ""
    8.  
    9.         If System.IO.File.Exists(dir.Text & "\" & file.Text & ".txt") = False Then
    10.             lastChar = HWFunctions.getLast(dir.Text)
    11.             If lastChar = "\" Then
    12.                 response = MsgBox("The file " & tempDir & tempFile & ".txt does not exist." _
    13.                                   & vbCrLf & "Would you like it to be created for you?", 4)
    14.             End If
    15.             If lastChar <> "\" Then
    16.                 response = MsgBox("The file " & tempDir & "\" & tempFile & ".txt does not exist." _
    17.                                   & vbCrLf & "Would you like it to be created for you?", 4)
    18.             End If
    19.             If response = MsgBoxResult.Yes Then
    20.                 If System.IO.Directory.Exists(dir.Text) = False Then
    21.                     Try
    22.                         System.IO.Directory.CreateDirectory(dir.Text)
    23.                     Catch ex As ArgumentException
    24.                         MsgBox("Please input a directory name.")
    25.                         checker = "something"
    26.                     End Try
    27.                 End If
    28.                 If checker = "" Then
    29.                     lastChar = HWFunctions.getLast(dir.Text)
    30.                     Try
    31.                         If lastChar = "\" Then
    32.                             System.IO.File.Create(tempDir & tempFile & ".txt")
    33.                         ElseIf lastChar <> "\" Then
    34.                             System.IO.File.Create(tempDir & "\" & tempFile & ".txt")
    35.                         End If
    36.                     Catch ex As UnauthorizedAccessException
    37.                         MsgBox("Access to the current directory is denied.")
    38.                         checker = "something"
    39.                     End Try
    40.                     My.Settings.chosenDir = dir.Text
    41.                     My.Settings.chosenFileName = file.Text
    42.                 End If
    43.  
    44.             End If
    45.  
    46.             If response = MsgBoxResult.No Then
    47.                 MsgBox("Please choose another directory.")
    48.                 checker = "something"
    49.             End If
    50.         Else
    51.             My.Settings.chosenDir = dir.Text
    52.             My.Settings.chosenFileName = file.Text
    53.  
    54.             If hw.Visible = False Then
    55.                 hw.Show()
    56.             End If
    57.  
    58.             Me.Hide()
    59.         End If
    60.  
    61.  
    62.  
    63.         If checker = "" Then
    64.             If hw.Visible = False Then
    65.                 hw.Show()
    66.             End If
    67.  
    68.             Me.Hide()
    69.         End If
    70.  
    71.     End Sub
    Thanks,

    jerz4lunch

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: Help With an Error (re-post)

    Best to set a break point and step thru the code. One guess is Me.Hide()

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Help With an Error (re-post)

    It depends on exactly what you mean by "close". As KI suggests, Hide is obviously going to make the form disappear from the screen. As I suggested in your other thread, please provide a FULL and CLEAR description of the problem. That would include EXACTLY what you expect to happen and EXACTLY what does happen.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Help With an Error (re-post)

    I'd say it doesn't close but it's hidding and that is caused by one of the "Me.Hide" lines!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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