Understanding For, Do, and while Loops

Level:
Level1

In our tutorial about if statements in Visual Basic 6 (Understanding if statements and conditions in VB6) we describe how conditional statements work - these can be used in loops as while so if you have not read that tutorial please do so now. Now continueing on with our original problem we described in our if statement tutoria how do we generate the Fibonacci series. Its formula is relatively simple:
  1. Let x = 1, let y = 0.
  2. Print x.
  3. Let x = y + x
  4. Let y = x - y
  5. Repeat from 2.

This pseudo code will print out: 1, 1, 2, 3, 5, 8, 13, 21, ... as expected. But now how do we tell a Visual Basic program how to do this? The answer lies in using loops.

Loops provide the ability to repeatedly execute the same block of code, and to each time change values such that each run through the loop produces different results. Visual Basic provides four main kinds of loops: the classic Do-Loop, the Do-Until Loop, the Do-While Loop, and the For-Next Loop.


Do-Loops

The most basic form of loop in Visual Basic is the Do-Loop. Its construct is very simple:

Do
    (Code to execute)
Loop

This, quite simply, executes the block of code, and when it reaches Loop, returns to the beginning of the Do Loop and executes the same block of code again. The same block of code will be repeatedly executed until it is told to stop executing. So let's try to apply this to our problem of generating the Fibonacci series:

Dim X As Integer
Dim Y As Integer
   
Do
   Debug.Print X
   
   X = Y + X
   Y = X - Y
Loop

 

And, believe it or not, this code works! Well, sorta. If you try to run this code, it will indeed generate the Fibonacci series; however, it will continually generate and print out the next number infinitely--or, in this case, until it reaches an overflow error. This is known as the problem of the infinite do-loop, one that all programmers will experience, and some quite frequently.

Exit Do 

So we clearly need some way to escape from the Do-Loop. You could, of course, simply End the program once you have calculated enough values, but what if you still need to perform tasks after you're done calculating? The answer is to use the Exit Do statement. Whenever your program reaches an Exit Do statement within a loop, it will exit the current loop.

So, let's try a somewhat different approach to the Fibonacci problem. We decide that we want to calculate only eight values of the Fibonacci series, so we'll keep a counter and increment it each time throughout the loop. Then, once the counter reaches eight, we'll exit the loop.

Public Sub Main()
   Dim X As Integer
   Dim Y As Integer
   Dim cnt As Integer 'Our counter.
   cnt = 1
   Do
      Debug.Print X
      X = Y + X
      Y = X - Y
   
      If cnt >= 8 Then
         Exit Do
      Else
         cnt = cnt + 1
      End If
   Loop
End Sub

And now we're talking! This program successfully computes and prints out the first eight values of the Fibonacci series.

Do Until 

As an alternative approach to nesting an If-Statement inside the loop, and invoking Exit Do once we're done looping, Visual Basic provides a Do Until statement. Its syntax is the following:

Do Until (Expression)
    (Code to execute)
Loop

