Home All Groups Group Topic Archive Search About

Verify a person's name?

Author
5 Jul 2005 1:54 PM
Casey
Hello.  I am trying to get VB6 to ask the user for his/her name.  I have created a public variable called MyName.  I want to generate an inputBox that can get the user's name.  If the cancel button is pressed, I want the user to be redirected to the intro form, or to the inbutBox so they can re-enter their name.  If the Ok button is clicked, I want to show the user an msgBox verifying their name is correct.  If ok is clicked, then show the next form, if the cancel button is clicked, then I want to put the user back into the InputBox, or the intro.
This is the code I have so far.  What happens is the when the cancel button is clicked, then either the user is moved on to Q1, or the program closes.

MyName = InputBox("What is your first and last name?", "Your Name")
If vbOK Then
MyName = MsgBox("Is your name " & MyName & "? If it is, tap Enter. If it is not, tap Escape", vbOKCancel + vbQuestion, "Your Name")
ElseIf vbCancel Then
FrmIntro.Show
If vbOK Then
FrmQ1.Show
Else: FrmIntro.Show
End If
End If
End If
Thanks for any help!

--



Casey

Author
5 Jul 2005 2:13 PM
Ken Halter
The return for an InputBox is a string. You're test  for vbOk will always
fall through to the msgbox line.

You'll have to change...

If vbOK Then

to

If Len(MyName) = 0 Then

.....same goes for the vbCancel test. You're not comparing it to anything but
itself.


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..

"Casey" <csm***@cfl.rr.com> wrote in message
news:%23MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl...
Hello.  I am trying to get VB6 to ask the user for his/her name.  I have
created a public variable called MyName.  I want to generate an inputBox
that can get the user's name.  If the cancel button is pressed, I want the
user to be redirected to the intro form, or to the inbutBox so they can
re-enter their name.  If the Ok button is clicked, I want to show the user
an msgBox verifying their name is correct.  If ok is clicked, then show the
next form, if the cancel button is clicked, then I want to put the user back
into the InputBox, or the intro.
This is the code I have so far.  What happens is the when the cancel button
is clicked, then either the user is moved on to Q1, or the program closes.

