VB Newbie - code guidance required

DoctorNash
DoctorNash used Ask the Experts™
on
Thanks for taking a look at this! I'm pretty sure I'm making a fundamental error here (still at 'Chapter 1' as far as programming in general, and VB in particular is concerned!)

The application is supposed to convert from either US to (UK and European), or UK to (US and European) dress sizes, depending on what the user selects (the user first presses 'convert from UK' or 'convert from US' option button, then types in the size he/she wishes to convert from in a text box, then presses 'convert' button and the result appears in an adjacent window). What is happening in the following code is that now matter which option the user chooses, the application insists on converting from UK to US and European size only! Is it a problem with the branching statements? Any other tips re. this code will of course also be truly appreciated. Thanks again.

Option Explicit
Dim numselect As Integer

Private Sub Command1_Click()
Dim value As Integer
Select Case numselect
Case 2
GoTo US
Case 1
GoTo UK
End Select

US:
value = Text1.Text
If Val(value) Mod 2 <> 0 And Val(value) >= 6 And Val(value) <= 20 Then
MsgBox "size must be an even number"
ElseIf Val(value) Mod 2 <> 0 And Val(value) < 6 Then
MsgBox "size must be an even number and between 6 and 20"
ElseIf Val(value) Mod 2 <> 0 And Val(value) > 20 Then
MsgBox "size must be an even number and between 6 and 20"
ElseIf Val(value) < 6 Then
MsgBox "size must be in range 6 to 20"
ElseIf Val(value) > 20 Then
MsgBox "size must in range 6 to 20"
End If
 
Select Case value
Case 6
Text2.Text = "UK size 8, Euro size 34"
Case 8
Text2.Text = "UK size 10, Euro size 36"
Case 10
Text2.Text = "UK size 12, Euro size 38"
Case 12
Text2.Text = "UK size 14, Euro size 40"
Case 14
Text2.Text = "UK size 16, Euro size 42"
Case 16
Text2.Text = "UK size 18, Euro size 44"
Case 18
Text2.Text = "UK size 20, Euro size 46"
Case 20
Text2.Text = "UK size 22, Euro size 48"

End Select

UK:
value = Text1.Text
If Val(value) Mod 2 <> 0 And Val(value) >= 8 And Val(value) <= 22 Then
MsgBox "size must be an even number"
ElseIf Val(value) Mod 2 <> 0 And Val(value) < 8 Then
MsgBox "size must be an even number and between 8 and 22"
ElseIf Val(value) Mod 2 <> 0 And Val(value) > 22 Then
MsgBox "size must be an even number and between 8 and 22"
ElseIf Val(value) < 8 Then
MsgBox "size must be in range 8 to 22"
ElseIf Val(value) > 22 Then
MsgBox "size must in range 8 to 22"
End If
 
Select Case value
Case 8
Text2.Text = "US size 6, Euro size 34"
Case 10
Text2.Text = "US size 8, Euro size 36"
Case 12
Text2.Text = "US size 10, Euro size 38"
Case 14
Text2.Text = "US size 12, Euro size 40"
Case 16
Text2.Text = "US size 14, Euro size 42"
Case 18
Text2.Text = "US size 16, Euro size 44"
Case 20
Text2.Text = "US size 18, Euro size 46"
Case 22
Text2.Text = "UK size 20, Euro size 48"

End Select

End Sub


Private Sub Form_Load()
Text1.Text = " "
Text2.Text = " "
Command1.Caption = "convert"
Option1.value = vbUnchecked
Option2.value = vbUnchecked
numselect = 0

End Sub

Private Sub Option1_Click()
numselect = 1
End Sub

Private Sub Option2_Click()
 
numselect = 2
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Looks like it's going to convert to US -- and then fall into the convert to UK -- which means it'll only end up with UK.

Put an "Exit Sub" immediately before the UK: label.

bhh

P.S. I personally prefer not to use goto's.

Select Case numselect
Case 2
    Do_US
Case 1
    Do_UK
End Select
...
Sub Do_US()
   ' US calculations
End Sub
Sub Do_UK
   ' UK calculations
End Sub

Author

Commented:
Thankyou greatly bhh! You have enabled me to take a few more steps forward in the long, long journey before me.
bhh

Commented:
Glad I could help.

bhh

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial