PC Review


Reply
Thread Tools Rate Thread

Case Studies

 
 
Jim Berglund
Guest
Posts: n/a
 
      30th May 2010
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 With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      31st May 2010
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Website design case studies Tom Miller Microsoft Frontpage 7 13th Apr 2007 02:22 AM
case studies on caching in asp.net 2.0 Vikram Microsoft ASP .NET 0 27th Jan 2006 01:59 PM
Please help for my studies Henry Microsoft VB .NET 0 5th Apr 2004 04:29 PM
Please help for my studies Henry Windows XP General 5 1st Apr 2004 04:48 PM
.NET Case Studies Jamie Microsoft Dot NET 1 24th Sep 2003 03:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:32 AM.