+ Reply to Thread
Results 1 to 4 of 4

Function returning null value instead of string value

  1. #1
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39

    Question Function returning null value instead of string value

    Hi,

    I have a combo box with some values in it. Now, I want to make a function wherein I pass the value of the combo box as a string parameter and return a specific string value corresponding to the string parameter passed. I am able to pass the parametric value, but the value returned is "blank" or "null" instead of the string value that the function should be returning. Why is this happening? Below is the code that I am using for the function and how I am passing the value into it. Please help.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Peace,

    Shivboy
    Last edited by shivboy; 07-07-2006 at 01:18 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Shivboy,

    Try using a Select Case statement in place of the nested If ElseIf statements...

    Please Login or Register  to view this content.
    This makes your code easier to read and troubleshoot. Nested If statements can become a real headache quickly. Not sure if you renamed your ComboBox to Combo1, but if you didn't you need to change it in your code to ComboBox1.

    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 07-07-2006 at 01:33 AM.

  3. #3
    Registered User
    Join Date
    06-06-2006
    MS-Off Ver
    2010, 365
    Posts
    39
    Thanks Leith, it worked. Thanks a lot buddy.

    Quote Originally Posted by Leith Ross
    Hello Shivboy,

    Try using a Select Case statement in place of the nested If ElseIf statements...

    Please Login or Register  to view this content.
    This makes your code easier to read and troubleshoot. Nested If statements can become a real headache quickly. Not sure if you renamed your ComboBox to Combo1, but if you didn't you need to change it in your code to ComboBox1.

    Sincerely,
    Leith Ross

  4. #4
    Dana DeLouis
    Guest

    Re: Function returning null value instead of string value

    Hi. Here is the first and last line of your code...

    > Function convertDiv(oDiv As String) As String
    > End Sub


    The last line should be "End Function"

    Maybe another option?

    Function ConvertDiv(oDiv As String) As String
    If Len(oDiv) > 1 Then Exit Function
    Select Case oDiv
    Case "A" To "G"
    ConvertDiv = Chr(Asc(oDiv) - 16)
    End Select
    End Function

    --
    HTH. :>)
    Dana DeLouis
    Windows XP, Office 2003


    "shivboy" <shivboy.2ak7mz_1152249301.9523@excelforum-nospam.com> wrote in
    message news:shivboy.2ak7mz_1152249301.9523@excelforum-nospam.com...
    >
    > Hi,
    >
    > I have a combo box with some values in it. Now, I want to make a
    > function wherein I pass the value of the combo box as a string
    > parameter and return a specific string value corresponding to the
    > string parameter passed. I am able to pass the parametric value, but
    > the value returned is "blank" or "null" instead of the string value
    > that the function should be returning. Why is this happening? Below is
    > the code that I am using for the function and how I am passing the
    > value into it. Please help.
    >
    >
    > Code:
    > --------------------
    >
    > Function convertDiv(oDiv As String) As String
    > Dim wDiv, oDivID As String
    > wDiv = oDiv
    > If wDiv = "A" Then
    > oDivID = "1"
    > ElseIf wDiv = "B" Then
    > oDivID = "2"
    > ElseIf wDiv = "C" Then
    > oDivID = "3"
    > ElseIf wDiv = "D" Then
    > oDivID = "4"
    > ElseIf wDiv = "E" Then
    > oDivID = "5"
    > ElseIf wDiv = "F" Then
    > oDivID = "6"
    > ElseIf wDiv = "G" Then
    > oDivID = "7"
    > End If
    > convertDiv = oDivID
    > End Sub
    >
    > --------------------
    >
    >
    >
    > Code:
    > --------------------
    >
    > Sub init()
    > Dim a As String
    > a = convertDiv(Trim(combo1.Value))
    > lblType.Caption = a
    > End Sub
    >
    > --------------------
    >
    >
    > Peace,
    >
    > Shivboy
    >
    >
    > --
    > shivboy
    > ------------------------------------------------------------------------
    > shivboy's Profile:
    > http://www.excelforum.com/member.php...o&userid=35137
    > View this thread: http://www.excelforum.com/showthread...hreadid=559197
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1