Big DO loop problem:(

Big DO loop problem:(

Post by Minota » Thu, 29 Apr 2004 08:26:06


For some reason, Do loops do not work at all for me. It keeps telling me,
"Loop without do", when I have a "DO" in my damn program!!!!! I am
following book examples exactly and the code still does not work:( My code
is below. Can anyone help?

dim whatmonth As String
Dim month As String

Private Sub CmdMonth_Click()
whatmonth = InputBox("What month do you wish to know the number of days?",
"Type a Month")
month = whatmonth

f = 1

Select Case LCase(month)
Case Is = "january"
picMonth.Cls
picMonth.Print "January has 31 days"
Case Is = "february"
picMonth.Cls
Call Febber(f, Feb)
picMonth.Print "February has "; f; " days"
Case Is = "march"
picMonth.Cls
picMonth.Print "March has 31 days"
Case Is = "april"
picMonth.Cls
picMonth.Print "April has 30 days"
Case Is = "may"
picMonth.Cls
picMonth.Print "May has 31 days"
Case Is = "june"
picMonth.Cls
picMonth.Print "June has 30 days"
Case Is = "july"
picMonth.Cls
picMonth.Print "July has 31 days"
Case Is = "august"
picMonth.Cls
picMonth.Print "August has 31 days"
Case Is = "september"
picMonth.Cls
picMonth.Print "September has 30 days"
Case Is = "october"
picMonth.Cls
picMonth.Print "October has 31 days"
Case Is = "november"
picMonth.Cls
picMonth.Print "November has 30 days"
Case Is = "december"
picMonth.Cls
picMonth.Print "December has 31 days"
Case Else
picMonth.Cls
picMonth.Print "That month does not exist! Try again!!!!"
End Select

End Sub

Private Sub Febber(f, Feb)

Do While f=1
Feb = InputBox("Is this a leap year?", "Leap Year?")

If UCase(Feb) Like "Y*" Then
f = 29
ElseIf UCase(Feb) Like "N*" Then
f = 28
Else: f = 1
Loop

End Sub
 
 
 

Big DO loop problem:(

Post by dantex » Thu, 29 Apr 2004 08:41:45

>Subject: Big DO loop problem:(

I don't see an "EndIf" to complete your IF block??? Likely your problem?
The error message merely has problems diagnosing your error clearly.

I've note this type of "apparently misguided" error message before in other
compilers ( ie.. not just VB ). IF blocks, DO loops, FOR loops.... there
are similar. It must be difficult for error checking code to keep things 110%
straight. In any case... there error message points to some type of problems
with your programs Blocking structure.

Dan :-)

 
 
 

Big DO loop problem:(

Post by fajp » Thu, 29 Apr 2004 09:15:25


Yup, i'd say so too.
Especially for newbies (although i still do this myself) i would
recommend to write if or select blocks by writing out the conditional
part and straigh away putting the block end line down. Then go up and
fill in the in-between stuff. Putting a little reminder at the end
line also helps, when things span out a bit longish.

S'thing like :
if boo then
end if 'boo


--

Regards, Frank
 
 
 

Big DO loop problem:(

Post by Minota » Thu, 29 Apr 2004 11:15:38

Thank you both for all of your help!!! Yep, looks like I missed the "end
if" there, and now the code works perfect!!! One question for you guys if I
may; is there a way to use "Case like something" with Select Case? I know
you can use <>= not, etc... but when I try "like" it gives me an error? I
wanted to try to set up the below program so that if the person accidently
mispells the month, it still will work using case like "feb" for example.
But Select case does not seem to like, "like", which is mind boggling to me.
Or is there a special syntax to use for that? Any ideas? And thanks again
for al the help!!!! One step closer for me to not be a VB newbie:)





problem?
 
 
 

Big DO loop problem:(

Post by Steve Gerr » Thu, 29 Apr 2004 12:00:03


other
there
things 110%
problems

It seems that all or most compilers treat all blocks as if they ended
the way they do in C, with just a } at the end. Since it would be
unfair to expect a compiler to know which } you left out, VB and other
compilers also just punt and point their finger at the first (or is it
the last?) thing they find, even though VB could get a better clue by
matching up If's and End If's, etc.
 
 
 

Big DO loop problem:(

Post by Randy Birc » Thu, 29 Apr 2004 12:10:19

Here's a thought! ... why not write code to determine if the year is a leap
year, then you won't have to ask the user (who may respond incorrectly) ...
http://www.yqcomputer.com/

--

Randy Birch
MVP Visual Basic
http://www.yqcomputer.com/
Please respond only to the newsgroups so all can benefit.




: Thank you both for all of your help!!! Yep, looks like I missed the "end
: if" there, and now the code works perfect!!! One question for you guys if
I
: may; is there a way to use "Case like something" with Select Case? I know
: you can use <>= not, etc... but when I try "like" it gives me an error? I
: wanted to try to set up the below program so that if the person accidently
: mispells the month, it still will work using case like "feb" for example.
: But Select case does not seem to like, "like", which is mind boggling to
me.
: Or is there a special syntax to use for that? Any ideas? And thanks
again
: for al the help!!!! One step closer for me to not be a VB newbie:)
:
:



: >
: > >>Private Sub Febber(f, Feb)
: > >>
: > >>Do While f=1
: > >> Feb = InputBox("Is this a leap year?", "Leap Year?")
: > >>
: > >> If UCase(Feb) Like "Y*" Then
: > >> f = 29
: > >> ElseIf UCase(Feb) Like "N*" Then
: > >> f = 28
: > >> Else: f = 1
: > >>Loop
: > >>
: > >>End Sub
: > >
: > >I don't see an "EndIf" to complete your IF block??? Likely your
: problem?
: > >The error message merely has problems diagnosing your error clearly.
: > >
: > Yup, i'd say so too.
: > Especially for newbies (although i still do this myself) i would
: > recommend to write if or select blocks by writing out the conditional
: > part and straigh away putting the block end line down. Then go up and
: > fill in the in-between stuff. Putting a little reminder at the end
: > line also helps, when things span out a bit longish.
: >
: > S'thing like :
: > if boo then
: > end if 'boo
: >
: >
: > --
: >
: > Regards, Frank
:
:
 
 
 

Big DO loop problem:(

Post by Steve Garm » Thu, 29 Apr 2004 13:53:59

If you need to use Like in a case statement, you could try something
like this:

Dim mth As String
mth = "February"
Select Case True
Case mth Like "Jan*"
MsgBox "Jan"
Case mth Like "Feb*"
MsgBox "Feb"
Case mth Like "Mar*"
MsgBox "Mar"
End Select









--
Steve Garman
 
 
 

Big DO loop problem:(

Post by Steve Garm » Thu, 29 Apr 2004 14:16:32

Perhaps it wasn't very clear how this relates to your original case
statement.

Dim mth As String, whatmonth As String
whatmonth = "February"
mth = LCase(whatmonth)
Select Case True
Case mth Like "jan*"
MsgBox "Jan"
Case mth Like "feb*"
MsgBox "Feb"
Case mth Like "mar*"
MsgBox "Mar"
Case Else
MsgBox "None"
End Select

I've also shied away from using Month as a variable name, as this could
cause problems later if you try to use the built-in Month() function.





--
Steve Garman
 
 
 

Big DO loop problem:(

Post by erewho » Thu, 29 Apr 2004 16:38:26

On Tue, 27 Apr 2004 20:00:03 -0700, "Steve Gerrard"


<snip>


But to give VB its credit, it does have 'typed' end of clauses.

eg: End If, End Sub, Next, Wend

instead of: }, }, }, }, }
or: End;, End;, End;, End;, End;,
 
 
 

Big DO loop problem:(

Post by Mike Willi » Thu, 29 Apr 2004 17:40:30


I know that you're just investigating the Case stuff in order to learn more
about VB, and I certainly don't want to put you off doing that, but why not
also try investigating the DateDiff stuff, which can be very useful. For
example, instead of all those Case statements why not just get DateDiff to
tell you the number of days (after a bit of manipulation of the user's
input). Something like:

Print DateDiff("d", "1 February 2004", "1 March 2004")

Mike
 
 
 

Big DO loop problem:(

Post by butlerbo » Fri, 30 Apr 2004 01:40:46


in that case (pun intended) use an If/ElseIf construct. Dont'
bastardize a Select Case into being a substitute for the "proper"
structure.

If mth Like "Jan*" Then
msgbox "Jan"
ElseIf mth Like "Feb*" Then
<etc>

"Select Case True" is an abomination that *must* be stamped out in our
lifetimes.
 
 
 

Big DO loop problem:(

Post by Rick Roths » Fri, 30 Apr 2004 02:49:38

> > If you need to use Like in a case statement, you could try something

What's with all this If-Then or Select-Case stuff? The user can enter
three or more letters in the month and this code will work...

Private Sub CmdMonth_Click()
Dim Mth As Integer
Dim Days As Integer
Mth = Month(InputBox("What month?") & " 1, 9999")
On Error GoTo Oops
Days = Day(DateSerial(Year(Now), 1 + Mth, 0))
MsgBox MonthName(Mth) & " has " & Days & " days."
Exit Sub
Oops:
MsgBox "No such month!"
End Sub

<g>

Rick - MVP
 
 
 

Big DO loop problem:(

Post by Minota » Fri, 30 Apr 2004 06:53:33

Whoa, whoa, woah!!!! What is going on here? I think I should have stressed
that I am a VB newbie learning things one at a time. Of course, there are
20 ways to solve my problem, but I am just getting select case down, guys!
You guys are killin me here, LOL!!!! Thanks for the help, but I am starting
to get lost now:(

Jerry
 
 
 

Big DO loop problem:(

Post by Rick Roths » Fri, 30 Apr 2004 10:38:23

While the code I posted works, there was a <g> at the end of my message.
The others responders addressed what needed addressing, so I thought I'd
have a little fun. However, you should take away from my code that there
are more than one way to create code for your programs, some better than
others (experience will eventually tell you which). Let what I posted me
a motivator for you to learn as much as you can about VB so that you can
envision the multitude of solutions for yourself in order to pick the
one that works best for whatever your situation is at the time.

Rick




stressed
are
guys!
starting


something
enter
 
 
 

Big DO loop problem:(

Post by fajp » Fri, 30 Apr 2004 11:56:42

On Wed, 28 Apr 2004 17:53:33 -0400, "Minotar" < XXXX@XXXXX.COM >


Just keep to what was said at first and/or what you did understand.
It sometimes can get a bit difficult for newbies to keep up here, as
there are many ways of doing things and there are many different
programmers subscribing to different "cultures".
"Select Case True" is fine to use if you do understand that better.
Just because some (Bob <g>) don't like it, it doesn't mean it's bad to
use. And just because some others can make one liners (Rick <g>) to
scare the newbies, it doesn't mean you are forced to use those either.

However, it's just another way of learning new and old tricks. Bob's
if-then thing is just as good as the select case, and Rick's idea is..
well..as always, interestingly incomprehensible. ;-)

--

Regards, Frank