Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Call a proc inside itself (HELP)

Hello,
I have a problem...
I call my proc inside itself and here's what happens...

for example :
****
Sub test()

Dim MyYear as Variant
Dim AnyString as String

MyYear = Inputbox("type your date (yyyy)")

Select Case MyYear
Case 1900 to 2000
AnyString = "20th Century"
Case 2001 to 2050
AnyString = "Begining of 21Th Century"
Case else
AnyThing = "This is not a valid Date"
' I'M HERE RECALLING THE SAME SUB SO I CAN HAVE THE INPUTBOX AGAIN
call test ' (or just test)
End Select

Msgbox AnyString
End sub
****

Unfortunatly... if i run my modules and for several time put something else
than a number to my inputbox, it will run my inputbox several time but ALSO
would run the MSGBOX ANYSTRING as much as time... so i have onr right
message and several-1 not as good !!

Can anyone tell me what i'm doing wrong PLEASE !
Thnx

David.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Call a proc inside itself (HELP)

Sub test()

Dim MyYear as Variant
Dim AnyString as String
AnyString = "Invalid Input"

Do
MyYear = Inputbox("type your date (yyyy)")

Select Case MyYear
Case 1900 to 2000
AnyString = "20th Century"
Case 2001 to 2050
AnyString = "Begining of 21Th Century"
Case else
AnyString = "Invalid input"
End Select

Msgbox AnyString
Loop While lcase(anystring) = "invalid input"
End sub


--
Regards,
Tom Ogilvy

"David" wrote in message
...
Hello,
I have a problem...
I call my proc inside itself and here's what happens...

for example :
****
Sub test()

Dim MyYear as Variant
Dim AnyString as String

MyYear = Inputbox("type your date (yyyy)")

Select Case MyYear
Case 1900 to 2000
AnyString = "20th Century"
Case 2001 to 2050
AnyString = "Begining of 21Th Century"
Case else
AnyThing = "This is not a valid Date"
' I'M HERE RECALLING THE SAME SUB SO I CAN HAVE THE INPUTBOX AGAIN
call test ' (or just test)
End Select

Msgbox AnyString
End sub
****

Unfortunatly... if i run my modules and for several time put something

else
than a number to my inputbox, it will run my inputbox several time but

ALSO
would run the MSGBOX ANYSTRING as much as time... so i have onr right
message and several-1 not as good !!

Can anyone tell me what i'm doing wrong PLEASE !
Thnx

David.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Call a proc inside itself (HELP)


Hello David,

Thanks goes out to Tom, again. You noticed to expected behavior of
recursion with Excel VBA. Note: Your solution requires a call to a function
which returns the desired string value or a error message. Thus the calling
function can then drive require loop until a valid date is entered.

Answer by community.

Sonny Kocak
a-sonnykne.microsoft.com
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.




--------------------
| From: "Tom Ogilvy"
| References:
| Subject: Call a proc inside itself (HELP)
| Date: Tue, 3 Feb 2004 16:32:39 -0500
| Lines: 72
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID:
| Newsgroups: microsoft.public.excel.programming
| NNTP-Posting-Host: host-141-116-172-231.ptr.hqda.pentagon.mil
141.116.172.231
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.excel.programming:459001
| X-Tomcat-NG: microsoft.public.excel.programming
|
| Sub test()
|
| Dim MyYear as Variant
| Dim AnyString as String
| AnyString = "Invalid Input"
|
| Do
| MyYear = Inputbox("type your date (yyyy)")
|
| Select Case MyYear
| Case 1900 to 2000
| AnyString = "20th Century"
| Case 2001 to 2050
| AnyString = "Begining of 21Th Century"
| Case else
| AnyString = "Invalid input"
| End Select
|
| Msgbox AnyString
| Loop While lcase(anystring) = "invalid input"
| End sub
|
|
| --
| Regards,
| Tom Ogilvy
|
| "David" wrote in message
| ...
| Hello,
| I have a problem...
| I call my proc inside itself and here's what happens...
|
| for example :
| ****
| Sub test()
|
| Dim MyYear as Variant
| Dim AnyString as String
|
| MyYear = Inputbox("type your date (yyyy)")
|
| Select Case MyYear
| Case 1900 to 2000
| AnyString = "20th Century"
| Case 2001 to 2050
| AnyString = "Begining of 21Th Century"
| Case else
| AnyThing = "This is not a valid Date"
| ' I'M HERE RECALLING THE SAME SUB SO I CAN HAVE THE INPUTBOX
AGAIN
| call test ' (or just test)
| End Select
|
| Msgbox AnyString
| End sub
| ****
|
| Unfortunatly... if i run my modules and for several time put something
| else
| than a number to my inputbox, it will run my inputbox several time but
| ALSO
| would run the MSGBOX ANYSTRING as much as time... so i have onr right
| message and several-1 not as good !!
|
| Can anyone tell me what i'm doing wrong PLEASE !
| Thnx
|
| David.
|
|
|
|
|

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 Data -- SQL Server proc or function with parameter lm Excel Discussion (Misc queries) 1 August 21st 09 10:49 PM
running proc in excel just_real Excel Discussion (Misc queries) 1 November 21st 08 06:51 AM
Call Center Management: How to calculate 'cost per call' Denniso6 Excel Discussion (Misc queries) 2 June 25th 06 05:01 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM
How do you call one Sub from another Sub ? lothario[_30_] Excel Programming 2 October 17th 03 01:47 PM


All times are GMT +1. The time now is 05:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"