(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit the loop. Each time the program reaches Loop it will evaluate this expression. If the expression is True, it will exit the loop for us, but otherwise it will continue looping.. So let's try rewriting our Fibonacci program to use a Do-Until loop instead of Exit Do.

Public Sub Main()
   Dim X As Integer
   Dim Y As Integer
   Dim cnt As Integer 'Our counter.
   
   cnt = 1
   
   Do Until cnt >= 8
      Debug.Print X
      
      X = Y + X
      Y = X - Y
      cnt = cnt + 1
   Loop
End Sub

 

Here we've replaced the hideous If cnt >= 8 Then ... Else: Exit Do with a very simple Until cnt >= 8. We must, however, still be sure to increment our counter every time through the loop, or else the Until expression will never be True, resulting in an infinite Do Loop.

Do While 

In the place of Do Until, you can also use Do While. Its syntax is the following:

Do While (Expression)
    (Code to execute)
Loop

(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit the loop. Each time the program reaches Loop it will verify that this expression is True, and if it is False, it will exit the loop for us. Thus, instead of exiting when an expression is True, it now exits only once this expression is false. Let's try rewriting our Fibonacci program to use a Do-While loop instead of a Do-Until loop.

Public Sub Main()
   Dim X As Integer
   Dim Y As Integer
   Dim cnt As Integer 'Our counter.
   
   cnt = 1
   Do While cnt < 8
      Debug.Print X
      X = Y + X
      Y = X - Y
   
      cnt = cnt + 1
   Loop
End Sub

For-Next Loops 

In situations where you merely want to run the loop a predefined number of times, it can become quite tiresome to have to create and manage a counter for each loop, which is why we also have something called a For-Next Loop. This kind of loop allows you to specify a counter, to tell it to count from one number to another each time through the loop, and to exit once the counter has reached its upper limit. The syntax is as follow:

Dim I As Integer
   
For I = (Integer) To (Integer)
   (Code to execute)
Next I 

We used the variable name "I" above, as it is the most common name used for For-Loops; however, you can use any variable name you want, so long as the variable is of the type Integer. Now, let's improve our Fibonacci program even further:

Public Sub Main()
   Dim X As Integer
   Dim Y As Integer
   Dim cnt As Integer 'Our counter.
   
   For cnt = 1 To 8
      Debug.Print X
      X = Y + X
      Y = X - Y
   Loop
End Sub

 

In the example above, we first dimensioned cnt as an Integer, and then, in the declaration of the For-Next loop, set its value to 1. Each time through the loop, the value of cnt was incremented by 1 until it reached 8, at which point the loop was executed.

Exit For 

As with Do Loops, there is a statement that can be used to exit a For-Next loop, and it is called Exit For. Simply invoke this statement anywhere within a For-Next loop and the current loop will be exited.

Step 

By default, the variable used in the declaration of the For-Next loop is incremented by 1 each time through the loop; however, if you want to increment this value by a different amount each time through the loop, you can simply append Step (Integer) to the end of the For-Next loop declaration. If, for instance, we wanted to print out every even number counting backward from 20 to 0, we could do this using the following code:

Dim I As Integer
   
For I = 20 To 0 Step -2
   Debug.Print I
Next I

So there you have it now you can use loops all over your Visaul Basic 6 programs. These are one of the most useful tools you have. You might want to bookmark this tutorial so that later you can reference back to this great VB6 loop examples. If you have any questions or comments please post them below.

This tutorail is released under the GNU Free Documentation License 1.2. The original can be found here.

If you enjoyed this post, subscribe for updates (it's free)

Child maths table

Hi. There!
Is there anyone who can answer me this;
write a simple maths table that will Multiply from 1 to the number entered by a user. eg.
say we entered 5 then it produces this;
1x5=5
2x5=10
3x5=15
4x5=20
5x5=25

Plz help me write a program

Plz help me write a program in visual basic 6.0 to print
*
* *
* * *
* *
*

Help me Please

12345678
23456781
34567812
45678123
..........................

how to make it?
Help me Please.....

VB

try this:
For a = 0 To 9
For b = 1 To 10
For c = 2 To 11
For d = 3 To 12
For f = 4 To 13
ListBox5.Items.Add(f)
Next f
ListBox4.Items.Add(d)
Next d
ListBox3.Items.Add(c)
Next c
ListBox2.Items.Add(b)
Next b
ListBox1.Items.Add(a)
Next a

write count number

i write number this type
i write 1 to 50 numbers
1
2
3
4
5
6
sleep 7 to 45
46
47
48
49
50
how can write code in vb6

For R = 1 To 50 For c = 1 To

For R = 1 To 50
For c = 1 To R
Print c;
Next c
Print
Next R

Cara aqui bolei como apagar tudo no datagrid vb6

Após quebrar muito a cabeça conclui aqui, e compartilho com vo 6 ops, vb6. kkkkkk
Sem banco dados, dados de cxs de texto

Dim myRst As ADODB.Recordset
---------------------------------------------------- 'load
Set myRst = New ADODB.Recordset

myRst.Fields.Append "CodProd", adVarChar, 20
...........
myRst.Open
---------------------------
If txtDB(0).Text = "" Or txtDB(1).Text = "" Or txtDB(2).Text = "" Then
MsgBox "Preencha os 3 dados!"
Else
myRst.AddNew
myRst!CodVenda = txtDB(0).Text
........
myRst!Total = Val(txtDB(1).Text) * Val(txtDB(2).Text)

myRst.Update
Set DataGrid1.DataSource = myRst
End If
----------------------------------
Private Sub CmdDelall_Click() ' funfa blz zera datagrid by Paschoal
On Error Resume Next
If DataGrid1.Row < 0 Then
MsgBox "Nada para apagar!"
Exit Sub
Else
Do While DataGrid1.Row > 0
myRst.Delete
Loop
End If
myRst.Delete
Me.DataGrid1.Refresh
TxtQuant.Text = ""
TxtTotal.Text = ""
End Sub
====================
Private Sub CmdDellinha_Click() ' deleta linha selecionada
On Error Resume Next
If DataGrid1.Row < 0 Then
MsgBox "Nada para apagar!"
Exit Sub
Else
myRst.Delete
DataGrid1.Refresh
Somar
End If
End Sub

Awesome, really liked this

Awesome, really liked this tutorial!

help me to Create a program

help me to Create a program where it will ask the user a number and the program should add all the numbers on that range. So basically if the user inputs 10, the program will add numbers 1 to 10. And after adding all those numbers, it will also print the numbers 1-10. please I need the answer now :"(

answer it now please :"((

answer it now please :"((

hue

Lol do you homeworks by yourself! ask your teacher if you need help, and don,t cheat.

Average of multiple students, multiple marks

can any one help me to write a code for calculate avg of students by notpad information (Marks.txt) file and calculate each student avg by input box..
txt file is below... plssssssssssss

"Chaminda", 30, 40, 65, 80, 35
"Rohana", 40, 55, 90, 45, 60
"Saman", 60, 75, 45, 35, 70
"Sumana", 45,55, 80, 30, 40
"Wimala", 80, 65, 45, 75, 50
"Mudith", 40, 65, 95, 40, 50
"Nandana", 60, 50, 60, 70, 40
"Indika", 50, 55, 65, 45, 75
"Pradeep", 30, 25, 60, 45, 50
"Nimala", 20, 30, 45, 60, 40

hi

i nee to write a program which reads 10 integers and print the positive and negative integers

Flexgrid

need help about flexgrid

loop for name of day.

HELP ME PLEASE

Im having problems.

Help me please find sintax code for this looping problem.

"UNZ" is the number of "UNH"

its output will be like this: "UNZ + (Count of UNH) + ............."

Thank you.

HELP ME PLEASE

help me please coding for looping this problem.

"UNZ" adalah jumlah dari "UNH"

output nya akan seperti ini : " UNZ+ (Count of UNH)+............."

Thank you.

HELP ME PLEEEEASE!!

OMG! OMG! OMG!!!! Are you kidding me??? What a bunch of cry babies! You actually expect someone to do your homework for you??? What a bunch of lazy slackers! Here's a novel idea. Why don't you read your coursebooks, practice the excercises, and actually try to learn how to do something instead of expecting someone else to come along and bail your butts out!!!

HELP ME PLSSSSSSSSSSSS

I'm slow in learning looping. please help me in these questions. please sir, i really need a solution:

Question 1

One large chemical company pays its salespeople on a commission basis. The salespeople receive RM200 per week plus 9% of their gross sales for that week. For example, a salesperson who sells RM5000 worth of chemicals in a week receives RM200 plus 9% of RM5000, or a total of RM650. Develop a program that will request total number of salespersons and then you will input each salesperson’s gross sales for last week. The program must be able to calculate and display the salesperson’s earnings. Process one salesperson’s figures at a time.

Question 2

If we are given a collection of numbers, the mean and standard deviation for the numbers can be calculated by this formula,

Mean = m =

Standard deviation = s =
where
n = the number of collection
xi = the value of the items

For example, if the collection of the numbers is 2,3,5,7 and 8 so

Mean = m = = 5
and the standard deviation for the numbers is calculated as below:

= ( 2 + 3 + 5 + 7 + 8)2 = 625 = 22+32+52+72+82 = 151
So
s = = = 2.5495

You are required to develop a program to accept number of collection from users and the value of each item. Your program will calculate the mean and standard deviation for the inputted number.

Answer 1

Private Sub Command1_Click()
Dim no1, ans As Integer
no1 = Val(txtval.Text)
ans = 200 + 0.09 * no1
txtans.Text = ans
End Sub

Private Sub Command2_Click()
txtval.Text = ""
txtans.Text = ""
End Sub

Private Sub Command3_Click()
End
End Sub

Take three buttons calculate,reset and end
If any problem please e-mail me
saurabhindoria@hotmail.com

Very Urgent pls help me..

coding for add a list box item to the database using vb 6.0

Pls I need a program that

Pls I need a program that calculates the sum of integers between any range specified by the user...say sum of intergers between 2 and 215_plssss

vb program

i wrote a program that is required to find values for x2,y2, by assuming theta2 and theta1, now the next step that im stuck at is i have to use the values found for x2 and y2 and input that into the equation to find the values for theta1 and theta2, i have used the for code when assuming the values for theta1 n theta 2 and used the if code for the range of the x2 and y2 values.can you help me,thx

VBA Macro

write a loop that will calculate the sum of every third integer, beginning with i=2 (i.e., calculate the sum 2+5+8+11+....) for all values of i thta are less than 100 and presents the sum in a message box. Write the loop in each of the following ways:
using a for next structure
using a do while loop structure
using a do until loop structure
using a do loop while structure
using a do loop unti structure

How To Let The Text Box Accept Number Larger Than 35 ..

Help Please :

How To Let The Text Box Accept Number Larger Than 35 And Smaller Than 100 ONLY
100=< The text box >= 35

if textbox.text>35 and

if textbox.text>35 and textbox.text<100 then
' do what u want with it
else
msgbox("write a number from 35 to 100")
end if

I think it is diferent

If val(TextBox1.Text)<=35 Or Val(TextBox1.Text)>=100 then
TextBox1.text=""
TextBox1.text=Inputbox"The number Can´t be less of 35 or larger than 100." & (CHR(10)) & "Please enter a diferent number"
End If

Sorry for my English.

Greetings form México!

RE:

Hi,

Correct me if I'm wrong. I think you're asking for "How To Let The Text Box Accept Number Larger Than 100 And Smaller Than 35 ONLY"?

Best regards,

Tobee

pls help Create a program

pls help Create a program that can input 10 names and display them after. Use input box for data entry and message box for data output.

pls help Create a program

pls help Create a program that can input 10 names and display them after. Use input box for data entry and message box for data output.

QBASIC

WAP in BASIC to take 25 numbers as input and check whether prime or not

plz write the coding a) A

plz write the coding
a) A
B C
D E F
G H I J
in vb6

pahelp po

mr julio cervantes has P20,000in his savings account. Write a program that would enter a series of numbers terminated by 0 sentinel. A positive number would a deposit in his account and the negative number would mean withdrawal . For each numbered entered the outstanding balance must be displayed. The program should also check whether the amount to be withdrawn has sufficient funds. if there is not the message "INSUFFICIENT FUNDS!" must be dispalyed
pahelp naman po ako nito

Visual Basic Nested Loop

I have made the input of this, however, my teacher prefer it 4 'For' only.. and not 7 'For'

1
12
123
1234
12345
123456
1234567
123456
12345
1234
123
12
1

What is the proper code for this??

with nested loop up 1 to 7

with nested loop up 1 to 7 print krne ke liye
for r=1to 7
for c=1to r
print c;
next c
print
next r

need help in 'C'

need help here..

1) Use a For Loop and If Statement,from integers 0 to 50,compute the sum of numbers which fulfill one of the following conditions:
- has digit '2'
-is divisible by 3
The program should output this sum at the end.

2)Prompt user for an integer input and print out the multiplication result of the digits.For example,if the user enters 1234,then the program will print out 24.

Thx

ansur for no.2 Option

ansur for no.2

Option Explicit

Sub main()

Dim nNum As Integer
Dim nSum As Integer
Dim nMemory As Integer

nNum = InputBox(" ")
nSum = 1

