Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropListBox returns number instead of string? 1

Status
Not open for further replies.

tedb13

Technical User
Jan 20, 2011
41
CA
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,
 
Ted, the best way would be to use Select Case and code that accordingly.
 
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
 
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.
 


Did your try vzachin's code? In your case
Code:
    Name = dlgvar.CB1
rather than MsgBox.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
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
 
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,
 



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! ;-)

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top