Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do FOR/NEXT variables end up +1 more?
#11
It's amazing what one can all do in this case. That's fun! - And everything goes back to a For loop.  Tongue

Calling a Sub procedure and/or an EXE file.

PS: Damn, if one enter "n" it doesn't work. I'll take a look tomorrow.

Code: (Select All)

'Aus einer While-Schleife eine Sub-Prozedur aufrufen - 25. Aug. 2023

$Console:Only
Option _Explicit

Declare Sub Berechnen(eingabe As Integer)

Dim As Integer i, eingabe, modBedingung
Dim As String antwort

Print
Print "While-Schleife wird bis zur Eingabe durchlaufen, wobei"
Print "bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt."

Print
Input "Eingabe  : ", eingabe
Input "Modangabe: ", modBedingung
Print: Print

'While-Schleife wird bis zur Eingabe durchlaufen, wobei
'bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt
'Ergaenst um Aufruf eines externen Programms, wenn Bedingung erfuellt
i = 1
While i < eingabe
  i = i + 1
  If i Mod modBedingung = 0 Then
    Berechnen (i)
  ElseIf i Mod 23 = 0 Then
    Do
      Print
      Input "Weiter J/N: ", antwort
    Loop Until UCase$(antwort$) = "J"
    Run "D:\Lab\QuickBasic64\Finanz+Mathe\Geometrie\Rechtwinkliges-Dreieck-Hypo.exe"
  End If
Wend

End 'Hauptprogramm

Sub Berechnen (eingabe As Integer)

  eingabe = eingabe * 3
  Print Using "Ergebnis = ###"; eingabe
End Sub

The called EXE file:
Code: (Select All)

'Berechnungen am rechtwinkligen Dreieck - 5. August 2023
'https://qb64phoenix.com/qb64wiki/index.php/HYPOT

Option _Explicit

Dim As Double ankathede, gegenkathede, hypotenuse
Dim As Double hoehe_c, flaecheninhalt, umfang

Locate 2, 3
Input "Laenge der Ankathede(cm)  : ", ankathede
Locate 3, 3
Input "Laenge der Gegenkathede(cm): ", gegenkathede

hypotenuse = _Hypot(ankathede, gegenkathede)

Locate 5, 3
Print Using "Die laenge der Hypotenuse im Dreiceck betraegt: ###.## cm"; hypotenuse

'Hoehe hc und Flaecheninhalt im rechtwinkligen Dreieck
hoehe_c = ((ankathede * gegenkathede) / hypotenuse)
flaecheninhalt = ((hypotenuse * hoehe_c) / 2)
umfang = ankathede + gegenkathede + hypotenuse

Locate 7, 3
Print Using "Der Umfang dieses Dreiecks betraegt          : ###.## cm"; umfang
Locate 8, 3
Print Using "Der Flaecheninhalt dieses Dreiecks betraegt  : ###.## qcm"; flaecheninhalt

End

[Image: While-Prozeduren.jpg]
Reply
#12
Deleted!
Reply
#13
The easiest way to exit ON a number is just with a simple DO loop.


start = 10
finish = 20
increment = +1
DO
    'Whatever you want to repeat
    start = start + increment
    'Post increment work stuff, if desired
LOOP UNTIL start >= finish
Reply
#14
(08-26-2023, 12:57 AM)SMcNeill Wrote: The easiest way to exit ON a number is just with a simple DO loop.
start = 10
finish = 20
increment = +1
DO
    'Whatever you want to repeat
    start = start + increment
    'Post increment work stuff, if desired
LOOP UNTIL start >= finish
Thanks! Is also a possibility - I had tried it with Sleep 10. But I didn't like it because the user should decide when to continue. Now I found it. This is how it works as desired:

Code: (Select All)

'Aus einer While-Schleife eine Sub-Prozedur aufrufen - 25./26. Aug. 2023

$Console:Only
Option _Explicit

Declare Sub Berechnen(eingabe As Integer)

Dim As Integer i, eingabe, modBedingung
Dim As String antwort

Print
Print "While-Schleife wird bis zur Eingabe durchlaufen, wobei"
Print "bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt."

Print
Input "Eingabe  : ", eingabe
Input "Modangabe: ", modBedingung
Print: Print

'While-Schleife wird bis zur Eingabe durchlaufen, wobei
'bei Mod 7 = 0 jedesmal eine Ausgabe erfolgt
'Ergaenst um Aufruf eines externen Programms, wenn Bedingung erfuellt
i = 1
While i < eingabe
  i = i + 1
  If i Mod modBedingung = 0 Then
    Berechnen (i)
  ElseIf i Mod 23 = 0 Then
    Print
    Input "Weiter J/N: ", antwort
    If UCase$(antwort) = "J" Then
      Run "D:\Lab\QuickBasic64\Finanz+Mathe\Geometrie\Rechtwinkliges-Dreieck-Hypo.exe"
    Else
      Exit While
    End If
  End If
Wend

End 'Hauptprogramm

Sub Berechnen (eingabe As Integer)

  eingabe = eingabe * 3
  Print Using "Ergebnis = ###"; eingabe
End Sub
Reply
#15
An addition to make the output more understandable.

Code: (Select All)

While i < eingabe
  i = i + 1
  If i Mod modBedingung = 0 Then
    Berechnen (i)
  ElseIf i Mod 23 = 0 Then
    Print
    Print "Bricht bei Eingabe MOD 23 = 0 ab!"
    Print
    Input "Weiter J/N: ", antwort
    If UCase$(antwort) = "J" Then
      Run "D:\Lab\QuickBasic64\Finanz+Mathe\Geometrie\Rechtwinkliges-Dreieck-Hypo.exe"
    Else
      Exit While
    End If
  End If
Wend

[Image: While-MOD2023-08-26.jpg]
Reply




Users browsing this thread: 1 Guest(s)