While nNum <> 0

nMemory = (nNum) Mod 10

nSum = nSum * nMemory

nNum = (nNum / 10)
Wend

MsgBox (nSum)

End Sub

Need help.. For_Next

How to find the maximum or minimum value of the numbers that entered in input box with for next program?

I NEED TO MAKE A PROGRAM OF

I NEED TO MAKE A PROGRAM OF TEXT TWIST GAME :) PLEASE I NEED AN ANSWER ASAP :)

Programming

Write a program in java to print the tables of numbers up till 10. Ask the user up till what number does he/she wants to print the tables for? Then print the tables starting from 1 until the user given number. One line should contain only one table

visual basic

i need help.
how do i code my program
with the required outputs:
1st)
123456789
12345678
1234567
123456
12345
1234
123
12
1

2nd)
1
12
123
1234
12345
123456
1234567
12345678
123456789

3rd)
C
CO
COM
COMP
COMPU
COMPUT
COMPUTE
COMPUTER

and last)
COMPUTER
COMPUTE
COMPUT
COMPU
COMP
COM
CO
C

vb6.0

'try this code' that's gud

Private Sub cmdok_Click()
C$ = "12345678"
For a = 1 To 8
pic.Print Left$(C$, a)
Next a

C$ = "12345678r"
For b = 8 To 1 Step -1
pic.Print Left$(C$, b)
Next b
End Sub

coding in vb6 for r=1 to

coding in vb6
for r=1 to 8
for c=1 to r
print c;
next c
print
next r
or 3 ques me asky value ka use krege

i got an output similar to

i got an output similar to the combination of the required 3rd and 4th.
i got the clues now.

vb6.0

'try this code'

Private Sub cmdok_Click()
C$ = "123456789"
For x = 9 To 1 Step -1
pic.Print Left$(C$, x)
Next x

C$ = "123456789"
For y = 1 To 9
pic.Print Left$(C$, y)
Next y
End Sub

'jorges_philip1991@yahoo.com'

>>'jorges_philip1991@yahoo.co

>>'jorges_philip1991@yahoo.com'

the output is like a capital letter K.
thanx.

pleas help

create a script that will determine a positive number, negative number, if the number is less than 100 and if the number is greater than 100 and will ask if you want to start again before terminating.

Help Please?

Write a VB.NET program that calculates the sum of all the numbers between 1 and 100 that are divisible by 5 or 6 but not both.

Numbers divisible by 5 between 1 and 100 are:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100

Numbers divisible by 6 between 1 and 100 are:
6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96

So numbers between 1 and 100 that are divisible by 5 or 6 but not both are:
5, 6, 10, 12, 15, 18, 20, 24, 25, 35,
36, 40, 42, 45, 48, 50, 54, 55, 65, 66,
70, 72, 75, 78, 80, 84, 85, 95, 96, 100

C++ language

i want help

solve for me

7 programs without errors

by taking help from control structures in C++

1. write a program that accepts input four numbers and get the summation of even numbers only

2. write a program to test a number for being odd or not

3. write a program to ask for a password, and it check it with a saved password, it will return “Authorized” if the password match or “Unauthorized” if the password does not match
4.write a program to find the factorial of a number
5.Write a program to find the minimum of three numbers.
6.Write a program that accepts entry only positive numbers, if you enter negative number it will give an error message (unaccepted), the program will stop when you enter 10 positive numbers.
7.Write a program that prints the number in revise order, for example if you enter 1456, the program will print 6541. (Hint: you are to use modulus % and division / operators)
you will need to use control structures to solve the questions

First Solution

#include<iostream>
using namespace std;
int main()
{
    int sum = 0, temp = 0;
    for (int i = 0; i < 4; i++)
    {
        cout<<"Please enter number "<<i+1<<": ";
        cin>>temp;
        if (temp % 2 == 0)
            sum += temp;
    }
    cout<<endl<<"The sum of even numbers is: "<<sum<<endl;
    system("pause"); // can be removed
    return 0;
} 

Didnt work too well because

Didnt work too well because of code tags... sorry.

Hmm

First Off, do your own homework.

That is all

c free

Write a program in C that will ask from the user to enter a number between 1 and 5. While
the user doesn’t enter a number within this range, the program should repeatedly ask for
the number until the number is within the valid range. Then the program should print the
corresponding output based on the following table. Use the switch statement.

can you help me pls

PRIME NUMBER!!!

Hey all :)
i want a program in vb.net gives a prime number and the (GCD) and (SCM) as soon as possible pleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaase :))

please solve this project by for loop including "if"

write a program that calculates the min ,max and average a set of numbers . the size of that set should be received from the user at the beginning of the execution .

Done!

Here you are:

Option Explicit
Dim C As Integer, I As Integer
Dim Num As Long, SumN As Long, MaxN As Long, MinN As Long

Private Sub Form_Activate()
C = InputBox("How many numbers?", "Numbers")
For I = 1 To C
Num = InputBox("Enter the " & I & " number:", "Numbers")
If I = 1 Then
MinN = Num
MaxN = Num
Else
If Num < MinN Then
MinN = Num
ElseIf Num > MaxN Then
MaxN = Num
End If
End If
SumN = SumN + Num
Print Num
Next
Print "The max number was: " & MaxN
Print "The min number was: " & MinN
Print "The average of the numbers was: " & SumN / C
End Sub

whileloop

which a except a number and to find it square except user input that is the user whileloop is continue it find the square of another numbers.please slove this program right now its very importan for me.

alghorithm c++ for prime numbers

hi i need help i have to make proghram c++ for prime numbers like this
enter starting value: 1
enter ending value:10
2,3,5,7
minimum:2
maximum:7
average:17/4
plz i need help for write program c++

C++

Plz help..........
Help me..........
Q # Write a program that reads numbers repeatedly until 0 (zero) is entered, find and display the smallest and largest number. Use while loop statement.

03365961262

C++

Plz help..........
Help me..........
Q # Write a program that reads numbers repeatedly until 0 (zero) is entered, find and display the smallest and largest number. Use while loop statement.

03365961262

request

please dont change the captions you fools

Program

I know this doesn't have to with VB 6.0, yet VB 2010. Not too much about understanding For, Do, and while Loops either, but it does a little bit. I need to enter a program using option Explicit and Strict,Do Loop, Use of the console (No input boxes or message boxes), Console Clear command, Use of sentinel value, Counter Accumulator, and If statement. The situation is that I have to create a program that prompts the user to enter a series of numbers. When the user want to stop, have them enter in a "-1" to end the input. Afterwards, the program should then display the largest number, smallest number, and the average of all the numbers. Please help me out with the code! I found out a way to do average with this code: Dim iCounter As Integer
Dim dGrade As Double
Dim dTotalGrade As Double
dGrade = 0
iCounter = 0
dTotalGrade = 0
Console.Write("Enter Grade or -1 to Exit")
dGrade = CDbl(Console.ReadLine())
Do Until (dGrade = -1)
dTotalGrade = dTotalGrade + dGrade
iCounter = iCounter + 1
Console.Write("Enter Grade or -1 to Exit")
dGrade = CDbl(Console.ReadLine())
Loop
Console.WriteLine("Your Average is : " & _
CStr(dTotalGrade / iCounter))

Not sure if that is right so I really need help guys and would really appreciate it!

visual basic 2010 for -next loop please help

i just need help in coding the for loop. here's the problem. a financier wishes to have a program that will calculate the amount of money in an interest bearing account after a given number of years. the program needs to be written so that the user can input the ff. four data: initial deposit, annual interest rate, number of years, number of compounds per year (including "c" for continuous). upon pressing the calculate button, the program should report the total in the account after each year up to the given number of years. this information should be shown in the list box. the interest rate may be given as a decimal or a percent. the program should handle both. use the following formula: pt = p0 (1+r/n)^nt for a countable number of compounds, pt=p0e^rt for continuous compounding. where p0 is the initial deposit, pt is the year, r is the interest rate, n annual number of compound. thanks so much for any help. i'm so confused on how to code the exponent .

helppp mee :'(

