Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Statement
I have a following few lines of VBA codes. With input n=6, why is that when I
test dn it DOESN'T work, but test d(n+0) it works, which gives j=4. Thanks. n = InputBox("n") j = 0 Do While j < n j = j + 1 d = (n * j) / 3 If d (n + 0) Then Exit Do MsgBox ("d= ") & d & (" n= ") & n 'monitoring Loop MsgBox ("j= ") & j 'output |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Statement
I have the impression that if N is a Variant then N contains a string, not a
number, since Inputbox always return a string. The expression N+0 will be forced to be a number, since N is "casted" to a number. This can happen only if the user enters strings having only characters among 0...9. If N was an integer then assigning the return value of Inputbox would solve your problem, but in this case you'd better handle the error in case the user enters alphabetic data. Excerpt from the Help file: "Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String containing the contents of the text box." I hope this helps you. -- Stefano Gatto "zhj23" wrote: I have a following few lines of VBA codes. With input n=6, why is that when I test dn it DOESN'T work, but test d(n+0) it works, which gives j=4. Thanks. n = InputBox("n") j = 0 Do While j < n j = j + 1 d = (n * j) / 3 If d (n + 0) Then Exit Do MsgBox ("d= ") & d & (" n= ") & n 'monitoring Loop MsgBox ("j= ") & j 'output |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
Can an If statement answer an If statement? | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |