0% found this document useful (0 votes)
43 views5 pages

Private Sub Byval As String If False Then Else Dim As: "File Not Found: "

The document discusses the use of Do While and Do Until loops in Visual Basic code. It provides examples of using these loops to iterate through a range of numbers, change the background color of a form, and read user input in a loop until a condition is met. The key aspects covered are the syntax of the loops, how they differ in their condition checking, and examples of implementing them.

Uploaded by

Aderly Yanqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

Private Sub Byval As String If False Then Else Dim As: "File Not Found: "

The document discusses the use of Do While and Do Until loops in Visual Basic code. It provides examples of using these loops to iterate through a range of numbers, change the background color of a form, and read user input in a loop until a condition is met. The key aspects covered are the syntax of the loops, how they differ in their condition checking, and examples of implementing them.

Uploaded by

Aderly Yanqui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Private Sub ShowText(ByVal textFilePath As String)

If System.IO.File.Exists(textFilePath) = False Then


Debug.WriteLine("File Not Found: " & textFilePath)
Else
Dim sr As System.IO.StreamReader =
System.IO.File.OpenText(textFilePath)
Do While sr.Peek() >= 0
Debug.WriteLine(sr.ReadLine())
Loop
sr.Close()
End If
End Sub

Dim index As Integer = 0


Do While index <= 100
If index > 10 Then
Exit Do
End If
Debug.Write(index.ToString & " ")
index += 1
Loop
Debug.WriteLine("")
' Output: 0 1 2 3 4 5 6 7 8 9 10
Dim index As Integer = 0
Do While index <= 10
Debug.Write(index.ToString & " ")
index += 1
Loop
Debug.WriteLine("")
' Output: 0 1 2 3 4 5 6 7 8 9 10

Module calcolaMedia
Sub Main()
Dim Totale As Integer = 0
Dim contatore As Integer = 0
Dim media As Integer
Console.Write("Digita -1 per uscire")
Totale = numero
Do While (numero <> -1)
Console.Write("Numero: ")

Numero = Console.ReadLine()
Totale += numero
contatore += 1
Loop
If (contatore <> 1) Then
Console.WriteLine("La media : " & Totale / (contatore - 1) )
Else
Console.WriteLine("Non hai inserito nessun valore")
End If
End Sub
End Module

Module modTestExit
Sub Main()
Dim output As String = ""
Dim contatore As Integer
For contatore = 1 To 10
If contatore = 5 Then
Exit For
End If
Next
Console.WriteLine("Uscito da for: contatore = " & contatore)
Do Until contatore > 10
If contatore = 8 Then
Exit Do
Contatore += 1
Loop
Console.WriteLine("Uscito da do: contatore = " & contatore)
End Sub
End Module

'Learn how to use a Do While Loop.

Private Sub Form_Load()


'display the numbers from 0 to 9

Dim i As Integer
'method 1
Do While (i < 10)
Text1.Text = Text1.Text & i & ","
i = i + 1
Loop
i = 0 ' reset i
'method 2
Do
Text2.Text = Text2.Text & i & ","
i = i + 1
Loop While (i < 10)
End Sub
' Let us take a closer look at our do while loop:
'---------------------------------------------------------------'
Do While (i < 10)
'
Text1.Text = i
'
i = i + 1
'
Loop
'---------------------------------------------------------------' Do While - do while loop
' i < 10

- loop while i less than 10

' i=i+1

- increment o

' Loop
- loop while i less than 10
'---------------------------------------------------------------'Description:
'Loop until argument is set.
'Warning! The do while loop can crash your program if "done wrong".
'----------------------------------------------------------------------------

Module Module1
Sub Main()
Dim num As Integer = 0
Do
Console.WriteLine("Introduce un nmero entre 0 y 10")
num = Console.ReadLine()
Loop While num >= 10 Or num < 0

Console.WriteLine("El numero introducido con Loop While es

" &

num)
Do
Console.WriteLine("Introduce un nmero entre 0 y 10")
num = Console.ReadLine()
Loop Until num <= 10 Or num > 0
Console.WriteLine("El numero introducido con Loop Until es
num)
Console.ReadLine()
End Sub
End Module

1. Private Sub Command1_Click( )


Dim Control as Long
On Error Resume Next
Control = Text1.Text
Form1.BackColor = vbWhite
Do While Control <> 0
Label2.Caption = Valor: & Control
If Form1.BackColor = vbWhite Then
Form1.BackColor = vbRed
Else
Form1.BackColor = vbWhite
End If
Control = Text1.Text
DoEvents
Loop
MsgBox Loop completado
End Sub

Private Sub Command1_Click( )


Dim Control as Long
On Error Resume Next
Control = Text1.Text
Form1.BackColor = vbWhite
Do Until Control = 0
Label2.Caption = Valor: & Control
If Form1.BackColor = vbWhite Then
Form1.BackColor = vbRed
Else

" &

Form1.BackColor = vbWhite
End If
Control = Text1.Text
DoEvents
Loop
MsgBox Loop completado
End Sub

You might also like