Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Record Arrays
#1
So, using arrays as record elements is not possible in QB. OK, but declaring record arrays is also possible in QB.

I've tried this according to the QBasic manual, only a rudimentary guide, but something isn't working. The program runs without errors, but there is no meaningful output. I'm thinking wrong.

Code: (Select All)

Type Motorrad
  Modell As String * 30
  Kilowatt As Double
  Preis As Double
End Type

Dim MotorradMarken(2) As Motorrad

Dim As Integer anzahl, satzNummer

satzNummer = 1
Do
  Input "Modell    : ", Motorrad.Modell
  Input "Kilowatt  : ", Motorrad.Kilowatt
  Input "Preis      : ", Motorrad.Preis

  satzNummer = satzNummer + 1
Loop Until satzNummer = 2

For anzahl = 1 To satzNummer
  Print MotorradMarken(anzahl).Modell
  Print MotorradMarken(anzahl).Kilowatt
  Print MotorradMarken(anzahl).Preis
Next

[Image: Record-Array2024-07-01.jpg]

Does anyone know where the error is? Thanks!
Reply
#2
If you add `Optiion _Explicit` to your program you might realize what the issue is Smile

Your input lines should be using names similar to `MotorradMarken(satzNummer).Modell` for each line, so that the input is read into the array entries. With what you have right now, `Motorrad.Modell` is just treated like the name of a regular variable and QB64 simply creates the `Motorad.Modell` variable for you with the default `Single` type, completely separate from the array you declared.
Reply
#3
missing index too in the inputs

this is fixed unless you want to actually input 2 sets of data
Code: (Select All)
Type Motorrad
    Modell As String * 30
    Kilowatt As Double
    Preis As Double
End Type

Dim MotorradMarken(2) As Motorrad

Dim As Integer anzahl, satzNummer

satzNummer = 1
Do
    Input "Modell    : ", MotorradMarken(satzNummer).Modell
    Input "Kilowatt  : ", MotorradMarken(satzNummer).Kilowatt
    Input "Preis      : ", MotorradMarken(satzNummer).Preis

    satzNummer = satzNummer + 1
Loop Until satzNummer = 2 'or 3?

For anzahl = 1 To satzNummer - 1
    Print MotorradMarken(anzahl).Modell
    Print MotorradMarken(anzahl).Kilowatt
    Print MotorradMarken(anzahl).Preis
Next
b = b + ...
Reply
#4
(07-01-2024, 08:48 PM)DSMan195276 Wrote: If you add `Optiion _Explicit` to your program you might realize what the issue is
NEVER write QB64 programs without the first line of your code being:

OPTION _EXPLICIT

I have been saved countless times from typos by this one line of code.

It should be the default behavior of the IDE (in my opinion) with an option to turn it off when viewing QB64 or legacy code written by someone else that didn't use it:

_EXPLICIT _OFF

for example.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#5
Thanks for the answers. I'll look into it tomorrow... I think I've had one glass of wine too many today.  Big Grin Thanks!
Reply
#6
there's always room for one more glass Tongue
Reply
#7
Thanks again for the tips, I was totally off track yesterday.
Now it works also with the display of the book in question. It's not really "practical" yet, but it works.

Code: (Select All)

'Recordarray Uebung mit Buechern mit Bildanzeige - 2. Juli 2024

'$Console:Only
Option _Explicit

Type Buecher
  Buchtitel As String * 30
  Autor As String * 30
  ISBN As String * 20
  Preis As String * 6
End Type

Dim Buchbestand(10) As Buecher

Dim As Integer anzahl, satzNummer, bildNummer

satzNummer = 1
Locate 2, 3
Do
  Locate CsrLin, 3
  Input "Buchtitel : ", Buchbestand(satzNummer).Buchtitel
  Locate CsrLin, 3
  Input "Autor    : ", Buchbestand(satzNummer).Autor
  Locate CsrLin, 3
  Input "ISBN      : ", Buchbestand(satzNummer).ISBN
  Locate CsrLin, 3
  Input "Preis    : ", Buchbestand(satzNummer).Preis

  satzNummer = satzNummer + 1
  Print: Print
Loop Until satzNummer = 3

'Zwei Sekunden Pause, dann Anzeige
Sleep 2

Cls
Locate CsrLin + 1, 3
bildNummer = 1
For anzahl = 1 To satzNummer - 1
  Print Tab(3); "Buchtitel: ", Buchbestand(anzahl).Buchtitel
  Print Tab(3); "Autor    : ", Buchbestand(anzahl).Autor
  Print Tab(3); "ISBN    : ", Buchbestand(anzahl).ISBN
  Print Tab(3); "Preis    : ", Buchbestand(anzahl).Preis
  If bildNummer = 1 Then
    _Clipboard$ = "Revolusi.jpg"
    Shell "BildAnzeigen.exe"
  ElseIf bildNummer = 2 Then
    _Clipboard$ = "Tsushima.jpg"
    Shell "BildAnzeigen.exe"
  End If
  Print: Print Tab(3); "Druecken Sie eine Taste fuer weiter."
  Sleep
  bildNummer = bildNummer + 1
  Print
Next

End

Show picture.
Code: (Select All)

'Programm 2 (benenne und speichere dieses als Bild.bas und kompiliere es als Bild.exe)
'Wird von "BildAufrufen" aufgerufen. - Name muss mit dem Aufruf uebereinstimmen.
'Autor Pete - 19. Oktober 2022

Dim Bild As Long
Dim As String myBild

myBild = _Clipboard$
If _Trim$(myBild) = "" Then System ' Nothing got transferred.

Screen _NewImage(650, 750, 32)

Cls
'Neue Farbe setzen
Color _RGB32(255, 165, 0), _RGB32(0, 0, 0)

Bild = _LoadImage(myBild)

'Neues Fenster - Bildgroesse fuer mittig
'_PutImage (((800 - 689) / 2), ((500 - 459) / 2)), Bild
_PutImage (((650 - 540) / 2), ((750 - 660) / 2)), Bild

End

Display:
[Image: Buch-Revolusi2024-07-02.jpg]

[Image: Buch-Tsushima.jpg]
Reply




Users browsing this thread: 3 Guest(s)