Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

What to do when you're bored.

I had nothing to do so I just created this little thing, copy & paste the code in your console application and then run it.

Code
Module ConsoleModule

    Sub Main()
      Console.Write("Integer to reach: ")
      Dim iToReach As Integer = CInt(Console.ReadLine)
      Console.Write("Min range: ")
      Dim minRange As Integer = CInt(Console.ReadLine)
      Console.Write("Max range: ")
      Dim maxRange As Integer = CInt(Console.ReadLine)
      startReach(iToReach, minRange, maxRange)
    End Sub
    Sub startReach(ByVal iTR As Integer, ByVal minR As Integer, ByVal maxR As Integer)
      Dim amountOfTries As Integer = 0
      Dim iReached As Integer
      Do Until iReached = iTR
      Dim iRnd As New Random
      iReached = iRnd.Next(minR, maxR)
      amountOfTries += 1
      Console.WriteLine(amountOfTries)
      If iReached = iTR Then
      Console.WriteLine("Integer has been reached!")
      Console.WriteLine("Amount of tries: " & amountOfTries)
      End If
      Loop
      Main()
    End Sub
End Module

So what you do is specify an integer, then specify the minimum and maximum range and it will generate a random integer between that range until your specific integer is generated and tell you how many times it tried to reach that integer.

Tell me if I need to improve something.
Please use Option Strict you could really use it...
(Feb 14, 2015 06:27 PM)taktaktak Wrote:  Please use Option Strict you could really use it...

What do you mean with that? Only mistake I see is that I didn't use CINT.
But Option Strict was off by mistake.
(Feb 14, 2015 06:44 PM)LijpeMD Wrote:  What do you mean with that? Only mistake I see is that I didn't use CINT.
But Option Strict was off by mistake.

Well now that you've added it, it's better but it would just crash allot as the console would accept anything, even now your not doing anything to prevent someone typing in actual non-integer characters.
(Feb 14, 2015 07:04 PM)taktaktak Wrote:  Well now that you've added it, it's better but it would just crash allot as the console would accept anything, even now your not doing anything to prevent someone typing in actual non-integer characters.

Why are you trying to make me look stupid? Why would someone put in non-integer characters if they want to make the program work properly? I gave out the source so you can fix that yourself by simply adding a Try Catch statement, or disallow non-integer characters.
(Feb 14, 2015 07:14 PM)LijpeMD Wrote:  Why are you trying to make me look stupid? Why would someone put in non-integer characters if they want to make the program work properly? I gave out the source so you can fix that yourself by simply adding a Try Catch statement, or disallow non-integer characters.

Yes, and it's just good practice. Because considering you weren't using Cint on something that clearly needed it I question your ability and how well you practice good coding habits.
Fun if you are bored! Thanks! 😁


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by itai19901Jun 16, 2012 09:41 PM 10 244 Jun 16, 2012 09:41 PM
Last Post: itai19901
[.NET] by Joler1302Mar 24, 2010 09:12 PM 21 290 Mar 24, 2010 09:12 PM
Last Post: Kōtei