plllz I need it tomorrow before 11 pm :(:(

plz help =((

Writing Programs Problems:

a.write a program that reads N and prints the sum and average of all integers from 1 to N
Example:
Enter a number : 6
The sum from 1 to 6 = 21
The average from 1 to 6 = 3.5

b.Write a program that asks the user to enter 10 integers and writes the smallest value.

c.Write a program that reads in the side of a square and prints the square out of asterisks. Your program should work for square of all sizes between 1 and 20, when the user enter other sizes the program should display an error message.
for example: when the user enter 4
the output:
****
****
****
****

d.Write a program that prints an isosceles triangle on 5 lines.
*
***
*****
*******
*********
e.Write a program that reads a set of integers, and then finds and prints the sum of the even and odd integers.

Please help .... thanks =(

for the triangle: dim star as

for the triangle:

dim star as string="*"
for i as integer=1 to 5
listbox1.items.add(star)
star=star+"**"
next

for the square:

Dim size As Integer
size = InputBox("enter size of square between 1 and 20")
If size < 1 Or size > 20 Then
MsgBox("error")
size = InputBox("enter size of square between 1 and 20")
End If
Dim row As String = ""
Dim column As Integer = size
For j As Integer = 1 To size
row = row + "*"
Next
For k As Integer = 1 To column
ListBox2.Items.Add(row)
Next

for section A: Dim num As

for section A:

Dim num As Integer = 0
num = InputBox("enter a anumber")
Dim a(num) As Integer
Dim divby As Integer = num
Dim sum As Integer = 0
For i As Integer = 1 To num - 1
a(num) = i + 1
Next
For j As Integer = num To 0 Step -1
sum = sum + j
Next

ListBox3.Items.Add("sum is: " & sum)
Dim avg As Double
avg = sum / divby
ListBox3.Items.Add("avg is: " & avg)

#include int main() { int

#include
int main()
{
int i,j,n;
printf("\n raws");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
{
printf("\n);
return 0;
}
}

hw plllllllllllllz help

Write the Visual Basic language contains:
1 - student class contains:
• variable h in a matrix (The decision)
• a variable course in matrix (for the storage decisions)
• record function that allows the student to be registered and breathing
• branches of the student class studcomp contains a function record for the number of hours recorded by the student's courses and inform him if he passed the hours available for registration or not (the maximum recording hours 20 hours), if exceeded ask him to delete the extra hours and if not beyond achievement for the number of hours remaining recorded by him to
• When you press the button to add a decision to allow the student to be registered if it does not exceed the hours specified.
• In the Print function key materials and recorded hours and hours you lived to the selected or not

Max, min and avg of a list box

I could really use some help writing code for a program that takes the max, min and avg of numbers in a list box and sends them each to labels.
Any help would be greatly appreciated, Thanks!

hw vb

please i need ur help in my homework. am new in vb!

Problem 1:
Develop an application which accepts a positive integer value from the user and outputs the sum of all odd integers between 0 and the given integer.

Note: for problem 1, you might use a console application.

Problem 2:
Put two textboxes on your form. The first box asks users to enter a start position for a For Loop; the second textbox asks user to enter an end position for the For loop. When a button is clicked, the program will add up the numbers between the start position and the end position. Display the answer in a message box.

LOOPING

Good Day Sirs / Ma'ams,

I have this problem in looping in VB 6.. The process is I want to make a condition that would check a PC if it is vacant or not : If it is not, it will proceed to another PC (increment); If it is vacant, it will automatically display the first number or slot that it found. Can you help me with it ? I would very much appreciate it.. THANK YOU in advance.

I NEED A PROGRAM USING TURBO

I NEED A PROGRAM USING TURBO PASCAL , I NEED TO SHOW LOOPING STATEMENT .CAN YOU PLEASE HELP ME ?? :))

help

i have to make a fortune teller program for an assignment i i need help i want to display different messages depending on if the user is male or female and i need to know if i can use two loops on one function. but i'm getting both messages displayed at the same time please help me this is what i have so far:
Private Sub btnFortune_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFortune.Click
Dim female As Boolean
Dim male As Boolean
Do
female = True And male = True
If (txtEntNum1.Text >= 6) Then
female = True And male = False
MsgBox("Your fortune is that you will have a good job earning lots of money within the next 10 years. Enjoy ")
End If
If (txtEntNum1.Text <= 5) Then
female = True And male = False
MsgBox("Your fortune is that you will win the lottery this time next week! ")
End If
Loop While female = False And male = True
Do
male = True And female = True
If (txtEntNum1.Text >= 6) Then
male = True And female = False
MsgBox("Your fortune is that you will be in trouble next week with your boss ")
End If
If (txtEntNum1.Text <= 5) Then
male = True And female = False
MsgBox("Your fortune is that you will eat a cake tommorow! ")
End If
Loop While male = False And female = True

End Sub

VISUAL BASIC 6

HELP! I made a program that allows me to input as much integers I have and then the teacher tells us to get the AVERAGE. how am i going to get the average? *Visual Basic* In C, i will use counter... Is there such thing as counter in VB6???

and!!

how do i make a program using do-while loop or do-loop-while that looks for the HIGHEST number i inputted and then counts how many times I clicked it and in the end display the results in the text box and msgbox?????? STILL VB6

finding max and min of gross pay

Im having problems to finding out the answer to this and I hope someone can help me along. Basically I want to find out the max and min of 6 peoples wages. I have already calculated the wages for each person from a streamreader txt file using a do while and some if statements. That was the easy part but now I need to find out what is the max wage and the min wage.
Any suggestions would be greatly appreciated.
Thank you

How to find student in a school n after that how to find his mks

Please write one program.

How to find student in a school and after that how to find his marks and after that how to find his attandance. so for this please draw a flow chart and write one program.

Kindly inform me while sending.

Nagraju.Sarla
08147870944.

a can't understand i want the

a can't understand i want the most simple code in coding a calculator...just use only the Declairing variables and expressions.

visual basic hw

hello,
i need help with my assignment in excel..we need to do the following:
1) color white all cells containing a negative value
2) color yellow all cells whose value is even and greater than zero
3) color red all cells whose value is divisible by 5 but not by 10 and is greater than zero
4) color blue all cells whose value is equal to 0

and we are given a list of numbers of course, and here is what i got

Sub manipulation()
'1) color white all cells containing a negative value
'2) color yellow all cells whose value is even and greater than zero
'3) color red all cells whose value is divisible by 5 but not by 10 and is greater than zero
'4) color blue all cells whose value is equal to 0

Dim curCell
For Each curCell In Selection
curCell.Value = Application.Round(curCell.Value, 0)
If curCell.Value Mod 2 = 0 And curCell.Value > 0 Then
curCell.Interior.Color = RGB(255, 255, 0)
End If
If curCell.Value Mod 5 = 0 And curCell.Value Mod 10 = 1 Then
curCell.Font.Color = RGB(355, 0, 0)
Else
curCell.Font.Color = RGB(0, 0, 255)
End If

Next curCell

End Sub

can anyone help me to finish the rest?!

looping

please help me this :
1.write a program that asks the user to input N integers and compute the ff:
-sum of all odd integers
-sum of all even integers
-average of all odd integers
-average of all even integers
2. input 10 scores and count how many scores are in the rage 1-25, 26-50, 51-75,76-100, and out of range . allow the user to repeat the operation as often as possible.

HELP

how do you write a program that would calculate and display the results for the multiplication table for values ranging from 1 to 100? using pseudo code and repetition statements

PLS. HELP ME !!!

Create a project that will allow the users to input numbers and be able to display all the numbers, smallest and largest numbers, the repeated number/s and total of all numbers.

loops

x^2 - x + 41 will find the prime numbers where x is 1 to 40. Write a program using this formula to display the prime numbers in that range of x. Display the results in a RichTextBox.

please help me to "create an

