|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Verify a person's name?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 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 Hello. I am trying to get VB6 to ask the user for his/her name. I have news:%23MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl... 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 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 The return for an InputBox is a string. You're test for vbOk will alwaysnews:O2jbFvWgFHA.1444@TK2MSFTNGP10.phx.gbl... 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 Hello. I am trying to get VB6 to ask the user for his/her name. I havenews:%23MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl... 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 "Casey" <csm***@cfl.rr.com> wrote in message The thing is... an InputBox only returns strings. That means, your "If vbOK 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 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.. Ok, I understand, thanks for your explanation.
-- Casey "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message The thing is... an InputBox only returns strings. That means, your "If vbOKnews: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 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.. > Thanks Ken. I think I understand. I don't just want to compare if the If you want to test for when the user presses the cancel button on an input box, then check the return string pointer:> 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. '*** 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/ Thanks Mike. That does help.
-- Casey "Mike D Sutton" <ED***@mvps.org> wrote in message If you want to test for when the user presses the cancel button on an input 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. 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/ 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 Hello. I am trying to get VB6 to ask the user for his/her name. I havenews:#MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl... 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 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 What about trying to deduce their name without asking for it Casey?news:eZpUQMXgFHA.3616@TK2MSFTNGP12.phx.gbl... 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 Hello. I am trying to get VB6 to ask the user for his/her name. I havenews:#MNoOkWgFHA.2484@TK2MSFTNGP15.phx.gbl... 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 Casey wrote:
> Hello. I am trying to get VB6 to ask the user for his/her name. I [SNIP]> have created a public variable called MyName. > 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 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 [SNIP]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. > 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
Show quote
Hide quote
> "Michael Cole" <no***@hansen.com> wrote in message Casey wrote:> 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... > Good point, I hadn't thought of that. Do you think full name would It would depend on what you are going to do with the name. If it is just> be more appropriate? 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
Functional IDE DLL call compiles to non-functional DLL call
Problem comparing double values Programatically design a form Divide a path into a Drivename, Pathname, and Filename? How should I select a folder, create and select the folder? Testing for MAPI , again Default Property in VB6 Class SaveSetting question Return Security Events for Yesterday Help with WMI |
|||||||||||||||||||||||