Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 86
Default Case Studies

I have a set of input boxes that all allow a number to be added. The entries
can be:
a. Correct (proceed to the next step)
b. Wrong (doesn't meet a criteria - re-input until correct or blank
c. Blank
The first number can't be blank; subsequent entries can be. If
blank, proceed to the next step*

There are a several ways to do this, including in my order of preference:.
1. Have a multiple-entry input box that would allow input of several
numbers, leaving the others blank.
2. Make it a separate subroutine.
3. Use Cases (I haven't tried this, yet)
4. imbed it in the regular code - what I'm doing, but I'm having difficulty
getting 'out'* on blank entries

Questions:
1. is a multi-entry input box a widget that is available? If so, how can I
get it?
2. What do you experts think is the 'best' approach?
3. How do I get out of a code section without getting into a series of GoTo
statements, that seem to create other problems?

Here's what I'm working with right now...

Do
areaCode2 = InputBox("Enter a Second Area Code, (if required)", "Area
Code 2", "", 80)
If areaCode2 = "" Then GoTo XXX

Set wb = ThisWorkbook
On Error Resume Next
Set wb2 = Workbooks.Open(Filename:=Environ("Userprofile") &
"\Desktop\" & areaCode2 & ".csv", ReadOnly:=True)
If wb2 Is Nothing Then
msg = MsgBox("The Area Code " & areaCode2 & " file does not
exist!" & vbLf & vbLf & "Please try again.", vbExclamation, "Input error")

Else
wb2OK = True
End If
On Error GoTo 0 ' (is '0' the beginning of all the code, or
the 'Do'?)
Loop Until wb2OK = True
XXX:

Suggestions?

Jim Berglund

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Case Studies

Hi Jim,

The following is an example of what you might use. Some comments.
Don't use GoTo to get out of a loop. Use Exit Do.
Try to give the user an Out by Cancelling at the inut stage. Users need to
be able to Cancel and exit a procedure. (Note Application.InputBox is
different from InputBox function. See Help for more info)
You can use Select Case in lieu of multiple If/End If.

Feel free to get back to me if still having problems.

Sub test()
Dim areaCode2 As Variant
Dim wb As Workbook
Dim wb2 As Workbook
Dim msg

Do
'Use Application.InputBox in lieu of just InputBox
'Allows identification of Cancel by user.
areaCode2 = Application.InputBox _
("Enter a Second Area Code, (if required)", _
"Area Code 2", "", 80)

'Following allows user to click Cancel and abort
If areaCode2 = False Then
MsgBox "User Cancelled. Processing terminated"
Exit Sub
End If

If areaCode2 = "" Then Exit Do 'Exit the Loop

Set wb = ThisWorkbook 'Not sure why this is here

On Error Resume Next
Set wb2 = Workbooks.Open _
(Filename:=Environ("Userprofile") & _
"\Desktop\" & areaCode2 & ".csv", _
ReadOnly:=True)

If wb2 Is Nothing Then
msg = MsgBox("The Area Code " & areaCode2 & _
" file does not exist!" & vbLf & vbLf & _
"Please try again.", vbExclamation, "Input error")

'GoTo LoopAgain
End If

'Use the GoTo LoopAgain if other code here to be
'skipped if wb2 is nothing.

'LoopAgain:
Loop

End Sub


--
Regards,

OssieMac


"Jim Berglund" wrote:

I have a set of input boxes that all allow a number to be added. The entries
can be:
a. Correct (proceed to the next step)
b. Wrong (doesn't meet a criteria - re-input until correct or blank
c. Blank
The first number can't be blank; subsequent entries can be. If
blank, proceed to the next step*

There are a several ways to do this, including in my order of preference:.
1. Have a multiple-entry input box that would allow input of several
numbers, leaving the others blank.
2. Make it a separate subroutine.
3. Use Cases (I haven't tried this, yet)
4. imbed it in the regular code - what I'm doing, but I'm having difficulty
getting 'out'* on blank entries

Questions:
1. is a multi-entry input box a widget that is available? If so, how can I
get it?
2. What do you experts think is the 'best' approach?
3. How do I get out of a code section without getting into a series of GoTo
statements, that seem to create other problems?

Here's what I'm working with right now...

Do
areaCode2 = InputBox("Enter a Second Area Code, (if required)", "Area
Code 2", "", 80)
If areaCode2 = "" Then GoTo XXX

Set wb = ThisWorkbook
On Error Resume Next
Set wb2 = Workbooks.Open(Filename:=Environ("Userprofile") &
"\Desktop\" & areaCode2 & ".csv", ReadOnly:=True)
If wb2 Is Nothing Then
msg = MsgBox("The Area Code " & areaCode2 & " file does not
exist!" & vbLf & vbLf & "Please try again.", vbExclamation, "Input error")

Else
wb2OK = True
End If
On Error GoTo 0 ' (is '0' the beginning of all the code, or
the 'Do'?)
Loop Until wb2OK = True
XXX:

Suggestions?

Jim Berglund

.

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
Minor puzzle: some UDF calls respect mixed case, others insist on lower case Prof Wonmug Excel Programming 5 May 1st 10 12:32 AM
Changing multiple cell text from lower case to upper case Patti Excel Discussion (Misc queries) 2 January 4th 08 08:35 PM
How do I get personal financial templates(blank) for studies dondada Excel Worksheet Functions 1 September 2nd 06 12:19 PM
Change the text from lower case to upper case in an Excel work boo dave01968 Excel Discussion (Misc queries) 2 December 9th 05 09:09 AM
Accuracy Studies Ginny Excel Discussion (Misc queries) 1 April 1st 05 03:42 AM


All times are GMT +1. The time now is 10:46 AM.

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"