please help me to "create an application in vb to find the second biggest of the n number" and "coding to read the elements one by one and display the elements in the reverse format".........please tell me the CODING.....have to write my vb assignment...im new to visual basic and have no idea of the codings...please help to finish my assignments...please..:((

Reverse Number

textbox1
button1

button1.click event:

dim num,res,remi,res1 as integer
num=textbox1.text
res1=0
while num/10 <> 0
remi = num/10<>0
remi=num mod 10
res=math.truncate(num/10)
res1=(res1*10)+remi
num=res
end while
msgbox(res1)
end sub
end class

I want to do this in all loop

Create a program that reads

Create a program that reads the letter codes ‘A’ through ‘Z’ and prints the corresponding telephone digit. To stop the program, the user should enter ‘#’.

pls answer

pls answer

HELP PLEASE!

How do i construct a program that will accept the inputted name and will display it 5 times
using the For loop , Do while loop , While loop in C# ?

HELP PLEASE!

How do i construct a program that will accept the inputted name and will display it 5 times
using the For loop , Do while loop , While loop in C# ?

functions

how can i create a simple calculator that wil ask for two numbers. then displat a menue thatusers will choose whether they want to.
i.addition
ii.division.
iii.multiplication
iv.modulo.
v. subtraction.

it should also be nade up of
i.SUBROUTINE menue() that displays the menue.
ii.Function sumTwo() that accepts two numbers and returns the sum of the two numbers.
iii. should also apply for subtraction, division, modulo and division.

help please...

write a program to read in numbers of numbers to be inputted.read in the numbers. compute the sum,average,maximum and minimum values. print the sum, average, maximum and minimum values.the program will then ask the user if she/he wishes to continue, if yes then clear the screen and go back to the beginning of the program. if no, then end the program. if the input is less than 1,print a message containing the word error and perform and exit(0).

Done!

Here you are:

Option Explicit
Dim I As Long, Sum As Long, Num As Long, Max As Long, Min As Long

Private Sub Form_Activate()
Do
Me.Cls
For I = 1 To 10
Num = InputBox("Enter a number:", I & " Number")
If Num < 1 Then
MsgBox "E R R O R!"
End
End If
Print Num
If I = 1 Then
Sum = Num
Max = Num
Min = Num
Else
Sum = Sum + Num
If Num < Min Then
Min = Num
ElseIf Num > Max Then
Max = Num
End If
End If
Next

Print
Print "Sum = " & Sum
Print "Average = " & Sum / I - 1
Print "Max Number = " & Max
Print "Min Number = " & Min
Loop Until MsgBox("Do you wish to continue?", vbInformation + vbYesNo, "END") = vbNo

End
End Sub

HELP

pls, help me write simple VB.NET CODE SEGMENT to do the following;

1- x=5
y=2
x=x+5-y

z=y+X

2- what is the final answer for x, y, z

please, i need this before 8.00pm today.
thanks.

Visual basic.net

1 x=5,y=2.x=x+5-y, z=y+x.what is the final answer for x,y,z

do until

how can i solve this one , i have to get the output like this * *
** * *
*** *
or even any shapes of dots by using the do until loop
and when the user types a number in the input box it should show the numbers of dots that
the user has been type in the picture box...

please i need the codes of it immediately.... hope you can help me...

hell boss i think you need to

hell boss i think you need to display in your program like *** while running the program so just do it
select the text box which you want to insert ** and go to proparty window and set pasword char true (defalt value is false) i think it will help you other wise sorry .....

PasswordChar

On the textbox properties, look for PasswordChar. Then type *. That's it!

please help me creating a code

Please help me
1.Create a sequence where the next number is 1 higher than the previous.
2.Create a sequence where the next number is 10 higher than the previous.
3.Create a sequence where the next number is double the previous number.
4.Create a sequence where you show the first 5 odd numbers or even numbers.

all the answer must be shown in TextBox in the form of #,#,...,#

Done!

Option Explicit
Dim StartN As Long, EndN As Long, I As Long

Private Sub Form_Load()
Text1.Text = ""

While StartN < 1 Or StartN > 100
StartN = InputBox("Enter the start number for the sequence:", "0 - 100")
Wend
While EndN < 1 Or EndN > 100
EndN = InputBox("Enter the end number for the sequence:", "0 - 100 AND GREATER THAN START NUMBER")
Wend

For I = StartN To EndN 'answer 1.
Text1.Text = Text1.Text & Format(I, "#0") & ", "
Next

For I = StartN To EndN Step 10 'answer 2.
Text2.Text = Text2.Text & Format(I, "#0") & ", "
Next

For I = StartN To EndN 'answer 3.
If I = StartN Then
Text3.Text = Text3.Text & Format(I, "#0") & ", "
ElseIf I * 2 <= EndN Then
Text3.Text = Text3.Text & Format(I * 2, "#0") & ", "
End If
Next

For I = StartN To EndN 'answer 4.
If I Mod 2 = 0 Then
Text4.Text = Text4.Text & Format(I, "#0") & ", "
Else
Text5.Text = Text5.Text & Format(I, "#0") & ", "
End If
Next
End Sub

Create 5 text boxes to make it work right. I hope it will help you!

Thank you so much :-)

Thank you so much :-)

How to write From Right to left in Vb6

Can anyone help me to write From Right to left ( Like Arabic ) in vb6 with the default font, when changing the windows language from language bar.

Excel Macro

I need help using Visual Basic.

I am trying to add macros to a excel spreadsheet and one of the problems that i am facing right now is that i need to make lists every time I click a button. in other words, i want that every time I click on a button my number stores in the following row. I haven't been lucky with this so any help will be appreciated. thanks!

help plz..im new in VB

Public Class Form1

Private Sub mnuPoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPoint.Click
Dim point As Integer
Dim book, reader As Integer
book = 0
reader = 0

If (TextBook.Text > 6) Then
point = 20
ElseIf (TextBook.Text > 3) Then
point = 15
Else
point = 10
End If
book = book + TextBook.Text
reader = reader + 1
LblEarn.Text = point
End Sub

Private Sub mnuClr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClr.Click
TextReader.Text = ""
TextBook.Text = ""
LblEarn.Text = ""
LblAverage.Text = ""

End Sub

Private Sub mnuSum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSum.Click
Dim average As Double
Dim book As Integer
Dim reader As Integer
average = book / reader
LblAverage.Text = "books read " & book & " readers are " & reader

End Sub
End Class

"The problem is.....i want mnuSum_Click display the average number of book read for all readers.
the reader n book is variable....
mnuClr_Click is clear the name reader, the number of books read, and the bonus point and then reset the focus.
how to load the reader n book if 3 or 4 ppl read the book at the same time??
without load the reader n book, how to get average value...??
hope understand that situation...TQ"

Multiplication Table

How do I code an application so that it multiplies and displays any number I input by the numbers 1 to 9? Ex. Number: 25 Multiplication Table Displays: 25 * 1= 25, 25 * 2= 50, 25 * 3= 75, etc.

Done!

Here you are:

Private Sub Form_Activate()
Dim Num As Currency, I As Byte
Num = InputBox("Enter the number for multiplication:", "NUMBER")
For I = 1 To 9
Print Num & " * " & I & " = " & I * Num
Next
End Sub

Dim as ADODB.recordset do

Dim as ADODB.recordset
do while
loop
...rst.open

How do I convert a For...Next statement into a Do...Loop??

I still have not received an answer to my previous question below BUT how do I change this For... Next statement into a Do... Loop statement??

For intHours As Integer= 0 to 3
lblHours.Text=intHours.ToString
For intMinutes As Integer= 0 to 9
lblMinutes.Text= intMinutes.ToString
Next intMinutes
Next intHours

For...Next => Do...Loop

Here you are:

intHours = 0
Do While intHours < 4
lblHours.Text = intHours.ToString

intMinutes = 0
Do While intMinutes < 10
lblMinutes.Text = intMinutes.ToString
intMinutes = intMinutes +1
Loop

intHours = intHours +1
Loop

How do I convert a For...Next statement into a Do...Loop??

