Welcome to Dream.In.Code
Become a VB Expert!

Join 137,231 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,829 people online right now. Registration is fast and FREE... Join Now!




help rnd()

 
Reply to this topicStart new topic

help rnd(), kilometers calculator

ante
5 Feb, 2007 - 01:46 PM
Post #1

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 2


My Contributions
Hi all have seen your forum, very helpfull. But i'm just starting whith visual basic, i'm using Microsoft Visual Basic 2005 Express Edition. I need to do a prog that calculate the number of kilometers that a do in a week monday to friday. It works like this i type the starting km and the final km and the prog calculate the km i did by day, displaying like this. IPB Image


What i need to do now is to get the prog to make the ending km " km finais" to be random, but the final sum of the value must be iqual to (ending km - starting km). I made the code very simple, must like excel.

Private Sub calc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calc.Click
med.Text = (Val(kmf.Text) - Val(kmi.Text)) / 5
ki1.Text = Val(kmi.Text)
kf5.Text = Val(kmf.Text)
kf1.Text = Val(ki1.Text) + Val(med.Text)
ki2.Text = Val(kf1.Text)
kf2.Text = Val(ki2.Text) + Val(med.Text)
ki3.Text = Val(kf2.Text)
kf3.Text = Val(ki3.Text) + Val(med.Text)
ki4.Text = Val(kf3.Text)
kf4.Text = Val(ki4.Text) + Val(med.Text)
ki5.Text = Val(kf4.Text)
kf5.Text = Val(ki5.Text) + Val(med.Text)
kmfeitos.Text = Val(kmf.Text) - Val(kmi.Text)

End Sub


How can i make the kf?.Text random keeping the result of their sum be equal to kmf.Text - kmi.Text ??? i'm just lost. Sorry for language, i dont know how to write very well.

This post has been edited by ante: 5 Feb, 2007 - 02:23 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Help Rnd()
5 Feb, 2007 - 04:53 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,984



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
I'm not sure I understand what you want.

Are you asking how to create a random number?

Or how to create two random numbers that equal the sum of kmf.Text - kmi.Text ?

Sorry but you are going to need to clarify with an example if possible.
User is offlineProfile CardPM
+Quote Post

Ryan747
RE: Help Rnd()
5 Feb, 2007 - 05:14 PM
Post #3

New D.I.C Head
*

Joined: 16 Oct, 2006
Posts: 26


My Contributions
what are you trying to do make a random kilometer?

km = rnd() % value
User is offlineProfile CardPM
+Quote Post

ante
RE: Help Rnd()
6 Feb, 2007 - 11:13 AM
Post #4

New D.I.C Head
*

Joined: 5 Feb, 2007
Posts: 2


My Contributions
tkx guys, what i need to do is this:

i drive a company car, every week i need to give them a sheet with the km i made. The prog that i've wrote creats the average km per day when i input the km i started and the km i finished with. Then it wrights in the first up left field the starting km and at the right field it adds the average per day value. The result i'll
always be the starting day (km + average per day km). I need to make the "finish km" to be random. So at the end it doesn't seem to be like i made the same km every day.

IPB Image

Eg.

monday: ki1.Text = Val(kmi.Text)
kf1.Text = Val(ki1.Text) + Val(med.Text)

Tuesday: ki2.Text = Val(kf1.Text)
kf2.Text = Val(ki2.Text) + Val(med.Text)


and so on...

now i need to make the " kf*.Text values to oscilate and not to be always equal to the sum of ki + Val(med.Text). How can i make this keeping the sum of all "kf" equal to to the diference of (Val(kmf.Text) - Val(kmi.Text). I keep reading some books to learn more about VB. Do you have any sugestions on good books for start at VB programming??

This post has been edited by ante: 6 Feb, 2007 - 11:15 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:26PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month