Results 1 to 15 of 15

Thread: visual basic very basic beginners help please!

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Unhappy visual basic very basic beginners help please!

    im trying to generate a random integer from a range of two numbers. one with a larger value than the other. like i have three text boxes. one where i input the first value, then one for the second, and finally a textbox to display the random intgere in the range of the two values. my code does not seem to work. i dont know whats wrong. can anyone please help me?

    my code is as follows:

    Private Sub CmdRndInt_Click()
    Dim x As Integer, y As Integer, z As Integer

    x = Val(TxtMin) 'which is the first input box
    y = Val(TxtMax) 'which is the second input box
    z = Int((Rnd(xy))) 'the operation to calculate the random integer?? obviously wrong lol..
    TxtRndInt = z 'the display box for the random integer between the two values
    End Sub

  2. #2
    Addicted Member
    Join Date
    Jun 2010
    Location
    The Keystone State
    Posts
    131

    Re: visual basic very basic beginners help please!

    Code:
    RandomNumber = Int((MaxValue - MinValue + 1) * Rnd) + MinValue

    That is the Idea. You will need to substitute in your variables.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: visual basic very basic beginners help please!

    Being new to VB, you may want to spend a little time in the VB FAQs section. Within that section there happens to be a topic on random numbers. You can jump to the FAQs section via the link in my signature below
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Re: visual basic very basic beginners help please!

    Quote Originally Posted by B61Nuke View Post
    Code:
    RandomNumber = Int((MaxValue - MinValue + 1) * Rnd) + MinValue

    That is the Idea. You will need to substitute in your variables.
    thank you.

  5. #5
    Hyperactive Member
    Join Date
    Nov 2006
    Location
    Paris
    Posts
    301

    Re: visual basic very basic beginners help please!

    first off, to catch the value from the textboxes go like this:

    x=val(text.text)

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Re: visual basic very basic beginners help please!

    Quote Originally Posted by B61Nuke View Post
    Code:
    RandomNumber = Int((MaxValue - MinValue + 1) * Rnd) + MinValue

    That is the Idea. You will need to substitute in your variables.
    One more question if its alright with you )
    if for example, i have a name : adam, and i want to display it as Adam.
    how?

    the code i have is like :
    Dim A As String
    A = TxtFirstname.Text
    PicNameresult.Print (UCase(Left(A, 1)))
    end sub

    But that only prints A. it wont print the full name..

  7. #7
    Addicted Member
    Join Date
    Jun 2010
    Location
    The Keystone State
    Posts
    131

    Re: visual basic very basic beginners help please!

    I practically gave you the answer for the random number question you asked. Follow LaVolpe's advice and do a little reading on random numbers. Once you understand how the random number generator works, you will have no trouble using it.

  8. #8

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Re: visual basic very basic beginners help please!

    Quote Originally Posted by B61Nuke View Post
    I practically gave you the answer for the random number question you asked. Follow LaVolpe's advice and do a little reading on random numbers. Once you understand how the random number generator works, you will have no trouble using it.
    One more question if its alright with you )
    if for example, i have a name : adam, and i want to display it as Adam.
    how?

    the code i have is like :
    Dim A As String
    A = TxtFirstname.Text
    PicNameresult.Print (UCase(Left(A, 1)))
    end sub

    But that only prints A. it wont print the full name..

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: visual basic very basic beginners help please!

    Quote Originally Posted by Abs216 View Post
    the code i have is like :
    Dim A As String
    A = TxtFirstname.Text
    PicNameresult.Print (UCase(Left(A, 1)))
    end sub

    But that only prints A. it wont print the full name..
    Because your code is written to only print the 1st character, in upper case
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Re: visual basic very basic beginners help please!

    Quote Originally Posted by LaVolpe View Post
    Because your code is written to only print the 1st character, in upper case
    How can i make it print the first charachter in upper case as well as the full name like : Samplename instead of just S. ive been trying to do it for hours..

  11. #11
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: visual basic very basic beginners help please!

    Look at the StrConv function. It has a parameter vbProperCase which will print the entire string and capitalize the 1st character of each word

    Otherwise, you can do this: Print the 1st character upper case, then the remaining characters as is by using the Mid() function

    Suggest you read your help file regarding StrConv, Left, and Mid functions
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Thumbs up Re: visual basic very basic beginners help please!

    Quote Originally Posted by LaVolpe View Post
    Look at the StrConv function. It has a parameter vbProperCase which will print the entire string and capitalize the 1st character of each word

    Otherwise, you can do this: Print the 1st character upper case, then the remaining characters as is by using the Mid() function

    Suggest you read your help file regarding StrConv, Left, and Mid functions
    Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you Thank you thank you thank you sooo much dude

  13. #13

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    9

    Re: visual basic very basic beginners help please!

    Hey guys. i was wondering if you could help me. in my program i have a box where i want to input a few numbers. when i finish entering the numbers, i want toprint the average of the grades entered in a PictureBox, as well as the number of grades the student entered and the number of grades that are less than (50). please help me. i have done my research and really cannot seem to do it. kind regards.

  14. #14
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: visual basic very basic beginners help please!

    Wow. This guy has a private thread where you will all answer his individual questions! Didn't realise it worked like that round here!

    Does nobody here care about the ability for new users to search threads and find something specific?

  15. #15
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: visual basic very basic beginners help please!

    Figures that your manners would nose-dive once you'd got what you wanted. Have as nice a life as it is possible to have with an attitude like yours...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width