ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select Case Type Mismatch (https://www.excelbanter.com/excel-programming/426581-select-case-type-mismatch.html)

Ken

Select Case Type Mismatch
 
I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select

joel

Select Case Type Mismatch
 
What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select


Ken

Select Case Type Mismatch
 
Thanks for getting back to me.
I am trying to evaluate 3 different textboxes on a form. A person can be
entering x and y coordinates for a projection either Right or Left of center.
There are going to be 8 different configurations, 2 for each quadrant.
So I want to test if:
side= R
x 0
Y 0
Then the y needs to be negative. And so on for 7 more conditions.

"joel" wrote:

What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select


joel

Select Case Type Mismatch
 
Lets use binaray arithmetic to get 8 results

Index = 0
If Frm_Locations_UnBound.Side = "L" then
Index = Index + 4
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 2
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 1
end if

Select Case Index
Case 0 'R x<0 y<0

Case 1 'R x=0 y<0

Case 2 'R x<0 y=0

Case 3 'R x=0 y=0

Case 4 'L x<0 y<0

Case 5 'L x=0 y<0

Case 6 'L x<0 y=0

Case 7 'L x=0 y=0

end Select
"Ken" wrote:

Thanks for getting back to me.
I am trying to evaluate 3 different textboxes on a form. A person can be
entering x and y coordinates for a projection either Right or Left of center.
There are going to be 8 different configurations, 2 for each quadrant.
So I want to test if:
side= R
x 0
Y 0
Then the y needs to be negative. And so on for 7 more conditions.

"joel" wrote:

What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select


joel

Select Case Type Mismatch
 
I just realized that your numbers are in textboxes so you have to use VAL()
and I had X twice instead of X (+2) and Y (+1).

Index = 0
If Frm_Locations_UnBound.Side = "L" then
Index = Index + 4
end if
If Val(Frm_Locations_UnBound.DeptFromRefX) = 0 then
Index = Index + 2
end if
If val(Frm_Locations_UnBound.DeptFromRefY) = 0 then
Index = Index + 1
end if

Select Case Index
Case 0 'R x<0 y<0

Case 1 'R x=0 y<0

Case 2 'R x<0 y=0

Case 3 'R x=0 y=0

Case 4 'L x<0 y<0

Case 5 'L x=0 y<0

Case 6 'L x<0 y=0

Case 7 'L x=0 y=0

end Select


"joel" wrote:

Lets use binaray arithmetic to get 8 results

Index = 0
If Frm_Locations_UnBound.Side = "L" then
Index = Index + 4
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 2
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 1
end if

Select Case Index
Case 0 'R x<0 y<0

Case 1 'R x=0 y<0

Case 2 'R x<0 y=0

Case 3 'R x=0 y=0

Case 4 'L x<0 y<0

Case 5 'L x=0 y<0

Case 6 'L x<0 y=0

Case 7 'L x=0 y=0

end Select
"Ken" wrote:

Thanks for getting back to me.
I am trying to evaluate 3 different textboxes on a form. A person can be
entering x and y coordinates for a projection either Right or Left of center.
There are going to be 8 different configurations, 2 for each quadrant.
So I want to test if:
side= R
x 0
Y 0
Then the y needs to be negative. And so on for 7 more conditions.

"joel" wrote:

What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select


Ken

Select Case Type Mismatch
 
Thats an approach I've never seen before.
Cool, Thanks.

Just out of curiosity, can you have multiple conditions for multiple
variables in a Select case?, or can you just test multiple conditions for 1
variable.

"joel" wrote:

Lets use binaray arithmetic to get 8 results

Index = 0
If Frm_Locations_UnBound.Side = "L" then
Index = Index + 4
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 2
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 1
end if

Select Case Index
Case 0 'R x<0 y<0

Case 1 'R x=0 y<0

Case 2 'R x<0 y=0

Case 3 'R x=0 y=0

Case 4 'L x<0 y<0

Case 5 'L x=0 y<0

Case 6 'L x<0 y=0

Case 7 'L x=0 y=0

end Select
"Ken" wrote:

Thanks for getting back to me.
I am trying to evaluate 3 different textboxes on a form. A person can be
entering x and y coordinates for a projection either Right or Left of center.
There are going to be 8 different configurations, 2 for each quadrant.
So I want to test if:
side= R
x 0
Y 0
Then the y needs to be negative. And so on for 7 more conditions.

"joel" wrote:

What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select


joel

Select Case Type Mismatch
 
Select case can only be one value, but it could be a combination of variables
like

Select Case (OptionA and OPtionB)

where option A & b are booleans.

"Ken" wrote:

Thats an approach I've never seen before.
Cool, Thanks.

Just out of curiosity, can you have multiple conditions for multiple
variables in a Select case?, or can you just test multiple conditions for 1
variable.

"joel" wrote:

Lets use binaray arithmetic to get 8 results

Index = 0
If Frm_Locations_UnBound.Side = "L" then
Index = Index + 4
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 2
end if
If Frm_Locations_UnBound.DeptFromRefX = 0 then
Index = Index + 1
end if

Select Case Index
Case 0 'R x<0 y<0

Case 1 'R x=0 y<0

Case 2 'R x<0 y=0

Case 3 'R x=0 y=0

Case 4 'L x<0 y<0

Case 5 'L x=0 y<0

Case 6 'L x<0 y=0

Case 7 'L x=0 y=0

end Select
"Ken" wrote:

Thanks for getting back to me.
I am trying to evaluate 3 different textboxes on a form. A person can be
entering x and y coordinates for a projection either Right or Left of center.
There are going to be 8 different configurations, 2 for each quadrant.
So I want to test if:
side= R
x 0
Y 0
Then the y needs to be negative. And so on for 7 more conditions.

"joel" wrote:

What are you doing? the AND is producing a TRUE or FALSE result. Then you
can't compare "R" 0 (a character with a digit). You can search for a
String as folows

if Instr(MyStr, "R") 0

Instr indicates where one string is llocated i another str string. If the
string is not found you get 0.

"Ken" wrote:

I have a "Select Case" arrangement (below) and it is giving me a Type
mismatch error. This is based on a user form.
I tried using the Val() on the two numbers with no results. The variable
deptx,y is previously populated and works.
any help is greatly appreciated.

SELECT CASE Frm_Locations_UnBound.Side AND
Frm_Locations_UnBound.DeptFromRefX AND Frm_Locations_UnBound.DeptFromRefY
Case Is = "R", Is 0, Is 0 'NE Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is 0, Is 0 'NE Quad Left
deptx = deptx * -1
depty = depty
Case Is = "R", Is 0, Is < 0 'SE Quad Right
deptx = deptx * -1
depty = depty * -1
Case Is = "L", Is 0, Is < 0 'SE Quad Left
deptx = deptx
depty = depty
Case Is = "R", Is < 0, Is < 0 'SW Quad Right
deptx = deptx * -1
depty = depty
Case Is = "L", Is < 0, Is < 0 'SW Quad Left
deptx = deptx
depty = depty * -1
Case Is = "R", Is < 0, Is 0 'NW Quad Right
deptx = deptx
depty = depty * -1
Case Is = "L", Is < 0, Is 0 'NW Quad Left
deptx = deptx * -1
depty = depty * -1
End Select



All times are GMT +1. The time now is 12:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com