Adblock breaks this site

Random number

Discussion in 'Programming General' started by Michael3455, Feb 10, 2007.

  1. Michael3455

    Michael3455 Active Member

    Joined:
    Sep 11, 2005
    Posts:
    134
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    EDIT... One problem fixed, another pops up... Eeeek.

    Ok, well. The problem that I thought I had wasn't the problem that I had. I don't think. Because I was getting annoyed that I could never pick the number, I decided to look into it by placing a msgbox(randnum) after the if statements to see what the random number was each time. The results I got freaked me out.

    They changed every goddamn time! That's not a good thing. So, I'm gonna try to fix it up but I don't have a clue how to. I've got to figure out a way to get the random number to go into the variable randnum, but then stop changing.

    Also, if someone with a reasonably ammount of experience in programming and vb.net could comment on my code, tell me if I've done everything in the standard/best way. Also, is the if /ifelse statements the best way to do this?

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object_
    , ByVal e As System.EventArgs) Handles Button1.Click
            Dim answer As Integer
    
    
            Dim theRandomGen As New Random()
    
            Dim randnum = int (RND() * (1 - 100 + 1)) + 100
    
    
            answer = TextBox1.Text
    
            If answer = Randnum Then
                MsgBox("You got it right!")
    
            ElseIf answer > Randnum Then
                MsgBox("Too high!")
    
            ElseIf answer < Randnum Then
                MsgBox("Too low")
    
            End If
    
                Msgbox(randnum)
    
    
    
        End Sub
    
        Private Sub TextBox1_TextChanged(ByVal sender As System.Object_
    , ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    
        End Sub
    End Class
    
     
  2. slashshot007

    slashshot007 Active Member

    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    great for a first program. mine was a crappy webbrowser where i didn't understand anything.
     
  3. X Zero

    X Zero Forum Addict

    Joined:
    Jan 21, 2007
    Posts:
    577
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    Its good but theres no point in having the "to high / to low" thingy. The reason is that the numbers changes ever time u click button 1
     
  4. Michael3455

    Michael3455 Active Member

    Joined:
    Sep 11, 2005
    Posts:
    134
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    Hey, thanks to both of you! It's the first program that I've made without the aid of a tutorial, so yeah... I just don't think copying out of a book/website is coding. Ya know.

    So, i'll try you one. I just need it to be a whole number, not one with a decimal part to it. Hopefully that works.

    It's just confusing me, as I always thought that an Integer was a hole number, positive or negative. And that you needed to use floating point integers to get deciamls and all that gunky stuff.

    Anyway, again, thank you very much for responding.

    Oh Golly, the post count went away again? I really should start paying more attention. I seem to lurk more then post here, anyway.. But still, I had a lovely look number of 300 something. Ahh well.
     
  5. cooladrrang

    cooladrrang Active Member

    Joined:
    Jan 21, 2007
    Posts:
    125
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    i did the project for you and added one more future
    Download Here
     
  6. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Random number

    CoolAdrrang to the rescue! him, Flaming Idiots, and a few other select people are like the only people active in the .Net forum - for that I credit them.

    I'm stopping Windows development all up now. Starting to get in to GTK+ development for Linux ;)
     
  7. Michael3455

    Michael3455 Active Member

    Joined:
    Sep 11, 2005
    Posts:
    134
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    Ah, that was above and beyond what I could have possibled hoped to acheive! Thank you very much!

    However, Like I said in my original message, this is just my first program in VB.NET and all, not to mention the fact I was just trying to see if I could do it... My teacher said that was what one of our future projects was going to be for my Software design course.

    Anyway, thankyou very much. It's good to know that people are glad and willing to help with VB.NET, as it seems everyone here just loves VB 6. I still dunno if I like VB.NET all the much... I dunno exactly why, it's just a naggling sort of a feeling like something is missing. :p

    Swan, good luck with the HTK development. If you ever need someone to help test anything or such, I'm more then willing to boot up in Ubuntu.

    Anyway, thinks. I'll just go look over that code, then edit my own so it's a tad bit better.

    EDIT: Looking over the code, I'm pretty impressed. I never even thought of generating the random number by a button click, or the way you did some of the othing things. However, I'm also kinda disappointed that I didn't think of it. It seems so darn simple that I think that I should have been able to do it.

    Meh. Perhaps I just hate being wrong and needing to ask for help. Anyway, thanks for the help and thanks for actually reworking the whole program to make it a lot better. Hopefully I'll be able to code that well quite soon. Even though I'm at the top of my class... I'm the only one who's done some coding before and no the *very* basics of VB.NEt so 'i lyk ownt dem all lyk' :p
     
  8. Swan

    Swan When They Cry...
    Retired Global Moderator

    Joined:
    Jan 23, 2007
    Posts:
    4,957
    Referrals:
    0
    Sythe Gold:
    0
    Sythe's 10th Anniversary Member of the Month Winner
    Random number

    You mean: GTK :p
    And I don't know that I'll get all that far in to it - School started, not much time for programming, I have to squeeze time in for everything else I need to do. Iight thanks anyway ;)
     
  9. Michael3455

    Michael3455 Active Member

    Joined:
    Sep 11, 2005
    Posts:
    134
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    Yeah, 'g' is next to 'h' and I have lazy fingers... I found out that I suffer from RSI too.... Lol. School just started for me too. I went from spending around a few minutes a day doing homework last year, to two hours... And I haven't even been at school for a week yet! Year 11 is a bitch.

    Ah, oh well. The classes are better at least. Physics, Software Design&Development, Maths, Legal Studies, Ancient History... All these lovely subjects that i actually like... Unlike learning about wars and Aboriginals for three years... Not that i'm racist, it's just a pretty dry subject. Kinda like watching snail races when entirely sobre.
     
  10. cooladrrang

    cooladrrang Active Member

    Joined:
    Jan 21, 2007
    Posts:
    125
    Referrals:
    0
    Sythe Gold:
    0
    Random number

    if you need any other projct done i can make it for you im good but im out of ideas that idea you had its cool for your first project (my first project apart from hello world was a calculator with webbrowser it sucks its a dowload.com if you want to see it)
    Edit: link Click Here
     
< [TUT] Linked Lists | Amazing tut to installing the JDK and API Documentation (lots of pics :D) >


 
 
Adblock breaks this site