
May 21st, 2020, 02:21 PM
#1
Thread Starter
PowerPoster
[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?)

May 21st, 2020, 02:33 PM
#2
Thread Starter
PowerPoster
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?

May 21st, 2020, 02:38 PM
#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?
Sam I am (as well as Confused at times).

May 21st, 2020, 02:39 PM
#4
Re: how can i test a number if is valid?
Quote from Charles Kettering:
A problem well stated is a problem halfsolved

May 21st, 2020, 02:45 PM
#5
Thread Starter
PowerPoster
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?

May 21st, 2020, 02:47 PM
#6
Re: how can i test a number if is valid?
How about the IsNumeric() function?

May 21st, 2020, 02:48 PM
#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
Sam I am (as well as Confused at times).

May 21st, 2020, 02:52 PM
#8
Thread Starter
PowerPoster
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.

May 21st, 2020, 02:55 PM
#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.

May 21st, 2020, 03:00 PM
#10
Thread Starter
PowerPoster
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 '""')

May 21st, 2020, 03:04 PM
#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

May 21st, 2020, 03:06 PM
#12
Thread Starter
PowerPoster
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

May 21st, 2020, 03:06 PM
#13
Re: how can i test a number if is valid?
Then .X will always be a number. It cannot be anything else

May 21st, 2020, 03:15 PM
#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.

May 21st, 2020, 03:21 PM
#15
Thread Starter
PowerPoster
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

May 21st, 2020, 03:28 PM
#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

May 21st, 2020, 03:32 PM
#17
Thread Starter
PowerPoster
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

May 21st, 2020, 04:04 PM
#18
Re: [RESOLVED] how can i test a number if is valid?
VB6 functions have a buitin 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...

May 21st, 2020, 04:11 PM
#19
Thread Starter
PowerPoster
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

Forum Rules

Click Here to Expand Forum to Full Width
