Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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.


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function returning null value instead of string value


Hello Shivboy

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

Code
-------------------

Function convertDiv(oDiv As String) As Strin
Dim wDiv, oDivID As Strin
wDiv = oDi
Select Case wDi
Case Is = "A"
oDivID = "1
Case Is = "B"
oDivID = "2
Case Is = "C"
oDivID = "3
Case Is = "D"
oDivID = "4
Case Is = "E"
oDivID = "5
Case Is = "F"
oDivID = "6
Case Is = "G"
oDivID = "7
End Selec
convertDiv = oDivI
End Functio

-------------------

This makes your code easier to read and troubleshoot. Nested I
statements can become a real headache quickly. Not sure if you rename
your ComboBox to Combo1, but if you didn't you need to change it i
your code to ComboBox1

Sincerely
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55919

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Function returning null value instead of string value


Thanks Leith, it worked. Thanks a lot buddy.

Leith Ross Wrote:
Hello Shivboy,

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


Code:
--------------------

Function convertDiv(oDiv As String) As String
Dim wDiv, oDivID As String
wDiv = oDiv
Select Case wDiv
Case Is = "A"
oDivID = "1"
Case Is = "B"
oDivID = "2"
Case Is = "C"
oDivID = "3"
Case Is = "D"
oDivID = "4"
Case Is = "E"
oDivID = "5"
Case Is = "F"
oDivID = "6"
Case Is = "G"
oDivID = "7"
End Select
convertDiv = oDivID
End Function

--------------------


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



--
shivboy
------------------------------------------------------------------------
shivboy's Profile: http://www.excelforum.com/member.php...o&userid=35137
View this thread: http://www.excelforum.com/showthread...hreadid=559197

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default 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" wrote in
message ...

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperion Essbase Excel Add-in - returning text ("0") for null valu bill_morgan Excel Discussion (Misc queries) 7 February 28th 12 05:10 AM
Returning date instead of 'not null' Skeeterj Excel Worksheet Functions 4 November 3rd 09 04:40 PM
How suppress chart points - cells with formulae returning null sarcastix Charts and Charting in Excel 2 October 20th 08 12:50 AM
Replace null string with blank cell gjcase Excel Discussion (Misc queries) 2 August 9th 05 02:13 PM
Returning a string from a function fergusor[_2_] Excel Programming 5 February 18th 04 12:40 PM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"