SELECT CASES ???
#11
(10-16-2022, 10:28 PM)Pete Wrote:
(10-16-2022, 09:57 PM)SMcNeill Wrote: If it's a FUNCTION, then doesn't it need a return variable associated with it?

x = SatzLesen (or such)

That's the first thing you've been right about in the last 10 minutes. Either that or something like...
Code: (Select All)
PRINT SatzLesen

Pete

Unfortunately that didn't work at all.

There's the database, and I've changed the "Sub" to a function so that it returns the specified record number. The corresponding motorcycle should then be shown for each set number.
I couldn't find anything on the net about a function in a Select ... Case query. If it works with a sub, it must also work with a function, right? What kind of error is there just a complaint?

Code: (Select All)
$Console:Only

Option _Explicit

'Definition der Datenstruktur - Direktzugriff
Type MotorradModell
  Modell As String * 20
  Farbe As String * 10
  Hubraum As String * 10
  Kilowatt As String * 10
  Fahrgewicht As String * 10
  Preis As Double
End Type

'Global zur Verfuegung stellen, sonst wird es
'wirklich kompliziert
Dim Shared Motorrad As MotorradModell

Declare Sub Eingabe()
Declare Sub Lesen()
Declare Function SatzLesen(0)

Dim As Integer auswahl

Nochmal:
Cls
auswahl = 0
Locate 3, 4
Print "Waehlen Sie das gewuenschte Programm."
Locate 6, 10
Print "In Datei schreiben    -> 1"
Locate 7, 10
Print "Datei lesen           -> 2"
Locate 8, 10
Print "Bestimmten Satz lesen -> 3"
Locate 9, 10
Print "Programm beenden      -> 4"

Locate 11, 4
Input "Ihre Wahl bitte: ", auswahl
Print

Select Case auswahl
  Case 1
    Call Eingabe
  Case 2
    Call Lesen
  Case 3
    SatzLesen
  Case 4
    End
  Case Else
    Beep: Locate 12, 4
    Print "Falsche Eingabe!"
    Sleep 1
    GoTo Nochmal
End Select

End 'Hauptprogramm

'Neue Datei erstellen und Daten einlesen
Sub Eingabe

  Dim As Integer SatzNummer
  Dim As String Antwort

  Open "Motorrad.Dat" For Random As #1 Len = Len(Motorrad)

  SatzNummer = LOF(1) \ Len(Motorrad)

  'Neue Datensaetze hinzufuegen
  Do
    Input "Modell     : ", Motorrad.Modell
    Input "Farbe      : ", Motorrad.Farbe
    Input "Hubraum    : ", Motorrad.Hubraum
    Input "Kilowatt   : ", Motorrad.Kilowatt
    Input "Fahrgewicht: ", Motorrad.Fahrgewicht
    Input "Preis      : ", Motorrad.Preis

    SatzNummer = SatzNummer + 1

    'Datensatz in Datei schreiben
    Put #1, SatzNummer, Motorrad

    'Sollen weitere Daten eingegeben werden?
    Input "Weiter J/N: ", Antwort$
  Loop Until UCase$(Antwort$) = "N"

  Close 1#
End Sub

'Datensaetze sequentiell auslesen (alle)
Sub Lesen

  Dim As Integer AnzahlSaetze, SatzNummer

  Open "Motorrad.Dat" For Random As #1 Len = Len(Motorrad)

  'Anzahl der Datensaetze berechnen
  AnzahlSaetze = LOF(1) \ Len(Motorrad)

  'Datensaetze lesen und anzeigen
  For SatzNummer = 1 To AnzahlSaetze
    Get #1, SatzNummer, Motorrad

    'Daten anzeigen
    Print Tab(4); "Modell     : ", Motorrad.Modell
    Print Tab(4); "Farbe      : ", Motorrad.Farbe
    Print Tab(4); "Hubraum    : ", Motorrad.Hubraum
    Print Tab(4); "Kilowatt   : ", Motorrad.Kilowatt
    Print Tab(4); "Fahrgewicht: ", Motorrad.Fahrgewicht
    Print Tab(4); Using "Preis      : #####.##"; Motorrad.Preis
    Print
    Print Tab(4); "---------------------------------"
    Print
  Next

  Close 1#
End Sub