HELLLLPPPP!!!! I AM SO CONFUSED AS TO HOW TO CONVERT THIS STATEMENT INTO A DO... LOOP STATEMENT. :-(

For dblRate As Double = 0.05 To 0.1 Step 0.01
lblPayments.Text = lblPayments.Text _
& dblRate.ToString("P0") & " "

For intTerm As Integer = 3 To 5
dblPayment = _
-Financial.Pmt(dblRate / 12, _
intTerm * 12, dblPrincipal)
lblPayments.Text = lblPayments.Text _
& dblPayment.ToString("N2") & " "
Next intTerm

lblPayments.Text = lblPayments.Text & ControlChars.NewLine
Next dblRate

For...Next => Do...Loop

Here you are again:

dblRate = 0.05
Do While dblRate < 0.11
lblPayments.Text = lblPayments.Text & dblRate.ToString("P0") & " "

intTerm = 3
Do While intTerm < 6
dblPayment = -Financial.Pmt(dblRate / 12, intTerm * 12, dblPrincipal)
lblPayments.Text = lblPayments.Text & dblPayment.ToString("N2") & " "
intTerm = intTerm +1
Loop

lblPayments.Text = lblPayments.Text & ControlChars.NewLine
dblRate = dblRate + 0.01
Loop

How do I convert a For...Next statement into a Do...Loop??

Dim dblRate As Double
Dim intTerm As Integer
 
dblRate = 0.05
do until dblRate > 0.1
  ' stuff from outer for loop 
  lblPayments.Text = lblPayments.Text & dblRate.ToString("P0") & " "
 
  intTerm = 3
  do until intTerm > 5
    ' stuff from inner for loop
    dblPayment = -Financial.Pmt(dblRate / 12, intTerm * 12, dblPrincipal)
    lblPayments.Text = lblPayments.Text & dblPayment.ToString("N2") & " "
 
    intTerm = intTerm + 1
  loop
  dblRate = dblRate + 0.01
loop

Need help, looping an Average of 10 numbers everytime

Need help to solving this question. Was given a row of numbers from B1 to B100. Every ten numbers must be averaged out , e.g B1 to B10 must be sum up then divided by 10 and placed it on E10. The looping contiunes, e.g B2 to B11 sumed up and divid by 10 and put in E11.
I came up with certain codes but it always seems to be stuck in the following loop. E.g When I do B2 to B11, B3 to B12 doesnt appear. Wondering what mistake I made as I keep getting an error message. Here is my code.

Dim stock2 As Double
Dim stock3 As Double
Dim stocke() As Double
Dim stockf() As Double
Dim stock As Integer

e = 1
f = 10

ReDim stocke(f, 1) As Double

For coltwo = 1 To 1
For rowtwo = e To f

stocke(rowtwo, coltwo) = Range("B5").Cells(rowtwo, coltwo)

stock2 = stock2 + stocke(rowtwo, coltwo)

If (rowtwo = 10) Then

Range("E14").Cells(1, 1) = stock2 / 10

e = 1
f = 10

End If
Next rowtwo
Next coltwo

test1 = 2
test2 = 11

ReDim stockf(test2, 1) As Double

For g = 1 To 90
For coltwo = 1 To 1
For rowtwo = test1 To test2
stockf(rowtwo, coltwo) = Range("B5").Cells(rowtwo, coltwo) ---> When I add the variable g, this code will get an error.

stock3 = stock3 + stockf(rowtwo, coltwo)

If (rowtwo = test2) Then

Range("E5").Cells(test2, 1) = stock3 / 10
test1 = test1 + g
test2 = test2 + g
rowtwo = test1
stock3 = 0

End If

Next rowtwo
Next coltwo
Next g

Please help .... thanks guys ...

Help needed about complicated while-if-for loop.

Hey there. Heres the question.

I am going to write a C++ program that asks user to enter a seres of integer in range of -100 and 100.

if user enters a number out of that range my code shouldnt consider it and ask a another number. Also when I type 0 code should be finished.

I need that program to screen

displaying max number entered,min number entered, average of positive and negative numbers. I can do most of that thing but How can I count the numbers i get in...:/

An extra variable....

I believe you should use one more variable that every time the user enters a new number, this variable should be the counter for all the numbers.

E.x.

Counter = 0
Do Until Number <> 0
{make the calculations}
Counter = Counter +1
Loop

If you need more explanations, please tell me!

help

1. Create a console application to print the sum of numbers from 1-100 which are divisible on 3 or 5

2. Create a console application to print of numbers from 1-100 each 5 numbers on a line. Each line must show the sum of numbers on the line too. Like the following sample:

1 2 3 4 5 15
6 7 8 9 10 40
11 12 13 14 15 65
….
3. write a console application that reads 10 marks (real numbers) then finds and prints the maximum mark. average.(use for loop).

Done!

Here are all the consoles you need:

Option Explicit
Dim I As Integer, SumI As Integer
Dim N As Long, SumN As Long, MaxN As Long

Private Sub Form_Activate()
SumI = 0
For I = 1 To 100
If I Mod 3 = 0 Or I Mod 5 = 0 Then SumI = SumI + I
Next
Print SumI

Print
For I = 1 To 100 Step 5
Print I, I + 1, I + 2, I + 3, I + 4, "= ", 5 * (I + 2)
Next

Print
SumN = 0
MaxN = 0
For I = 1 To 10
N = InputBox("Enter the " & I & " real number:")
SumN = SumN + N
If N > MaxN Then MaxN = N
Next
Print "The max of the 10 numbers is:", MaxN
Print "The average of the 10 numbers is:", SumN / 10
End Sub

other answer for 1 to 100

Private Sub Command1_Click()
Dim som, i, r, t, j, begin, ennd As Integer
Dim nbr As String

r = 100 / 5
t = 1
begin = 1

Do While t <= r

nbr = ""
som = 0
ennd = 100 - (5 * (r - t))

For j = begin To ennd
som = som + j
nbr = nbr & j
Next

Print nbr, som
t = t + 1
begin = begin + 5

Loop
End Sub

on button1_click event , use

on button1_click event , use DO-WHILE to enter numbers using inputbox, the program will stop reading numbers when the sum of entered numbers is more than 100. the program must find the max of entered numbers.

Done!

Here you go:

Option Explicit
Dim SumNums As Long
Dim Num As Long, MaxNum As Long

Private Sub Command1_Click()
SumNums = 0
MaxNum = 0
Do While SumNums <= 100
Num = InputBox("Enter a number:", "SUM NUMBERS")
If Num > MaxNum Then MaxNum = Num
SumNums = SumNums + Num
Loop
Print "The Max Number was: " & MaxNum
Print "The Sum of Numbers was: " & SumNums
End Sub

Re: Help with Do While Loop

Sorry....There was some code that did not belong in my solution file. Below is the file that I am working with. Any help would GREATLY be appreciated...

Public Class Form1

' Define the

Private Sub lstCosts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstCosts.SelectedIndexChanged

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

' Close the application
Me.Close()

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click

' Reset the list boxes by deselecting the currently selected items
lstWorkshop.SelectedIndex = -1
lstLocation.SelectedIndex = -1
lstCosts.Items.Clear()
lblCost.Text = String.Empty

End Sub

Private Sub btnAddWorkshop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddWorkshop.Click
' Define variables
Dim intRegistrationFee As Integer
Dim intNumberOfDays As Integer
Dim intLodgingFeePerDay As Integer
Dim intAmount As Integer
Dim strAmount As String

If lstWorkshop.SelectedIndex = -1 Then
' Please select a workshop
MessageBox.Show("Select a workshop")

ElseIf lstLocation.SelectedIndex = -1 Then
' Please select a location
MessageBox.Show("Select a location")

End If
' Calculations using variables

If lstLocation.SelectedItem = "Austin" Then
intLodgingFeePerDay = 95
ElseIf lstLocation.SelectedItem = "Chicago" Then
intLodgingFeePerDay = 125
ElseIf lstLocation.SelectedItem = "Dallas" Then
intLodgingFeePerDay = 110
ElseIf lstLocation.SelectedItem = "Orlando" Then
intLodgingFeePerDay = 100
ElseIf lstLocation.SelectedItem = "Phoneix" Then
intLodgingFeePerDay = 92
ElseIf lstLocation.SelectedItem = "Raleight" Then
intLodgingFeePerDay = 90
End If

If lstWorkshop.SelectedItem = "Handling Stress" Then
intNumberOfDays = 3
intRegistrationFee = 595

ElseIf lstWorkshop.SelectedItem = "Time Management" Then
intNumberOfDays = 3
intRegistrationFee = 695

ElseIf lstWorkshop.SelectedItem = "Supervision Skills" Then
intNumberOfDays = 3
intRegistrationFee = 995

ElseIf lstWorkshop.SelectedItem = "Negotiation" Then
intNumberOfDays = 5
intRegistrationFee = 1295

ElseIf lstWorkshop.SelectedItem = "How to Interview" Then
intNumberOfDays = 1
intRegistrationFee = 395

End If

intAmount = intRegistrationFee + (intLodgingFeePerDay * intNumberOfDays)
strAmount = intAmount.ToString("c")
lstCosts.Items.Add(strAmount)

' This would be to add the items to the lstcosts listbox. Just an example and not for this problem
' lstCosts.Items.Add(lstWorkshop.SelectedItem.ToString)
' lstCosts.Items.Add(lstLocation.SelectedItem.ToString)

End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim intCount As Integer ' Loop counter
Dim intEachWorkshopCost As String ' to hold the selected workshop's costs
Dim intTotal As Decimal ' Use as an accumulator

' Store the starting values in the counter and the accumulator
intCount = 1
intTotal = 0
' The following loop gets the workshop costs for the day
Do While intCount < lstCosts.Items.Count

intEachWorkshopCost = lstCosts.Text 'store the totals for workshops
intTotal += intEachWorkshopCost 'Add totals of each workshop to the totals for all workshopes combined
intCount += 1 'increment the counter

' Display the running total.
intEachWorkshopCost += intTotal
Loop

lblCost.Text = intTotal.ToString("c")

End Sub
End Class

Help with Do While Loop

Please help. I am trying to retreive totals from a listbox using the Do Whilte loop. The user is allowed to select an infiinte number of choices from two lists boxes (user must choose one option from each of my two list boxes). Each item in the listbox generates a certain cost ($). After choosing one option from my two lists boxes, the user then chooses a button that I names "btnAddWorkshop" and the certain cost associated with their options in each of the two lists boxes is displayed in a third listbox. Since the user has the option to make multiple selections that will generate many costs in my third listbox, I then need to add all costs that are displayed in that same third listbox.

The problem that I am having is that I need to use a loop to add those costs that are displayed in my third listbox, and display them in a label that I named lstCalculate Total. Below is some code. Everything in the "Do while loop" is probably all wrong. Please help!

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

Dim intCount As Integer ' Loop counter
Dim intEachWorkshopCost As String ' to hold the selected workshop's costs
Dim intTotal As Decimal ' Use as an accumulator

' Store the starting values in the counter and the accumulator
intCount = 1
intTotal = 0
' The following loop gets the workshop costs for the day
Do While intCount < lstCosts.Items.Count

intEachWorkshopCost = lstCosts.Text 'store the totals for workshops
intTotal += intEachWorkshopCost 'Add totals of each workshop to the totals for all workshopes combined
intCount += 1 'increment the counter

'Do While intListCounter < lstShoppingCart.Items.Count
' lblCompletedOrder.Text &= lstShoppingCart.Items(intListCounter).ToString & ", "
' intListCounter += 1
'Loop

' For intListCounter = 0 To lstShoppingCart.Items.Count - 1
' lblCompletedOrder.Text &= lstShoppingCart.Items(intListCounter).ToString & ", "
' Next

' Display the running total.
intEachWorkshopCost += intTotal
Loop

lblCost.Text = intTotal.ToString("c")

End Sub
End Class

Please help me solve this problem.

Write a visual basic program that will ask the user to input 10 numbers and determine the maximum and minimum number.

Done!

I think this works:

Option Explicit
Dim Num(9) As Long, MinNum As Long, MaxNum As Long
Dim I As Byte

Private Sub Form_Activate()

For I = 0 To 9
Num(I) = InputBox("Enter number " & I + 1 & ":")
Print Num(I)
Next

MaxNum = Num(0)
MinNum = Num(0)

For I = 1 To 9

If Num(I) > MaxNum Then
MaxNum = Num(I)
ElseIf Num(I) < MinNum Then
MinNum = Num(I)
End If

Next

Print "The maximum is: " & MaxNum & vbCr & "The minimum is: " & MinNum

End Sub

HELP! HELP! HELP! Read a

HELP! HELP! HELP!

Read a positive integer value, and compute the following sequence: If the number is even, halve it; if it's odd, multiply by 3 and add 1. Repeat this process until the value is 1, printing out each value. Finally print out how many of these operations you performed.
Typical output might be:
Inital value is 9
Next value is 28
Next value is 14
Next value is 7
Next value is 22
Next value is 11
Next value is 34
Next value is 17
Next value is 52
Next value is 26
Next value is 13
Next value is 40
Next value is 20
Next value is 10
Next value is 5
Next value is 16
Next value is 8
Next value is 4
Next value is 2
Final value 1, number of steps 19
If the input value is less than 1, print a message containing the word
Error
and perform an
exit( 0 );

Done!

I believe you are looking for the code to solve this problem. Here it is then:

Dim Unum As Long
Dim I As Integer

Private Sub Command1_Click()

If Text1.Text < 0 Then
MsgBox "Enter a number greater than 0!"
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Exit Sub
End If

Unum = Text1.Text
Debug.Print "Inital value is " & Unum
I = 1

Do
Unum = IIf(Unum Mod 2 = 0, Unum / 2, Unum * 3 + 1)
If Unum = 1 Then Exit Do
Debug.Print "Next value is " & Unum
I = I + 1
Loop

Debug.Print "Final Value: 1, Number of steps: " & I
End Sub

You need a text box and a command button to run this sample.

other answer odd/even nbr

Private Sub Command1_Click()
Dim nbr, s As Integer

nbr = InputBox("entrez un nbr")
If nbr = 0 Then Print "error": Exit Sub
Print "Inital value is", nbr
s = 0
Do Until nbr = 1
If nbr Mod 2 = 0 Then
nbr = nbr / 2
Else
nbr = (nbr * 3) + 1
End If
s = s + 1
Print "Next value is", nbr
Loop
Print "Final value", nbr, "number of steps", s
End Sub

debug.print ?!?!?

ok so i did the ones it shows, but when i run it nothing happens! (I am on VB 2010 express fyi) my code is as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim X As Integer
Dim Y As Integer
Dim CNT As Integer
X = 1
Y = 0
For CNT = 1 To 8
Debug.Print(X)
X = Y + X
Y = X - Y
Next
End Sub
when I run it it doesn't give me any errors, but nothing comes up, also where i put in debug.print the debug is blue, the print is not (in the tutorial it is the other way around), does this mean anything, or am i just paranoid. i think that is where the problem is, if i put a MsgBox(X) on the next line after the debug.print it comes up with the numbers one at a time, is there a way to show them all at once?
thanks, i am fairly new at this but i really like this site, it actually tells you what is going on!

Problem with prgram

Hi Im fairly new to VB and really need some help with some code.
I would really appreciated any help. The code is as follow....I know
my problem is trying to get out of the loop...I don't even understand the secone part.
Please....help

Option Strict On
Option Explicit On
 
Public Class gradplan
    Const fullTimeTuition As Decimal = 2485
    Const partTimeTuition As Decimal = 207
    Const inflationRate As Double = 0.02
    Const totHoursForGrad As Integer = 120
 
 
    Private Sub btnToGrad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToGrad.Click
 
 
        Dim currentYear As Integer
        Dim currentTerm As String
        Dim totalHours As Integer
 
        Dim termHours As Integer
        Dim tuition As Decimal
 
        'initialize totalhours to txtStartHours.Text
        totalHours = CInt(txtStartHours.Text)
 
        'Print the headings in the labels
        lblGradInfo.Text = "     Term" & "     Hours" & "     Tuition" _
        & "     Tot Hrs"
 
        While totalHours <> totHoursForGrad
 
            ' Determine the hours
            Select Case txtStartTerm.Text
                Case Is = "U"
                    txtStartHours.Text += txtSummerHours.Text
                Case Is = "F"
                    txtStartHours.Text += txtFallHours.Text
                Case Is = "S"
                    txtStartHours.Text += txtSpringHours.Text
                Case Else
                    txtStartTerm.Text = ("Enter a Valid Start Term F/ S/ U")
            End Select
 
            currentTerm = txtStartTerm.Text
 
            'calcualte tuition
            If currentTerm = "F" Or currentTerm = "S" Then
                If totalHours >= 12 And totalHours <= 15 Then
                    tuition = fullTimeTuition
                    tuition = CInt(fullTimeTuition * inflationRate)
                Else
                    tuition = partTimeTuition * totalHours
                End If
            Else
                tuition = partTimeTuition * totalHours
            End If
 
            'Add term hours to total hours
            termHours = totalHours
 
            'Print Label
            lblGradInfo.Text = currentTerm & CStr(currentYear) & CStr(totalHours) _
            & FormatCurrency(tuition) & CStr(totalHours)
 
            currentYear += 1
 
        End While
    End Sub
 
    Private Sub btnMaxTerms_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMaxTerms.Click
        Dim strTerms As String
 
 
 
 
 
        strTerms = InputBox("Enter Maximum Terms")
    End Sub
End Class

This is what it is soppose to do...I"m so sorry its long, and appreciate your tme.

This code will do the following : The user will enter their starting term (txtStartTerm)and year (txtStartYear), and starting credit hours (txtStartHours) in the textboxes along the top line of the form. In the second line the user will enter the number of credit hours they plan to take in each of their remaining fall (txtFallHours) , spring (txtSpringHours), and summer terms (txtSummerHours). The user than can click either the "To Graduation" button (btnToGrad)or the "Max Terms" button (btnMaxTerms). The "To Graduation" button will compute and display a term by term plan for each term from the starting term until the student attains the total credit hours needed for graduation (120 hours). Some students have a specific number of terms in mind by which time they must graduate. The "Max Term" button will allow the user to enter this number (via an input box) and will produce a plan for just that many terms, regardless of when the total hours reaches 120.
For the max term button i need to use mostly all the code for the to graduation button.
I don't have any runtime errors, but I think I have a never ending loop. I cant seem to fine the mistake.
I attached a working version is attatched

calculate using eponent

our prof. required as to use exponent in visual basic and we are prohibited to use this sign (^), what alternatives can we possibly use ?? :)) loops? what specific loops ? thanks! :)

