none
RANDOMIZE Rnd functie 123 RRS feed

  • Question

  •    Public Class frmRaadspelletje
        'Author
        Dim intWillekeurig As Integer


        Private Sub btnNieuwspel_Click(sender As Object, e As EventArgs) Handles btnNieuwspel.Click
            'wissen van de teksvakken
            txtGetal.Text = ""
            lblFeedback.Text = ""

            'bepalen van nieuwe willekeurig getal tussen 1 en 100
            intWillekeurig = Int((100 - 1 + 1) * Rnd() + 1)

        End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Randomize()
            intWillekeurig = Int((100 - 1 + 1) * Rnd() + 1)

        End Sub

     Dim intGetal As Integer 

     intGetal =cint(txtGetal.text

         'berekening
            If intGetal = intWillekeurig Then
                lblFeedback.Text = "proficiat! je hebt het getal geraden"
            Else
                If intGetal > intWillekeurig Then
                    lblFeedback.Text = "Raad lager"
                Else
                    lblFeedback.Text = "Raad hoger"
                End If
            End If



    Sunday, December 17, 2017 4:03 PM

All replies

  • Hi Creanathan,

    Thanks for posting here.

    This forum is about the MSBuild, as your issue is more related to the VB, we help you move it to correct forum for better support.

    If you have some MSBuild questions, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 18, 2017 6:30 AM
  • Creanathan

    The Randomize function is less used so there are few still knowing around it. 

    Take the Random class

    https://msdn.microsoft.com/en-us/library/2dx6wyd4(v=vs.110).aspx

    Be aware that they both seem to use a very old DOS 16 bit function and are not real endless random. 

    A sample is on the page

     


    Success
    Cor

    Monday, December 18, 2017 7:57 AM
  • Hi Creanathan,

    What problems do you encounter? Or what do you want to do?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, December 18, 2017 8:10 AM
    Moderator
  • Hi Creanathan,

    According to your code, I can not run, this code can not be compiled. Can you provide the code that I can compile or you can share more code here, please give error message that you encounter.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I can with a single addition which was probably caused by the fact that the use of the buttons in this forum is not as self-evident as you would expect. (Or at least a text behind it, there is room enough)

    Option Strict Off
    Public Class Form1
        Dim intWillekeurig As Integer
        Private Sub btnNieuwspel_Click(sender As Object, e As EventArgs) Handles btnNieuwspel.Click
            'wissen van de teksvakken
            txtGetal.Text = ""
            lblFeedBack.Text = ""
            'bepalen van nieuwe willekeurig getal tussen 1 en 100
            intWillekeurig = Int((100 - 1 + 1) * Rnd() + 1)
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Randomize()
            intWillekeurig = Int((100 - 1 + 1) * Rnd() + 1)
        End Sub
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Dim intGetal As Integer
            intGetal = CInt(txtGetal.Text)
            'berekening
            If intGetal = intWillekeurig Then
                lblFeedBack.Text = "proficiat! je hebt het getal geraden"
            Else
                If intGetal > intWillekeurig Then
                    lblFeedBack.Text = "Raad lager"
                Else
                    lblFeedBack.Text = "Raad hoger"
                End If
    
            End If
        End Sub
    End Class

    A pity that paid moderators cannot do this, while Karen does not even think about it and does it direct. 


    Success
    Cor



    Monday, December 18, 2017 9:51 AM