Function SatzLesen ()

  Const Falsch = 0, Wahr = Not Falsch
  Dim As Integer AnzahlSaetze, BestimmterSatz, SatzNummer

  Open "Motorrad.Dat" For Random As #1 Len = Len(Motorrad)

  'Anzahl der Datensaetze berechnen
  AnzahlSaetze = LOF(1) \ Len(Motorrad)
  BestimmterSatz = Wahr

  Do
    Print
    Print Tab(4); "Satznummer: ";
    Print "(Null zum Beenden): ";
    Input " ", SatzNummer

    'Warum "AnzahlSaetze + 1"? War intuitiv!
    If SatzNummer > 0 And SatzNummer < AnzahlSaetze + 1 Then
      Get #1, SatzNummer, Motorrad

      'Bestimmten Datenssatz anzeigen
      Print
      Print Tab(4); "Modell     : ", Motorrad.Modell
      Print Tab(4); "Farbe      : ", Motorrad.Farbe
      Print Tab(4); "Hubraum    : ", Motorrad.Hubraum
      Print Tab(4); "Kilowatt   : ", Motorrad.Kilowatt
      Print Tab(4); "Fahrgewicht: ", Motorrad.Fahrgewicht
      Print Tab(4); Using "Preis      : #####.##"; Motorrad.Preis
    ElseIf SatzNummer = 0 Then
      AnzahlSaetze = Falsch
    Else
      Print: Print: Beep: Print Tab(4); "Satznummer ausserhalb des Bereichs!"
    End If
  Loop While BestimmterSatz = 0
  SatzLesen = SatzNummer
End Function
Reply


Messages In This Thread
SELECT CASES ??? - by Pete - 10-16-2022, 07:55 PM
RE: SELECT CASES ??? - by SMcNeill - 10-16-2022, 08:48 PM
RE: SELECT CASES ??? - by mnrvovrfc - 10-17-2022, 07:40 AM
RE: SELECT CASES ??? - by James D Jarvis - 10-16-2022, 08:49 PM
RE: SELECT CASES ??? - by SMcNeill - 10-16-2022, 09:07 PM
RE: SELECT CASES ??? - by Pete - 10-16-2022, 09:01 PM
RE: SELECT CASES ??? - by Pete - 10-16-2022, 09:12 PM
RE: SELECT CASES ??? - by SMcNeill - 10-16-2022, 09:23 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-16-2022, 09:35 PM
RE: SELECT CASES ??? - by SMcNeill - 10-16-2022, 09:57 PM
RE: SELECT CASES ??? - by Pete - 10-16-2022, 10:28 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-16-2022, 10:44 PM
RE: SELECT CASES ??? - by SpriggsySpriggs - 10-16-2022, 11:06 PM
RE: SELECT CASES ??? - by Pete - 10-16-2022, 11:42 PM
RE: SELECT CASES ??? - by SMcNeill - 10-17-2022, 01:34 AM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 02:04 AM
RE: SELECT CASES ??? - by SpriggsySpriggs - 10-17-2022, 02:46 AM
RE: SELECT CASES ??? - by mnrvovrfc - 10-17-2022, 07:48 AM
RE: SELECT CASES ??? - by dbox - 10-17-2022, 03:46 AM
RE: SELECT CASES ??? - by SMcNeill - 10-17-2022, 05:21 AM
RE: SELECT CASES ??? - by DSMan195276 - 10-17-2022, 06:32 AM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 06:41 AM
RE: SELECT CASES ??? - by DSMan195276 - 10-17-2022, 07:34 PM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 08:28 AM
RE: SELECT CASES ??? - by RhoSigma - 10-17-2022, 09:29 AM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 07:00 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-17-2022, 08:15 PM
RE: SELECT CASES ??? - by SMcNeill - 10-17-2022, 09:44 PM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 09:45 PM
RE: SELECT CASES ??? - by SMcNeill - 10-17-2022, 09:50 PM
RE: SELECT CASES ??? - by Pete - 10-17-2022, 10:05 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-18-2022, 08:07 PM
RE: SELECT CASES ??? - by Pete - 10-18-2022, 08:38 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-18-2022, 08:49 PM
RE: SELECT CASES ??? - by Pete - 10-18-2022, 09:33 PM
RE: SELECT CASES ??? - by Kernelpanic - 10-19-2022, 06:32 PM
RE: SELECT CASES ??? - by Pete - 10-19-2022, 06:39 PM



Users browsing this thread: 5 Guest(s)