Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question on ln in a for/next loop
#12
The global "ln" was probably passed to a Procedure(Sub). - A local "ln" is only known in this subprogram and has no effect on the program outside.

[Image: Variable-Lokal-Global-2024.jpg]

Why it is -2

Does the local variable also come before a "shared variable" in the main program? Test it!  Tongue

Code: (Select All)

'Beispiel lokale Variablen - 13. Sept. 2024

$Console:Only
Option _Explicit

Declare Sub Beispiel()
Declare Sub Beispiel2(ln As Integer)

Dim As Integer ln, speed(10)

For ln = 1 To 10
  speed(ln) = ln
  Print speed(ln)

  'Sonst ist ln = 11
  If ln = 10 Then
    Exit For
  End If
Next
Print: Print ln

Locate CsrLin + 1, 2
Call Beispiel

Locate CsrLin + 1, 2
Call Beispiel2(ln)
End

Sub Beispiel
  Dim As Integer i
  Dim As Single ln

  For i = 1 To 10
    ln = i * 1.36
    Print Using "##.##"; ln
    Locate CsrLin, 2
  Next
End Sub

Sub Beispiel2 (ln)

  Dim As Integer ln

  'Das lokale "ln" geht vor dem globalen
  ln = ln - 2
  Print ln
End Sub
Reply


Messages In This Thread
Question on ln in a for/next loop - by Dimster - 09-12-2024, 03:59 PM
RE: Question on ln in a for/next loop - by Petr - 09-12-2024, 05:25 PM
RE: Question on ln in a for/next loop - by LEM - 09-12-2024, 05:44 PM
RE: Question on ln in a for/next loop - by bplus - 09-13-2024, 12:45 AM
RE: Question on ln in a for/next loop - by bplus - 09-13-2024, 04:43 PM
RE: Question on ln in a for/next loop - by Pete - 09-13-2024, 06:23 PM
RE: Question on ln in a for/next loop - by Kernelpanic - 09-13-2024, 10:06 PM
RE: Question on ln in a for/next loop - by bplus - 09-13-2024, 10:26 PM



Users browsing this thread: 2 Guest(s)