<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Visual Basic .NET</title><link>http://forums.asp.net/36.aspx</link><description>Discussions/Questions about the Visual Basic .NET language. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=14&amp;c=23" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Problem Calling Function A In Funtion A</title><link>http://forums.asp.net/thread/3275714.aspx</link><pubDate>Mon, 06 Jul 2009 00:28:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275714</guid><dc:creator>mmmisa83</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275714.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=36&amp;PostID=3275714</wfw:commentRss><description>&lt;p&gt;Ah, I think you are right. Your first reply suggests to change line 16 to 
&lt;br /&gt;
&lt;/p&gt;&lt;pre name="code" class="vb.net"&gt;Return RandomizeNo(totalLot) &lt;/pre&gt;&lt;p&gt;but what I did was changing line 19 with the suggested code. That&amp;#39;s why it caused infinite looping LOL. 
&lt;br /&gt;&lt;br /&gt;
Yes, both snippets below work.
&lt;br /&gt;&lt;/p&gt;
&lt;pre name="code" class="vb.net"&gt;If randomizeAgain = True Then
  Return RandomizeNo(totalLot)
End If

  Return intLot &lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre name="code" class="vb.net"&gt;If randomizeAgain = True Then
  Return RandomizeNo(totalLot)
Else
  Return intLot
End If&lt;/pre&gt;&lt;p&gt;Actually I modified/simplified the function a bit to make it easier for readers to see the function flow. I just wanted to mention the function calling in the function assuming readers would ignore the For Looping part.
&lt;br /&gt;&lt;br /&gt;
Well it works now! Just by adding the word &amp;#39;Return&amp;#39; in line 16 ;)
&lt;br /&gt;&lt;br /&gt;
Thanks a lot.
&lt;/p&gt;</description></item><item><title>Re: Problem Calling Function A In Funtion A</title><link>http://forums.asp.net/thread/3275361.aspx</link><pubDate>Sun, 05 Jul 2009 12:44:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275361</guid><dc:creator>anders__f</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275361.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=36&amp;PostID=3275361</wfw:commentRss><description>&lt;p&gt;Well, it would only call the function again if randomizeAgain = True, and randomizeAgain is only set to true if intLot = 5. Isn&amp;#39;t that what you want?&lt;/p&gt;&lt;p&gt;These code snippets are equivalent:&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;pre name="code" class="vb.net"&gt;If randomizeAgain = True Then
    Return RandomizeNo(totalLot)
End If

Return intLot&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt; &lt;pre name="code" class="vb.net"&gt;If randomizeAgain = True Then
    Return RandomizeNo(totalLot)
Else
    Return intLot
End If&lt;/pre&gt;&lt;p&gt;&lt;br /&gt; Just another thing, why do you use a for loop? The looping variable k is never used. And this in turn means that the parameter totalLot is in fact never used. What exactly do you want this function to return for different parameter values?&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Problem Calling Function A In Funtion A</title><link>http://forums.asp.net/thread/3275356.aspx</link><pubDate>Sun, 05 Jul 2009 12:33:47 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275356</guid><dc:creator>mmmisa83</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275356.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=36&amp;PostID=3275356</wfw:commentRss><description>&lt;p&gt;Thanks anders__f for replying. But I dont think that would solve the problem, it instead will cause infinite looping because &amp;quot;Return RandomizeNo(totalLot)&amp;quot; keeps calling the function.
&lt;br /&gt;&lt;br /&gt;
This function returns intLot, if the value of intLot is not 5. Otherwise the function will be called.
&lt;br /&gt;&lt;br /&gt;
Any other suggestion? Thanks again.
&lt;/p&gt;</description></item><item><title>Re: Problem Calling Function A In Funtion A</title><link>http://forums.asp.net/thread/3275313.aspx</link><pubDate>Sun, 05 Jul 2009 11:35:05 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275313</guid><dc:creator>anders__f</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275313.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=36&amp;PostID=3275313</wfw:commentRss><description>&lt;p&gt;Look at the exit point for this function, the return statement at line 19. It will always return intLot, no matter if line 16 was executed or not.&lt;/p&gt;&lt;p&gt;The thing is that when you call the function again in line 16, you will get a new variable scope, and the function will not use the same variable/values as in the calling scope.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I have not tried your code, but probably it will be enough to change line 16 to&lt;/p&gt;&lt;p&gt;&lt;pre name="code" class="vb.net"&gt;Return RandomizeNo(totalLot)&lt;/pre&gt;&lt;br /&gt; &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Problem Calling Function A In Funtion A</title><link>http://forums.asp.net/thread/3275202.aspx</link><pubDate>Sun, 05 Jul 2009 08:13:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3275202</guid><dc:creator>mmmisa83</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3275202.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=36&amp;PostID=3275202</wfw:commentRss><description>&lt;p&gt;Hi,
&lt;br /&gt;&lt;br /&gt;
I have this simple function (below) that randomizes number between 1 to 10.
&lt;br /&gt;&lt;br /&gt;
This function works well, except when Random() returns 5,
which means intLot=5, randomizeAgain = true, and then the same function RandomizeNo will be called to randomize again. (refer the code below)
&lt;br /&gt;&lt;br /&gt;
Even the new value of intLot equals other than 5 next time, say 4, the funtion returns 0.
&lt;br /&gt;&lt;br /&gt;
I have no idea why.

&lt;/p&gt;&lt;pre name="code" class="vb.net"&gt;Function RandomizeNo(ByVal totalLot As Integer) As Integer
        Dim intLot As Integer

        randomizeAgain = False
        
	intLot = New Random().Next(1, 10)

	For k = 1 To totalLot - 1
	  If intLot = 5 Then
	    randomizeAgain = True
	    Exit For
	  End If
	Next

        If randomizeAgain = True Then
            RandomizeNo(totalLot)
        End If

        Return intLot
End Function&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;
Please help.
&lt;br /&gt;&lt;br /&gt;
Thanks in advance.&lt;/p&gt;</description></item></channel></rss>