×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

DropListBox returns number instead of string?

DropListBox returns number instead of string?

DropListBox returns number instead of string?

(OP)
Hi. I am at a loss. I have asked this question once before but I feel as though I was not clear. In the following script I have an example of a droplistbox.

CODE

DropListBox  120, 100, 75, 32, "Cris"+chr$(9)+"Micheal"+chr$(9)+"Krista"+chr$(9)+"Kevin"+chr$(9)+"Jennifer", .dbxOption

If the user selects Micheal, The following line of code returns the number 1.

CODE

Name=dMain.dbxOption
MsgBox Name

How do I get Name to show up as Micheal instead of 1?

No, I am no programmer, but the answers to such questions will allow me to automate a lot of my repetitive navigation and input. There are a great deal of different functionalities that could be made simpler and error free from this; I am already grateful for all the information I have learned in this forum and to all of those who have offered their input and assistance thus far, and this solution would go a long way to improving mine and others performance at work. I created and shared quickpads at work 4 or 5 years ago, but am now learning there is a lot more than sendkeys. Again, your assistance will be much appreciated.

Ted,

RE: DropListBox returns number instead of string?

Ted, the best way would be to use Select Case and code that accordingly.

RE: DropListBox returns number instead of string?

ted, here's a variation without Select Case

CODE

Sub Main

    Dim ord(10) as string

    ord(0)  = "0"
    ord(1)  = "Chris"
    ord(2)  = "Michael"
    ord(3)  = "Krista"
    ord(4)  = "Kevin"
    ord(5)  = "Jennifer"
    ord(6)  = "6"
    ord(7)  = "7"
    ord(8)  = "8"
    ord(9)  = "9"
    ord(10) = "10"
    

    
    Begin Dialog dlgOptions 285, 19, 184, 190, "Selection Dialog Box"
        OkButton  130, 6, 50, 14, .btnOK
        CancelButton  130, 23, 50, 14, .btnCancel
        

        Text           5, 85, 70, 10, "Employee"
        DropComboBox  55, 85, 73, 40, ord(), .CB1
 
    End Dialog


    Dim dlgVar as dlgOptions
    
    Dialog dlgVar
    
    msgbox dlgvar.CB1

  
End Sub

RE: DropListBox returns number instead of string?

(OP)
I feel like a blind man asking directions, and being told, "That way!". So the blind man asks, "Can you guide me?"

Is my question unclear? the Case statement is in the function and where the selection numerical value is given a related string. Selection 1, micheal. If I wanted to call the funtion and get the string "micheal" from main() instead of 1, what should I write? Please a line of code I can try, because I have tried so many different ways, but to no avail. My inexperience there becomes apparent.

RE: DropListBox returns number instead of string?



Did your try vzachin's code?  In your case

CODE

    Name = dlgvar.CB1
rather than MsgBox.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: DropListBox returns number instead of string?

i used the House sample

CODE

Declare Function DisplayChoice(iEmployee%) As String

Sub Main

Dim iEmployee%
Dim iDone%
Dim szEmp as String


        Begin Dialog dlgEmployee 0, 1, 185, 100, "Employee List"
           
           ButtonGroup .ButtonPressed
           OkButton         125, 10, 50, 14
           CancelButton     125, 30, 50, 14
           PushButton       125, 50, 50, 14, "&Reset", .btnReset
           
           Text         15, 15, 77, 8, "Employee:"
           DropListBox  15, 30, 81, 130, "Cris"+chr$(9)+"Micheal"+chr$(9)+"Krista"+chr$(9)+"Kevin"+chr$(9)+"Jennifer", .dlbEmployee
           
        End Dialog
        

    iDone = FALSE

    While (iDone = FALSE)    
        
        Dim dMain as dlgEmployee

        nRet = Dialog(dMain)
        
        Select Case nRet
            Case -1                       ' -1 is returned if the user chose OK
                iDone = TRUE

                iEmployee = dMain.dlbEmployee

                szEmp = DisplayChoice(iEmployee)
                msgbox (szEmp)
                
            Case 0                        ' 0 is returned if the user chose Cancel
                iDone = TRUE
                
            Case 1                        ' 1 is returned if the user chose Reset

                dMain.dlbEmployee = 0

            Case Else
                msgbox "Some undefined button pressed " + str(dMain.ButtonPressed)
                
        End Select
    Wend

End Sub


'--------------------------------------------------------------------------------

Function DisplayChoice(iEmployee%) As String
Dim szEmployee$
Dim szResult$


    Select Case iEmployee
    Case 0
        szEmployee = "Cris"
    Case 1
        szEmployee = "Michael"
    Case 2
        szEmployee = "Krista"
    Case 3
        szEmployee = "Kevin"
    Case 4
        szEmployee = "Jennifer"

    End Select

    
    szResult = szEmployee
    DisplayChoice = szResult
    
End Function

RE: DropListBox returns number instead of string?

(OP)
excellent!

RE: DropListBox returns number instead of string?

(OP)
Hi Skip and vzachin,

Vzachin, when you put the first code up I was actually typing my message. I must have gotten distracted by my 2 week old daughter before posting my plea for clarification. In that time the post from you was up, but not yet visible to me. For that, I want to apologize to you. You guys are a great help! You deserve 100 purple stars each! I get frustrated with myself sometimes if I feel as though I am not clear with my request. In retrospect though, I am getting connections happening in my head, when I feel I'm learning something. I am really looking forward to learning how to use vba for Excel, but in our work environment not everyone uses Excel, or even has it open unless needed. That is why my focus is mainly on EB. With the information I have learned in this short time, I have revisited the EB help files, and a lot of the things that were not clear before, are becoming much clearer; the explations are easier to read and understand.

Again, I thank you both.

Ted,

RE: DropListBox returns number instead of string?




Ted,

Keep pressing on!  Tek-Tips is a great place to get questions answered and also view solutions that other have found helpful.

Post back any time.  With an attitude like your, you will be posting solutions at some point, with maybe a star or two to boot! winky smile

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

RE: DropListBox returns number instead of string?

Ted, as Skip says "Keep pressing on!"...i've been learning here for the past few years from Skip and many others who share their knowledge.  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close