MyName = InputBox("What is your first and last name?", "Your Name")
If vbOK Then
MyName = MsgBox("Is your name " & MyName & "? If it is, tap Enter. If it is
not, tap Escape", vbOKCancel + vbQuestion, "Your Name")
ElseIf vbCancel Then
FrmIntro.Show
If vbOK Then
FrmQ1.Show
Else: FrmIntro.Show
End If
End If
End If
Thanks for any help!

--



Casey
Author
5 Jul 2005 2:27 PM
Casey
Thanks Ken.  I think I understand.  I don't just want to compare if the
InputBox is empty, I want to let the user see if any typos exist, and click
the cancel buttons to go back.  Sorry if I'm not understanding you.
--


Casey


"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:O2jbFvWgFHA.1444@TK2MSFTNGP10.phx.gbl...
The return for an InputBox is a string. You're test  for vbOk will always
fall through to the msgbox line.

You'll have to change...

If vbOK Then

to

If Len(MyName) = 0 Then

.....same goes for the vbCancel test. You're not comparing it to anything but
itself.


--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..

"Casey" <csm***@cfl.rr.com> wrote in message
news:%23MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl...
Hello.  I am trying to get VB6 to ask the user for his/her name.  I have
created a public variable called MyName.  I want to generate an inputBox
that can get the user's name.  If the cancel button is pressed, I want the
user to be redirected to the intro form, or to the inbutBox so they can
re-enter their name.  If the Ok button is clicked, I want to show the user
an msgBox verifying their name is correct.  If ok is clicked, then show the
next form, if the cancel button is clicked, then I want to put the user back
into the InputBox, or the intro.
This is the code I have so far.  What happens is the when the cancel button
is clicked, then either the user is moved on to Q1, or the program closes.

MyName = InputBox("What is your first and last name?", "Your Name")
If vbOK Then
MyName = MsgBox("Is your name " & MyName & "? If it is, tap Enter. If it is
not, tap Escape", vbOKCancel + vbQuestion, "Your Name")
ElseIf vbCancel Then
FrmIntro.Show
If vbOK Then
FrmQ1.Show
Else: FrmIntro.Show
End If
End If
End If
Thanks for any help!

--



Casey
Author
5 Jul 2005 2:39 PM
Ken Halter
"Casey" <csm***@cfl.rr.com> wrote in message
news:%23yoh92WgFHA.572@TK2MSFTNGP15.phx.gbl...
> Thanks Ken.  I think I understand.  I don't just want to compare if the
> InputBox is empty, I want to let the user see if any typos exist, and
> click
> the cancel buttons to go back.  Sorry if I'm not understanding you.
> --
>
>
> Casey

The thing is... an InputBox only returns strings. That means, your "If vbOK
Then" and "ElseIf vbCancel Then" won't mean a thing when it comes to an
InputBox. The MsgBox function returns vbOk, etc. InputBox doesn't.

Not only that but.... your tests aren't really testing anything.

You're saying....

If vbOK Then

which is exactly the same as....

Const vbOk = 1
If vbOk Then

because vbOk will *always* = 1. The line following the If statement will
always run (the value of vbOk will never change).

To make that test mean anything at all, even for a msgbox, you'd have to say
something like....

If SomeResultFromAFunction = vbOk Then

The line above is comparing 2 numbers. The return from a function and the
vbOk constant.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
Author
5 Jul 2005 8:16 PM
Casey
Ok, I understand, thanks for your explanation.

--


Casey


"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:OpdcN9WgFHA.2632@TK2MSFTNGP09.phx.gbl...
"Casey" <csm***@cfl.rr.com> wrote in message
news:%23yoh92WgFHA.572@TK2MSFTNGP15.phx.gbl...
> Thanks Ken.  I think I understand.  I don't just want to compare if the
> InputBox is empty, I want to let the user see if any typos exist, and
> click
> the cancel buttons to go back.  Sorry if I'm not understanding you.
> --
>
>
> Casey

The thing is... an InputBox only returns strings. That means, your "If vbOK
Then" and "ElseIf vbCancel Then" won't mean a thing when it comes to an
InputBox. The MsgBox function returns vbOk, etc. InputBox doesn't.

Not only that but.... your tests aren't really testing anything.

You're saying....

If vbOK Then

which is exactly the same as....

Const vbOk = 1
If vbOk Then

because vbOk will *always* = 1. The line following the If statement will
always run (the value of vbOk will never change).

To make that test mean anything at all, even for a msgbox, you'd have to say
something like....

If SomeResultFromAFunction = vbOk Then

The line above is comparing 2 numbers. The return from a function and the
vbOk constant.

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..
Author
5 Jul 2005 2:54 PM
Mike D Sutton
> Thanks Ken.  I think I understand.  I don't just want to compare if the
> InputBox is empty, I want to let the user see if any typos exist, and click
> the cancel buttons to go back.  Sorry if I'm not understanding you.

If you want to test for when the user presses the cancel button on an input box, then check the return string pointer:

'***
Dim RetStr As String

RetStr = InputBox("Hit cancel")
If (StrPtr(RetStr) = 0) Then Call MsgBox("User hit cancel")
'***

So in your case, you'd want something like:

'***
MyName = InputBox("What is your first and last name?", "Your Name")
If (StrPtr(MyName) <> 0) Then
    If (MsgBox( ... ) = vbOk) Then
        ' Good to go
    ... etc ...
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Jul 2005 8:17 PM
Casey
Thanks Mike.  That does help.

--


Casey


"Mike D Sutton" <ED***@mvps.org> wrote in message
news:OI6w2FXgFHA.3132@TK2MSFTNGP10.phx.gbl...
> Thanks Ken.  I think I understand.  I don't just want to compare if the
> InputBox is empty, I want to let the user see if any typos exist, and
> click
> the cancel buttons to go back.  Sorry if I'm not understanding you.

If you want to test for when the user presses the cancel button on an input
box, then check the return string pointer:

'***
Dim RetStr As String

RetStr = InputBox("Hit cancel")
If (StrPtr(RetStr) = 0) Then Call MsgBox("User hit cancel")
'***

So in your case, you'd want something like:

'***
MyName = InputBox("What is your first and last name?", "Your Name")
If (StrPtr(MyName) <> 0) Then
    If (MsgBox( ... ) = vbOk) Then
        ' Good to go
    ... etc ...
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Jul 2005 3:06 PM
Tony Proctor
What about trying to deduce their name without asking for it Casey?

1) The GetUserNameEx API supposedly takes a NameDisplay parameter to return
the "friendly name" of the current user, e.g. "Tony Proctor":

Private Declare Function GetUserNameEx Lib "secur32" Alias "GetUserNameExA"
( _
    ByVal format As Long, ByVal Name As String, ByRef namlen As Long) As
Long

Private Const NameDisplay As Long = 3

Function sGetUser(lFormat As Long) As String
Dim lNamlen As Long
Dim lRet As Long

    lNamlen = 255
    sGetUser = String$ (lNamlen, 0)
    lRet = GetUserNameEx (lFormat, sGetUser, lNamlen)
    Debug.Print "Ret=" & CStr(lRet) & ", LastError=" & Hex(Err.LastDllError)
&
        ", Len=" & CStr(lNamlen)
    If lRet = 0 Then
        sGetUser = "????"
    Else
        sGetUser = Left (sGetUser, lNamlen)
    End If
End Function

Sub Main()
    Debug.Print sGetUser(NameSamCompatible)
    Debug.Print sGetUser(NameDisplay)
End Sub

However, this isn't in NT4, and I never managed to find a W2K box that
provided this name information. Every machine I tried just returned a blank
string for the DisplayName.

2) Use Active Directory. If you have the SAM-format account name of the user
(e.g. similar to "MyDomain\tony" from GetUserName), then something like:

