| ComboBox, Image, Type, Common Dialog |
| |
| |
| Const pfadt$ = "D:\Graphics\Metafile\Business\" | Konstante für Pfad der Grafik verwenden. |
| Const max% = 10 | Array mit zehn Feldern deklarieren. |
| |
| Private Type TPerson | Nutzerdefinierter Datentyp. |
| intNr As Integer | Zähler (Kundennummer). |
| strName As String | Nachname. |
| strVorname As String | Vorname. |
| strTel As String | Telefonnummer. |
| strBild As String | Bild, Photo... |
| End Type | |
| | |
| Private liste(1 To max) As TPerson | Definieren der Strukturvariablen. |
| Private pos% | |
| |
| Private Sub Form_Load() | Formular wird geladen. |
| Dim index% | |
| pos = 1 | |
| imgFoto.Stretch = True | |
| | |
| With frmAdress | Startgröße des Formulars festlegen. |
| .Height = 3000 | |
| .Width = 3800 | |
| End With | |
| For index = 1 To max | Array mit Werten füllen. |
| With liste(index) | |
| .intNr = Val(index) | |
| .strName = index & " Huber" | |
| .strVorname = "Hans" | |
| .strTel = "0123/45678" | |
| .strBild = pfadt & "Harddisk.wmf" | |
| End With | |
| cboName.AddItem Val(index) & " Huber", index - 1 | Laden der ComboBox. |
| Next index | |
| Call anzeigen | |
| End Sub | |
| |
| Private Sub anzeigen() | Array füllt Werte in die Textboxen. |
| cboName = liste(pos).strName | |
| txtNr = Str$(pos) | |
| txtVorname = liste(pos).strVorname | |
| txtTel = liste(pos).strTel | |
| imgFoto.Picture = LoadPicture(liste(pos).strBild) | |
| End Sub | |
| |
| Private Sub cmdSuch_Click() | Suchprogramm starten. |
| Dim strVergleich As String | |
| strVergleich = txtSuch.Text | Variable = Text in TextBox. |
| Call suchen(strVergleich) | Prozedur "Suchen" wird aufgerufen. |
| End Sub | |
| |
| Private Sub suchen(ByVal strSu As String) | Prozedur "Suchen". |
| Dim index As Integer | |
| Dim counter As Integer | |
| Dim gefunden(10) As TPerson | |
| Dim strAus As String | |
| counter = 0 | |
| index = 1 | |
| Call speichern | |
| |
| While index <= max | |
| If LCase(strSu) Like LCase(liste(index).strName) Or _ | LCase wandelt alle Buchstaben in Kleinbuchstaben um. |
| LCase(strSu) Like LCase(liste(index).strVorname) Then | |
| counter = counter + 1 | |
| gefunden(counter) = liste(index) | |
| index = index + 1 | |
| Else | |
| index = index + 1 | |
| End If | |
| Wend | |
| If counter <> 0 Then | Ausgabe der gefundenen Werte als Strings in MsgBox. |
| For index = 1 To counter | |
| strAus = strAus & gefunden(index).strName & " " & gefunden(index).strVorname _ |
| & " " & gefunden(index).strTel & " " & vbCrLf | |
| Next index | |
| MsgBox strAus, vbInformation, "Suche" | |
| Else | |
| MsgBox "Der Name wurde nicht gefunden", vbInformation, "Suche" |
| End If | |
| End Sub | |
| |
| Private Sub speichern() | Änderungen ins Array speichern. |
| liste(pos).intNr = Val(txtNr.Text) | |
| liste(pos).strName = cboName.Text | |
| liste(pos).strVorname = txtVorname.Text | |
| liste(pos).strTel = txtTel.Text | |
| End Sub | |
| |
| Private Sub cmdErweitert_Click() | Das Formular wird vergrößert, um das Bildfeld anzuzeigen. |
| With frmAdress | |
| .Height = 3450 | |
| .Width = 7100 | |
| End With | |
| cmdErweitert.Visible = False | |
| End Sub | |
| |
| Private Sub cmdWeniger_Click() | Das Formular wird verkleinert. |
| With frmAdress | |
| .Height = 3000 | |
| .Width = 3800 | |
| End With | |
| cmdErweitert.Visible = True | |
| End Sub | |
| |
| Private Sub cmdRueck_Click() | Zurückblättern im Array. |
| If pos < max Then | |
| Call speichern | Vorher wird gespeichert. |
| pos = pos + 1 | |
| Call anzeigen | |
| Else | |
| MsgBox "Sie befinden sich am Ende", vbInformation, "Info" | |
| End If | |
| End Sub | |
| |
| Private Sub cmdVor_Click() | Vorblättern im Array. |
| If pos > 1 Then | |
| Call speichern | Vorher wird gespeichert. |
| pos = pos - 1 | |
| Call anzeigen | |
| Else | |
| MsgBox "Sie befinden sich am Anfang", vbInformation, "Info" | |
| End If | |
| End Sub | |
| |
| Private Sub imgFoto_Click() | Bei Klick aus das Bildfeld kann ein Bild ins Feld |
| dialog.ShowOpen | geladen werden. |
| imgFoto.Picture = LoadPicture(dialog.FileName) | |
| liste(pos).strBild = dialog.FileName | |
| Call speichern | |
| End Sub | |
| |
| Private Sub cboName_Click() | Bei Klick in das Auswahlfeld der ComboBox wird der |
| pos = cboName.ListIndex + 1 | entsprechende Eintrag geladen. |
| Call anzeigen | |
| End Sub | |
| | |
| |
| |
| |
| |
| |
| |
| |
| . |
| |