dcsimg
Results 1 to 19 of 19

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

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    Resolved [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?)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    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).

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,208

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

    Quote from Charles Kettering:

    A problem well stated is a problem half-solved

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,152

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

    How about the IsNumeric() function?

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    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).

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,993

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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 '""')
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,993

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  13. #13
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,993

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

    Then .X will always be a number. It cannot be anything else
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  14. #14
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,993

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  15. #15

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,993

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  18. #18
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,208

    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. #19

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,330

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

    thank you Eduardo i never knew about it.. thank you
    VB6 2D Sprite control

    To live is difficult, but we do it.

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


Click Here to Expand Forum to Full Width