Dim sNTLogin As String
Dim oUser As IADsUser

    sNTLogin = "MyDomain\tony"        'SAM-format account name
    Set oUser = GetObject("WinNT://" & Replace(sNTLogin, "\", "/") &
        ",user")
    Debug.Print oUser.FullName


        Tony Proctor


"Casey" <csm***@cfl.rr.com> wrote in message
news:#MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl...
Hello.  I am trying to get VB6 to ask the user for his/her name.  I have
created a public variable called MyName.  I want to generate an inputBox
that can get the user's name.  If the cancel button is pressed, I want the
user to be redirected to the intro form, or to the inbutBox so they can
re-enter their name.  If the Ok button is clicked, I want to show the user
an msgBox verifying their name is correct.  If ok is clicked, then show the
next form, if the cancel button is clicked, then I want to put the user back
into the InputBox, or the intro.
This is the code I have so far.  What happens is the when the cancel button
is clicked, then either the user is moved on to Q1, or the program closes.

MyName = InputBox("What is your first and last name?", "Your Name")
If vbOK Then
MyName = MsgBox("Is your name " & MyName & "? If it is, tap Enter. If it is
not, tap Escape", vbOKCancel + vbQuestion, "Your Name")
ElseIf vbCancel Then
FrmIntro.Show
If vbOK Then
FrmQ1.Show
Else: FrmIntro.Show
End If
End If
End If
Thanks for any help!

--



Casey
Author
5 Jul 2005 8:19 PM
Casey
Wow, I can use that.  I do need to ask the user for their now, but I can use
this later on.
Thanks very much.

--


Casey


"Tony Proctor" <tony_proctor@aimtechnology_NoMoreSPAM_.com> wrote in message
news:eZpUQMXgFHA.3616@TK2MSFTNGP12.phx.gbl...
What about trying to deduce their name without asking for it Casey?

1) The GetUserNameEx API supposedly takes a NameDisplay parameter to return
the "friendly name" of the current user, e.g. "Tony Proctor":

Private Declare Function GetUserNameEx Lib "secur32" Alias "GetUserNameExA"
( _
    ByVal format As Long, ByVal Name As String, ByRef namlen As Long) As
Long

Private Const NameDisplay As Long = 3

Function sGetUser(lFormat As Long) As String
Dim lNamlen As Long
Dim lRet As Long

    lNamlen = 255
    sGetUser = String$ (lNamlen, 0)
    lRet = GetUserNameEx (lFormat, sGetUser, lNamlen)
    Debug.Print "Ret=" & CStr(lRet) & ", LastError=" & Hex(Err.LastDllError)
&
        ", Len=" & CStr(lNamlen)
    If lRet = 0 Then
        sGetUser = "????"
    Else
        sGetUser = Left (sGetUser, lNamlen)
    End If
End Function

Sub Main()
    Debug.Print sGetUser(NameSamCompatible)
    Debug.Print sGetUser(NameDisplay)
End Sub

However, this isn't in NT4, and I never managed to find a W2K box that
provided this name information. Every machine I tried just returned a blank
string for the DisplayName.

2) Use Active Directory. If you have the SAM-format account name of the user
(e.g. similar to "MyDomain\tony" from GetUserName), then something like:

