UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, The GoNix Initiative, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
Sponsored Links
Latest Postings
Latest Reviews
Topic Options
Rate This Topic
#17539 - 12/03/04 12:42 AM Help with VB.net Program
Lucid Offline
Junior Member

Registered: 12/02/04
Posts: 1
Loc: US
The purpose of the program is to simulate rolling a six sided die. Then the program keeps track of the frequency of each roll, the number of total rolls and the probability . My problem is that every time my program simulates rolling a one it prints to Frq1 and does not increment correctly. I want it to increment each time by one starting from a value of zero. Any help would be greatly appreciated.
Code:

Private Sub Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calculate.Click
Dim Frequency As Double
Dim Probability As Decimal
Dim DieNumber As Integer
Dim One, Two, Three, Four, Five, Six As Integer


One = 0

IncrementCounter:

Randomize()
DieNumber = CInt(Int((6 * Rnd()) + 1))
Results.Items.Add(DieNumber)

Select Case True
Case DieNumber = 1
One = One + 1


Frq1.Items.Add(One)
GoTo IncrementCounter

End Select

Top
Sponsored Links
      
#17540 - 12/12/04 04:33 PM Re: Help with VB.net Program
n0mel Offline
Junior Member

Registered: 04/30/04
Posts: 34
Loc: ...
You know, a do loop would work just as well as a goto. People might make fun of you if you use gotos.

Look at where your end select is. (wink wink).

Not that your way is wrong, but another way to do what you're doing is to use an array, such as

dim dienumbers(5) as integer

then, you could do

DieNumber = CInt(Int((6 * Rnd()) + 1))
other stuff
dienumbers(dienumber-1) = dienumbers(dienumber-1) + 1
other stuff
Freq1.items.add(dienumbers(dienumber-1))

Since the array starts at 0, all values for one would be stored in dienumbers(0), and all from 6 would be in dienumbers(5). If you didn't mind, you could waste the first element of the array and use dim dienumbers(6) and dienumbers(dienumber) = blah.

The benefit of this way is not as much typing for you

This is the first time I've seen vb.net code. Doesn't look too different from vb6. What is with the ") Handles Calculate.Click"? Can you specify the subroutine for an event?

Top

Featured Member
Registered: 02/28/02
Posts: 7193
Forum Stats
2148 Members
46 Forums
35091 Topics
70261 Posts

Max Online: 1567 @ 04/25/10 05:20 AM
Top Posters
UGN Security 28253
Gremelin 7193
§intå× 3255
SilentRage 1273
Ice 1146
pergesu 1136
Infinite 1041
jonconley 955
Girlie 908
unreal 860
Newest Members
Tim050, Gecko666, defghi795767, Devo60, ali
2148 Registered Users
Who's Online
0 registered (), 421 Guests and 271 Spiders online.
Key: Admin, Global Mod, Mod
Latest News


Donate
  Get Firefox!
Get FireFox!