calculate using exponent

Anne, just an idea, but maybe your prof. was thinking along these lines:

x^3 x * x * x (3 times)

x^5 x * x * x * x * x (5 times)

So x^n would be
result = 1
for counter = 1 to n
result = result * x
loop

But that's just an idea. And it only works for positive integer n.

For is a good idea for exponent!

I agree with Nick. Here is one more example:

Let's say that Text1 is the text box that user can enter the base and Text2 is the text box for the exponent. Also, Command1 is the command botton that calculates the amount. The code for the Command1 is the below one:

Private Sub Command1_Click()
Dim Exp As Double
Exp = Text1.Text
For I = 1 To Text2.Text - 1
Exp = Exp * Text1.Text
Next
MsgBox Format(Exp, "#,##")
End Sub

vending machine

hi, tnks 4 the cool site. I'm stuck & any help will b great!
I have 2 write a simulation program in vb6 4 a vending machine using drag&drop 4 coins & bars.
can any one give me any ideas plz.

Just great!

Just great!

Great Tutorial

Thanks so much! This tutorial was really helpful. I'll be sure to check out your other stuff too :)

Programming help

Write a program that looks for the first number over 100 that is divisible both by 3 and 4. Here is the strategy you are to use:

write a loop that starts counting at 100
if the current number is divisible by 3 and 4
print a message that states the current number and that it is divisible by 3 and 4
break out of the loop
if the current number is divisible by 3
print a message that the current number is divisible by 3, but not by 4
otherwise if the current number is divisible by 4
print a message that the current number is divisible by 4, but not by 3
otherwise print a message that the current number is not divisible by either 3 or 4
increase the current value by 1