Dim sNTLogin As String
Dim oUser As IADsUser

    sNTLogin = "MyDomain\tony"        'SAM-format account name
    Set oUser = GetObject("WinNT://" & Replace(sNTLogin, "\", "/") &
        ",user")
    Debug.Print oUser.FullName


        Tony Proctor


"Casey" <csm***@cfl.rr.com> wrote in message
news:#MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl...
Hello.  I am trying to get VB6 to ask the user for his/her name.  I have
created a public variable called MyName.  I want to generate an inputBox
that can get the user's name.  If the cancel button is pressed, I want the
user to be redirected to the intro form, or to the inbutBox so they can
re-enter their name.  If the Ok button is clicked, I want to show the user
an msgBox verifying their name is correct.  If ok is clicked, then show the
next form, if the cancel button is clicked, then I want to put the user back
into the InputBox, or the intro.
This is the code I have so far.  What happens is the when the cancel button
is clicked, then either the user is moved on to Q1, or the program closes.

MyName = InputBox("What is your first and last name?", "Your Name")
If vbOK Then
MyName = MsgBox("Is your name " & MyName & "? If it is, tap Enter. If it is
not, tap Escape", vbOKCancel + vbQuestion, "Your Name")
ElseIf vbCancel Then
FrmIntro.Show
If vbOK Then
FrmQ1.Show
Else: FrmIntro.Show
End If
End If
End If
Thanks for any help!

--



Casey
Author
6 Jul 2005 12:57 AM
Michael Cole
Casey wrote:
> Hello.  I am trying to get VB6 to ask the user for his/her name.  I
> have created a public variable called MyName.

[SNIP]

> MyName = InputBox("What is your first and last name?", "Your Name")

Just a minor point, and probably not relevent to you but...

Be aware that the First and Last Name format for personal names is not
universal.  Obviously, in most western countries, it is, but even then,
there can be confusion.  Some eastern Europeans will consider their Family
name as their first name and their given name as their last name, ie, "Smith
Fred", rather than "Fred Smith" as per Anglo-Saxon rules.

And many cultures may not even use last names...

--

Regards,

Michael Cole
Author
6 Jul 2005 1:36 AM
Casey
Good point, I hadn't thought of that.  Do you think full name would be more
appropriate?

--


Casey


"Michael Cole" <no***@hansen.com> wrote in message
news:ePfPpWcgFHA.3448@TK2MSFTNGP12.phx.gbl...
Casey wrote:
> Hello.  I am trying to get VB6 to ask the user for his/her name.  I
> have created a public variable called MyName.

[SNIP]

> MyName = InputBox("What is your first and last name?", "Your Name")

Just a minor point, and probably not relevent to you but...

Be aware that the First and Last Name format for personal names is not
universal.  Obviously, in most western countries, it is, but even then,
there can be confusion.  Some eastern Europeans will consider their Family
name as their first name and their given name as their last name, ie, "Smith
Fred", rather than "Fred Smith" as per Anglo-Saxon rules.

And many cultures may not even use last names...

--

Regards,

Michael Cole
Author
6 Jul 2005 1:56 AM
Michael Cole
Show quote Hide quote
> "Michael Cole" <no***@hansen.com> wrote in message
> news:ePfPpWcgFHA.3448@TK2MSFTNGP12.phx.gbl...
> Casey wrote:
>> Hello.  I am trying to get VB6 to ask the user for his/her name.  I
>> have created a public variable called MyName.
>
> [SNIP]
>
>> MyName = InputBox("What is your first and last name?", "Your Name")
>
> Just a minor point, and probably not relevent to you but...
>
> Be aware that the First and Last Name format for personal names is not
> universal.  Obviously, in most western countries, it is, but even
> then, there can be confusion.  Some eastern Europeans will consider
> their Family name as their first name and their given name as their
> last name, ie, "Smith Fred", rather than "Fred Smith" as per
> Anglo-Saxon rules.
>
> And many cultures may not even use last names...

Casey wrote:
> Good point, I hadn't thought of that.  Do you think full name would
> be more appropriate?

It would depend on what you are going to do with the name.  If it is just
for recording purposes, then simply asking for their "Name" would be
appropriate, and accept whatever they type.  If you need to parse the
entered name, for addressing purposes etc, then you would have to either
state the name order, or provide seperate entries for each portion of their
name.  Note that internationally, there are 36 accepted Personal Name
Formats.

I think "Full Name" would be more appropriate if you are not parsing what is
entered.


--
Regards,

Michael Cole