Results 1 to 3 of 3

Thread: File Load Question

  1. #1

    Thread Starter
    Lively Member JAtkinson's Avatar
    Join Date
    Feb 2004
    Location
    Richmond, VA
    Posts
    68

    File Load Question

    Ive created a program that saves information about a person. The directory in which it is saved depends on what you select in two different comboboxes. (ie. if combobox1.text = "VBWIRE", and combobox2.text = "Forums", then the (OpenFileDialog) .initialdirectory should be "c:\VBWIRE\Forums\"). Instead, the initial directory keeps coming up as the path of the first file loaded.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.  
    4.         With SaveFileDialog1
    5.             .FileName = txtNewPlayer.Text
    6.             .DefaultExt = "nfl"
    7.             .Filter = "nfl files (*.nfl)|*.nfl|All files (*.*)|*.*)"
    8.             .FilterIndex = 1
    9.             .InitialDirectory = "C:\Player Information\" & cmbNewTeam.Text & "\" & cmbNewPosition.Text & "\"
    10.             .OverwritePrompt = True
    11.             .Title = "NFL Player Database - File Save"
    12.  
    13.         End With
    14.  
    15.         If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
    16.             strFileName = SaveFileDialog1.FileName
    17.             Dim objWriter As StreamWriter = New StreamWriter(strFileName, False)
    18.  
    19.             objWriter.WriteLine(txtNewPlayer.Text)
    20.             objWriter.WriteLine(cmbNewTeam.Text)
    21.             objWriter.WriteLine(cmbNewPosition.Text)
    22.             objWriter.WriteLine(cmbNewHeight.Text)
    23.             objWriter.WriteLine(txtNewWeight.Text)
    24.             objWriter.WriteLine(cmbNewQuality.Text)
    25.             objWriter.WriteLine(txtNewJerseyNumber.Text)
    26.             objWriter.Write(rtbNewInformation.Text)
    27.             objWriter.Close()
    28.             objWriter = Nothing
    29.         End If
    30.     End Sub
    31.  
    32.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    33.  
    34.  
    35.     End Sub
    36.  
    37.  
    38.     Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    39.  
    40.         With OpenFileDialog1
    41.             .Filter = "NFL files (*.nfl)|*.nfl|All files (*.*)|*.*"
    42.             .FilterIndex = 1
    43. ' This is where Im having the problem... works fine with save, but not open.
    44.             .InitialDirectory = "C:\Player Information\" & cmbNewTeam.Text & "\" & cmbNewPosition.Text & "\"
    45.             .Title = "NFL Player Database - File Open"
    46.          
    47.         End With
    48.  
    49.         If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
    50.             strFileName = OpenFileDialog1.FileName
    51.             Dim objReader As StreamReader = New StreamReader(strFileName)
    52.  
    53.             txtNewPlayer.Text = objReader.ReadLine
    54.             cmbNewTeam.Text = objReader.ReadLine
    55.             cmbNewPosition.Text = objReader.ReadLine
    56.             cmbNewHeight.Text = objReader.ReadLine
    57.             txtNewWeight.Text = objReader.ReadLine
    58.             cmbNewQuality.Text = objReader.ReadLine
    59.             txtNewJerseyNumber.Text = objReader.ReadLine
    60.             rtbNewInformation.Text = objReader.ReadToEnd
    61.             objReader.Close()
    62.             objReader = Nothing
    63.  
    64.         End If
    65.     End Sub


    Anyone have any ideas why it wont actively change to whatever the combobox text is?? Is there some kind of "clear" that I should put in there to reset it?
    Last edited by JAtkinson; Feb 11th, 2004 at 04:31 PM.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    take a look at RestoreDirectory , eg:
    VB Code:
    1. Dim sd As New SaveFileDialog() '/// public variable.
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.  
    5.         With sd
    6.             .InitialDirectory = "C:\"
    7.             .RestoreDirectory = True
    8.             .Filter = "textfiles|*.txt"
    9.             .FilterIndex = 1
    10.             .ShowDialog()
    11.         End With
    12.  
    13.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Lively Member JAtkinson's Avatar
    Join Date
    Feb 2004
    Location
    Richmond, VA
    Posts
    68
    Hmm, still not working...

    If I press the load button (with the comboboxes filled out) it will take me to the correct folder. If I hit cancel instead of actually opening the file, it will work properly. Only if I hit "OK" and open a file, and then try to open another file does it go to the wrong folder nomatter what the field is in the combobox.

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