-
Mar 27th, 2012, 02:24 PM
#1
Thread Starter
New Member
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
-
Mar 27th, 2012, 03:05 PM
#2
Addicted Member
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.
-
Mar 27th, 2012, 03:12 PM
#3
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
-
Mar 27th, 2012, 03:18 PM
#4
Thread Starter
New Member
Re: visual basic very basic beginners help please!
Originally Posted by B61Nuke
Code:
RandomNumber = Int((MaxValue - MinValue + 1) * Rnd) + MinValue
That is the Idea. You will need to substitute in your variables.
thank you.
-
Mar 27th, 2012, 03:21 PM
#5
Hyperactive Member
Re: visual basic very basic beginners help please!
first off, to catch the value from the textboxes go like this:
x=val(text.text)
-
Mar 27th, 2012, 03:24 PM
#6
Thread Starter
New Member
Re: visual basic very basic beginners help please!
Originally Posted by B61Nuke
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..
-
Mar 27th, 2012, 03:26 PM
#7
Addicted Member
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.
-
Mar 27th, 2012, 03:36 PM
#8
Thread Starter
New Member
Re: visual basic very basic beginners help please!
Originally Posted by B61Nuke
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..
-
Mar 27th, 2012, 03:40 PM
#9
Re: visual basic very basic beginners help please!
Originally Posted by Abs216
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
-
Mar 27th, 2012, 03:42 PM
#10
Thread Starter
New Member
Re: visual basic very basic beginners help please!
Originally Posted by LaVolpe
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..
-
Mar 27th, 2012, 03:52 PM
#11
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
-
Mar 27th, 2012, 03:55 PM
#12
Thread Starter
New Member
Re: visual basic very basic beginners help please!
Originally Posted by LaVolpe
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
-
Apr 22nd, 2012, 11:53 AM
#13
Thread Starter
New Member
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.
-
Apr 22nd, 2012, 08:58 PM
#14
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?
-
Apr 24th, 2012, 05:06 PM
#15
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|