end loop

  • Thread starter Thread starter Murt
  • Start date Start date
M

Murt

on my inbox below i want the loop to quit if the user enters End,

It does not function as written,

any ideas?

thanks

----------------------
Dim inputString As String

Dim i As Integer

For i = 0 To n + 1
farmers(i) = InputBox("enter a farmer's name", , "<farmer>")

If inputString = "end" Then

Exit For

End If

Next

----------------------
 
Murt, you haven't ever assigned a value to inputString - testing the string
for "end" is therefore wasted effort.

If you really must keep the code construct the way you have written it, the
minimal changes required to get your code going have been amended to your
original posting below. I would think of alternative logic such as adding a
new farmer name to an ArrayList until an "end" is detected, then converting
to a String array of farmer.

This is all looks very similiar to a question asked by "portroe" on 02
Friday 2004 ;)

Regards
Hexathioorthooxalate


Dim inputString As String

For i = 0 To n + 1
inputString = InputBox("enter a farmer's name", , "<farmer>")
If inputstring = "end" Then
Exit For
Else farmers(i)=inputstring
End If
Next
 
You are not assigning anyting to inputString! Instead, you are assigning the
InputBox result to farmers(i)

If inputString = "end" Then

should read

If farmers(i) = "end" Then

I would also suggest using farmers(i).ToLower = "end" to ignore case entered
by user
 
* Murt said:
on my inbox below i want the loop to quit if the user enters End,

It does not function as written,
[...]

See corrected code below:
 
Hi Herfried,

I find the complete answer from Jim 2 hours before you much better.
(My answer was exaclty the same , inclusief the tolower)

Cor
 
* "Cor said:
I find the complete answer from Jim 2 hours before you much better.

I find it not as good as mine because it reads "end" into the array
which is not the name of a farmer.
(My answer was exaclty the same , inclusief the tolower)

You didn't post an answer...
 
Hi Murt,

Looking to the answer from Herfried, I think my answer was to him was wrong.

This is a kind of streaming operation and therefore I think that it is right
to do it that way

dim i as integer = 0
farmers(i) = InputBox("enter a farmer's name", , "<farmer>")
do until farmers(i).tolower = "end"
i +=1
farmers(i) = InputBox("enter a farmer's name", , "<farmer>")
loop
i -=1

Cor
 
Hi Herfried,

Your answer about the last farmer is right, (could be easily corrected with
a i -= 1, but I think this problem needs another approach, see my answer to
Murt, now your answer would fail because there is no integer n, but that is
of course a not important detail.

Cor
 
* "Cor said:
Your answer about the last farmer is right, (could be easily corrected with
a i -= 1, but I think this problem needs another approach, see my
answer to

I based my solution on the info the OP gave us/me in his original
thread.
 
Back
Top