|
Ein Programm in der Programmiersprache | A program in the programming language | |||
Visual BASIC | ||||
zum Öffnen von Datei- und Verzeichnis-Auswahlfenstern | for opening of file- and folder-select windows | |||
Mit VB-Script konnten ebenfalls Datei-Auswahl-Fenster programmiert werden, aber seit Windows Vista geht das nicht mehr. Hier ist dazu ein Programm in Visual Basic für XP und Windows 7, für Datei-Auswahl, Datei-Sicherung und Verzeichnis-Auswahl, der erste Absatz zeigt eine Routine zur Ermittlung von den sog. Windows-System-Spezial-Verzeichnissen, die als Initial-Verzeichnis für die Auswahlfenster ausgewählt werden können. Da man mit der Datei-Auswahl mehrere Dateien auswählen kann, so wird an das "Programm" ein Array übergeben. Daher wird bei der Datei-Sicherung und der Verzeichnis-Auswahl der Wert der Ausgabe-Variablen ebenfalls in Form eines Arrays übergeben. Das Programm erkennt dann, was es tun soll. | By VB-Script could be programmed File-Select-Windows too, but since Windows Vista this does not work any longer. Here is a program in Visual Basic for XP and Windows 7, for File-Select, File-Save and Folder-Select, the first paragraph shows a routine for getting the so-called Windows-System-Special-Folders, which can be selected as initial-folders for the select-windows. Because one can choose several files with the file-selection, it is handed over an array to the "Program". Therefor by the file-saving and by the browse-folder there is the value of the output-variable handed over likewise in form of an array. The program recognises, what is has to do. | |||
Das Programm ist getestet vor der Publikation, aber es kann keine Garantie gegeben werden, dass es fehlerfrei ist | The program ist tested before publication, but there can be given no guarantee, that it is free of errors | |||
28. April 2011 | April 28th 2011 |
Public Class Form1 Public SpFolder Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' Special Folders: ' AllUsersDesktop AllUsersStartMenu AllUsersPrograms ' AllUsersStartup Desktop Favorites ' Fonts MyDocuments NetHood ' PrintHood Recent SendTo ' StartMenu Startup Templates Dim WSH WSH = CreateObject("WScript.Shell") SpFolder = WSH.SpecialFolders("MyDocuments") MsgBox("SpecialFolder" & vbCrLf & SpFolder) End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Dim Diag = "OpenFile" Dim Results = OpenFileDiag() Program(Results, Diag) End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click Dim Diag = "SaveFile" Dim Results(0) : Results(0) = SaveFileDiag() Program(Results, Diag) End Sub Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click Dim Diag = "BrowseFolder" Dim Results(0) : Results(0) = FolderBrowserDiag() Program(Results, Diag) End Sub Private Sub Button4_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button4.Click Me.DialogResult = System.Windows.Forms.DialogResult.OK Me.Visible = False Me.Close() End Sub Function OpenFileDiag() Dim Filelist Dim OpenFileDialog As New OpenFileDialog() Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog With Me.OpenFileDialog1 .Title = "Open the File" .Filter = "txt files (*.txt)|*.txt|html files (*.htm*)|*.htm*" .FilterIndex = 2 .Multiselect = True .RestoreDirectory = True Dim result As DialogResult = .ShowDialog If result = Windows.Forms.DialogResult.OK Then Filelist = .FileNames Else ReDim Filelist(0) : Filelist(0) = "" End If End With OpenFileDiag = Filelist End Function Function SaveFileDiag() Dim Filename = "" Dim SaveFileDialog As New SaveFileDialog() Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog With Me.SaveFileDialog1 .Title = "Save the File" .Filter = "txt files (*.txt)|*.txt|html files (*.htm*)|*.htm*" .FilterIndex = 2 .RestoreDirectory = True Dim result As DialogResult = .ShowDialog If result = Windows.Forms.DialogResult.OK Then Filename = .FileName End If End With SaveFileDiag = Filename End Function Function FolderBrowserDiag() Dim folderName = "" Dim FolderBrowserDialog As New FolderBrowserDialog() Me.FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog() With Me.FolderBrowserDialog1 .Description = "Select a Destination Folder" .SelectedPath = SpFolder .ShowNewFolderButton = True Dim result As DialogResult = .ShowDialog If result = Windows.Forms.DialogResult.OK Then folderName = .SelectedPath End If End With FolderBrowserDiag = folderName End Function Sub Program(ByVal AnyArray, ByVal AnyDiag) Dim i For i = 0 To UBound(AnyArray) Select Case AnyDiag Case "OpenFile" 'Program here Case "SaveFile" 'Program here Case "BrowseFolder" 'Program here End Select MsgBox(AnyArray(i), , AnyDiag & "-Dialog-Result:") Next End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged End Sub Private Sub Button6_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button6.Click End Sub Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, _ ByVal e As System.ComponentModel.CancelEventArgs) End Sub Private Sub FolderBrowserDialog1_HelpRequest(ByVal sender As System.Object, _ ByVal e As System.EventArgs) End Sub Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, _ ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk End Sub Private Sub GroupBox1_Enter(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles GroupBox1.Enter End Sub End Class | ||