Note that the above is pseudo-code (that is, an outline written in English, not C). It does not include punctuation, braces, etc., although the indentation provides information about where loop and if/else parts start and end.

Here is a sample run (your wording may be slightly different):

100 is divisible by 4, but not by 3
101 is not divisible by 3 or by 4
102 is divisible by 3, but not by 4
103 is not divisible by 3 or by 4
104 is divisible by 4, but not by 3
105 is divisible by 3, but not by 4
106 is not divisible by 3 or by 4
107 is not divisible by 3 or by 4
108 is the first number over 100 that is divisible by 3 AND 4!

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
{
int i;
for( i=100; i<=108; i++ )
printf("100 is divisable by 4, but not 3 .\n");
printf("101 is not divisible by 3 or by 4.\n");
printf("102 is divisible by 3, but not by 4.\n");
printf("103 is not divisible by 3 or by 4 .\n");
printf("104 is divisible by 4, but not by 3 .\n");
printf("105 is divisible by 3, but not by 4 . \n");
printf("106 is not divisible by 3 or by 4 . \n");
printf("107 is not divisible by 3 or by 4 . \n");
printf("108 is the first number over 100 that is divisible by 3 AND 4! .\n");

}

// These next lines pause the computer. Not needed on all compilers.
printf("\n\nPress [ENTER] to exit the program.\n");
fflush(stdin);
getchar();

return 0;
}

Thats what I got so far I know i Have if statements but not in my code confused about that. Im new at this but im trying!!

you can try using a linked

you can try using a linked list to make your life easier :)

Private Sub

Private Sub Form_Load()
Do
Beep
Loop
End Sub

:D nice

:D nice

PLS HELP ME WITH THIS

PLS HELP ME WITH THIS PROBLEM
K/M=0.c1,c2,c3,...,cn,..., where K and M are given natural numbers (K=5 and M=7) and the result must be with 100 decimals.

regular expression

hi,

can anyone help me create a vb code for regular expressions
for example the expression is a*b*
will input strings in a textbox then after pressing the OK button, a message box will show saying if the inputted string is "valid" or "invalid" for the declared expression.
for example the input is 'aabb', the message box should show "valid"

thank you.

My vb6 Xsignment

By using the loop Do ... until construct a program that will continuously check if the user entered PIN number is true. Users are allowed three attempts only input pin number, if not the message "PIN NOT VALID" is displayed and the program is terminated.

vb

program for printing tables from 1-10 on a label using for loop?
please reply.

vb..

olivera
do you mean??

dim i as integer

i = val(text1.text)
for i = val(text.text) to 20
label.caption i, "*"
next

is that what you mean??.... i can understand your question... im sorry :) i wish that will help you

VB 6.0

I am working on a grading system. how can i change the percentage if it is already encoded?

Easy solution

Use variables.
If that's not what you mean, then I don't know what you are talking about.

Fibonacci Series!!

please help me guys!! please make me a program which includes FIBONACCI SERIES and looping!!... please please!! i need it for my assignment and i am quite new with vb!!..... :(( HEELLLPPP MMEEE PLEASEEEEE..

Fibonacci Series!!

olivera

i wish this will help you...
private sub cmdfibo_click
Dim fibonacci(10) As Long
Dim i As Integer
fibonacci(1) = 1
fibonacci(2) = 1
For intCount = 3 To 10
fibonacci(i) = fibonacci(i - 1) + fibonacci(i - 2)
Next i
For i = 1 To 10
picturebox.Print fibonacci(i)
Next i
End Sub

no it didnt help

no it didnt help us............. make a better program nxt tym

please give me a program

please give me a program using a Fibonacci series! with looping! i am new to programming!! pleaseee!!!!

btw, i am using vb.

Im trying to figure it out?

Hi how can i solve this problem . Example :- if i set up a number of folders that each contain a number of dummy photograph files. (e.g. simple Word files).The names of these dummy files have to be the names allocated to the imagined photographs.And how to display of where photographs that meet the given criteria can be found?
The user interface must consist of two forms and One to allow Mark to enter the details he has decided into the text file and maintain that information.One to request the paths to photographs that meet selected simple criteria and display these paths in a list. it is possible to append to an existing text file, any significant updating of a serial file by programming VB 2008 implies that the file has to be rewritten.

plzz help

plz help . how to make find sum of first 10 natural numbers, using for next looping