473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Simple If/Then/else Question

1
I'm trying to do a very simple if, then, else program in excel VBA (which I'ved simplified even further below). What I'm hoping will happen is that it will keep asking me for a variable until its greater than 5 and then it will post a single message of 'finished'
What actually happens is that depending on how many time I provide an input before I get to something that's greater than 5 it will then repeat the 'finished' message that number of times. What am I doing wrong.

Sub test()
Dim var1 As Variant

var1 = InputBox("variable please")
If var1 < 5 Then
Call test
Else
MsgBox ("two")
End If

MsgBox ("finished")
End Sub
Jun 26 '08 #1
1 1007
kadghar
1,295 Expert 1GB
Thats because the msgbox is shown once for everytime you call Test, because it always run up to the last line.

Imagine you enter the number > 5 in the 2nd attemp. then the first atemp will call Test again, in the second one, Test will finish and show "Finished", then it'll go back to finish the Test you started first, and i'll do so

Msgbox("two") will show only once ^.^
that'll give you an idea.

what i recomend you to do here is not to use a recursion formula. A single loop is enough:

Expand|Select|Wrap|Line Numbers
  1. sub test()
  2. dim var1
  3. do
  4.     var1=inputbox("variable please")
  5. loop until var1 > 5
  6. msgbox "two"
  7. msgbox "finish"
  8. end sub
HTH
Jun 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Graham Mattingley | last post by:
I think I have lost my brain, or drank too much Redbull, because I cant make the following work. if menu_list <> "age" OR menu_list <> "first_name" then .... else ....... end if
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
5
by: Tim::.. | last post by:
Can someone tell me how I convert this simple SQL statement so I can use it in ASP.NET??? I have an issue with the quotation marks and wondered if there is a simple rule for converting the sql...
0
by: pete | last post by:
Simple question, so simple answer I hope. I am trying to upgrade my asp skills to asp.net so please bear with me for a few moments. I want to create a simple custom control that returns a string...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
5
by: Support | last post by:
Hello: I have the following code that currently needs to go in every page. QUESTION 1) Can Page_Preinit go somewhere else more global like Global.asax so that I dont have to copy this code in...
6
by: Jim M | last post by:
I've been distributing a fairly mature, very specific MS Access application to end users in small offices of colleges for several years now. This is a part-time venture and low volume operation-...
3
by: asianmuscle | last post by:
Hi I am relearning datastructure... but got kinda stuck in a basic delete node operation. what it does is to delete the first node it finds when the item is equal the input item. the end result is...
2
by: Lawrence | last post by:
Hi I have only begun to look into ASP due to an assignments requirements (I usually code in PHP), one feature in PHP is to be able to do an if...else statement, where if a certain statement is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.