2017-08-18 1 views
0

私があなたを助けてくれることを願っています。電話番号とテキスト返信

enter image description here

画像は実際にプログラムを実行するために必要なものを示していますが、コードが正しく動作しません。

Imports System.Text.RegularExpressions 
 

 
Public Class Form1 
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
 
     FolderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) & "" 
 
     If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then     
 
      TextBox1.Text = FolderBrowserDialog1.SelectedPath 
 
      Dim str As String = TextBox1.Text 
 
      Dim dir As Match = Regex.Match(str, "\\([^\\]+)\\") 
 
      Dim count = TextBox1.Text.Count(Function(x) x = "\")       
 
      TextBox2.Text = dir.Groups(count - 2).ToString  
 
     End If 
 
    End Sub 
 
End Class

+0

_Iがループに入ってit_から抜け出すことができません。何のループ?イメージは、フォームの名前を指定していないか、ボタンを押すか、テキストボックスの横にラベルを貼っているので、プログラムが何をしているかを実際には説明していません。あなたのプログラムは何をしようとしていますか?実行中にコードエラーが発生している場合、エラーが発生しましたか? –

+0

@ Cal-cium。私はイメージを更新しました。 エラーはありません。 TextBox2では「デスクトップ」ではなく「ユーザー」が終了しません –

答えて

0

私はあなたの次のコードは、あなたが探している動作を与える、頼む理解している場合:

Public Class Form1 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    FolderBrowserDialog1.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) 
    If (FolderBrowserDialog1.ShowDialog() = DialogResult.OK) Then 
     Dim strFullPath As String = FolderBrowserDialog1.SelectedPath 
     TextBox1.Text = Mid(strFullPath, InStrRev(strFullPath, "\") + 1) 
     TextBox2.Text = strFullPath 
    End If 
End Sub 
End Class 
+0

ありがとうございます!!! –