# Thread: [RESOLVED] how can i test a number if is valid?

1. ## [RESOLVED] how can i test a number if is valid?

ok... the variable integer can get zero, positive and negative... until here fine...
imagine that 1 function\sub parameter is a type with X,Y,Z members.... and i only need use 1 of that members depending if 1 of them have a valid value....
if the X,Y,Z are integer, what value i can give them for test if is valid?
(yes i need zero, positive and negative... so how can i give an invalid value for i test it?)

2. ## Re: how can i test a number if is valid?

Code:
`Private Function GetLinePosition(Origin As Position3D, Destiny As Position3D, FromActual As Position3D) As Position3D`
by deafult the FromActual.X, FromActual.Y, FromActual.Z are zero... but i only need use just 1 of that members, so i need test if they are valid or not... how can i do it?

3. ## Re: how can i test a number if is valid?

3300+ posts? You are not very explicit in this question.

Do you want to see if a 'number' is a number? Or if a 'number' is an Integer? Or what?

4. ## Re: how can i test a number if is valid?

Quote from Charles Kettering:

A problem well stated is a problem half-solved

5. ## Re: how can i test a number if is valid?

"Do you want to see if a 'number' is a number?"
yes...
if i do:
Code:
`FromActual.Z=nothing`
is the same of zero?

7. ## Re: how can i test a number if is valid?

Again, will wait for (I hope) a better explanation. But, in the meantime, just consider what this code does:

Code:
```Private Sub Command1_Click()
If IsNumeric(Text1.Text) Then
MsgBox "Number is Numeric"
Dim x As Integer
x = InStr(1, Text1.Text, ".")  'integers will NOT have a period in it  (but do know this, that I am in the US, so not checking other countries' use of commas as separators)
If x = 0 Then
MsgBox "The Numeric Entry is an Integer"
Else
MsgBox "The Numeric Entry is NOT an integer"
End If
Else
MsgBox "What is entered is NOT Numeric"
End If
End Sub```

8. ## Re: how can i test a number if is valid?

i need use FromActual.X or FromActual.Y or FromActual.Z, it depends on their values...
- if 'Z' have a value, i must ignore the others;
- if 'X' have a value, i must ignore the others;
- if 'Y' have a value, i must ignore the others.

9. ## Re: how can i test a number if is valid?

Let's start over.

If you are asking what is a valid number? You must first define what are invalid numbers.

If you are asking, "I have 3 parameters and I need to ignore 2 of them depending on situations"? Then I would have to say, make a list of the situations so you can better visualize the problem.

10. ## Re: how can i test a number if is valid?

1st i'm so sorry if my question is confused:
see these sample:
Code:
```FromActual.X=nothing
'...............
if(FromActual.X!=nothing) then
'do something
end if```
same for others members... but i belive 'nothing' is zero...
(at least the string have 'empty' or '""')

11. ## Re: how can i test a number if is valid?

What vartype is X? Is it a variant?

If so, then if X isn't filled in its value will be Empty, i.e., If FromActual.X = Empty or If IsEmpty(FromActual.X) = True

12. ## Re: how can i test a number if is valid?

Code:
```Private Type Position3D
X As Double
Y As Double
Z As Double
End Type```
it's double

13. ## Re: how can i test a number if is valid?

Then .X will always be a number. It cannot be anything else

14. ## Re: how can i test a number if is valid?

Ok, I think I understand what you are asking.

You want to know if the value was actually changed by the user vs. being the default value VB assigns a double? Is that correct? If so, good luck with that. That's like asking if a Boolean was changed by the user to False when its default value is False.

If there was an invalid number that would never be used, you can always set X,Y,Z to that value. Then if it is that value, the user didn't change it.

15. ## Re: how can i test a number if is valid?

thank you so much for correct me...
thank you to all for all.. thank you

16. ## Re: [RESOLVED] how can i test a number if is valid?

If absolutely necessary, you might be able to user your UDT
Code:
```Private Type Position3D
X As Double
Y As Double
Z As Double
Changed As Boolean
End Type```

17. ## Re: [RESOLVED] how can i test a number if is valid?

the best is change these:
Code:
`Private Function GetLinePosition(Origin As Position3D, Destiny As Position3D, FromActual As Position3D) As Position3D`
to these:
Code:
`Private Function GetLinePosition(Origin As Position3D, Destiny As Position3D, ActualPosition As double, WhatCoordenate as string) As Position3D`

18. ## Re: [RESOLVED] how can i test a number if is valid?

VB6 functions have a buit-in mechanism to know whether a parameter has been set or not, but the input parameters need to be optional variants, not UDT's or other types.

Then you can test:

Code:
```Function MyFunction(Optional Parameter1 As Variant, Optional Parameter2 As Variant, Optional Parameter3 As Variant) As WhaterverType

If IsMissing(Parameter1)...```
In case that you want/need to use an UDT, you still can be able to test whether a member have been set or not, but you also need to use variants:

Code:
```Private Type Position3D
X As Variant
Y As Variant
Z As Variant
End Type

Function MyFunction(Values As Position3D) As WhaterverType

If IsEmpty(Values.X) Then...```

19. ## Re: [RESOLVED] how can i test a number if is valid?

thank you Eduardo i never knew about it.. thank you

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured