Martin2k Forums

Board index Visual Basic VB.NET

VB Visual Studio Help - Random Item / Treasure Roller

Ask questions about all versions of Visual Basic.NET (2002, 2003, 2005, 2008 & 2010) or anything to do with VB.NET programming.

VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Wed Dec 22, 2010 9:44 am

Greetings 9 years ago i learned alittle Visual basic 6.0 - with that knowledge i made a RPG Item treasure roller... it was lost in a HD crash

Im attempting it again...

This is the project goals i need help with

Dice Roller (d20) (20 sided) with adjustment by 2 different listboxes the dice roller will post to a textbox the total - I have done some of this so far and i have some of the code i have posted below

Then the rolled dice will associate with a number on a list that will print the result of the roll on the next text box of is it is a treasure or not - i have some of this done also

Then if there is a treasure roll then it will go to annother list and decide what specific item it is then print that result to a textbox - hmmm

Now if it is a magical item it will need to further roll on annother chart or possable charts assigning a possable prefix or suffix to that item - O.O

Lastly then the total things ie if it is magical with a prefix and suffix it will put them things together all in one text box making an item and name all in one...

Example of how it should look

<Label> You rolled: <textbox> Nothing
<Label> You rolled: <textbox> Gold <# of coins>
<Label> You rolled: <textbox> <Exsample is Armor> Plate Armor <details of armor>
<Label> You rolled: <textbox> <Example of simple Magical Dagger> Evil <prefix> Dagger <Details of Dagger> <Details of Prefix>
<Label> You rolled: <textbox> <Example of Magical Jewel> Quiet <Prefix> Jewel <Item> of Health <Suffix> <Details of Jewel> <Details of Prefix> <details of Suffix>
<Label> You rolled: <textbox> <Example of Complex Magic hat> Blood Cowel <Name Gen Prefix/Sufix> <random Gen 2 prefix and one suffix or vice versa *special> <Details on all>
i don't need to go on because most of the other stuff will be all basic text box add ins simple states applied to specific items... exc...

this is a snipit of what i got so far is there a better way to do this any suggestions will help and info on how to do it <examples would be grate>
Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Int(Rnd() * 50)
        TextBox2.Text = Int(Rnd() * 50)
        Select Case TextBox1.Text
            Case 0
                TextBox1.Text = "1"
                TextBox2.Text = "Trap"
            Case 1
                TextBox1.Text = "2"
                TextBox2.Text = "Nothing"
Exc....

         End Select
    End Sub
End Class

Help?

Velendar Halberd the Goblin King
The Dungeon Master Bard
Very Rusty VB user

And if you wonder this is an adaptation of diablo 2 item generator <and yes i know there is a Java based one on WotC>
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Mark » Wed Dec 22, 2010 2:12 pm

You are pretty much using VB6 syntax. The VB.NET way to do the same thing would be

Code: Select all
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rndRandomClass As New Random()
        Dim intDice1 As Integer = rndRandomClass.Next(1, 20)
        Dim intDice2 As Integer = rndRandomClass.Next(1, 20)

        TextBox1.Text = intDice1.ToString()

        Select Case intDice1
            Case 1
                TextBox2.Text = "Trap"
            Case 2
                TextBox2.Text = "Nothing"
            Case 3
                TextBox2.Text = ""
        End Select
    End Sub


When calling the next method of the RandomClass, one of the overloads allows you to specify the lower and upper range of your number set.
Mark
Moderator
 
Posts: 129
Joined: Wed Dec 01, 2010 5:40 pm
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Keith » Wed Dec 22, 2010 9:25 pm

Welcome to the forum. :vbwelcome:
velendar wrote:
Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = Int(Rnd() * 50)
        TextBox2.Text = Int(Rnd() * 50)
        Select Case TextBox1.Text
            Case 0
                TextBox1.Text = "1"
                TextBox2.Text = "Trap"
            Case 1
                TextBox1.Text = "2"
                TextBox2.Text = "Nothing"
Exc....

         End Select
    End Sub
End Class


With code like that isn't VB6. ;)
I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Image
Keith
Administrator
 
Posts: 869
Joined: Tue Oct 13, 2009 12:15 am
Location: Stoke on Trent, England
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Mark » Wed Dec 22, 2010 9:57 pm

I was just referring to the syntax within the click event. If you cut that out and place it in vb6 it would almost work.
Mark
Moderator
 
Posts: 129
Joined: Wed Dec 01, 2010 5:40 pm
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Wed Dec 22, 2010 11:28 pm

Wow thanks for the active responce...

Ok thanks to mark it seems to load faster on test.... and it seems that it works good

Now on to the two listboxes one will be an adjustment to the roll of the 1 to 20 of a bonus up 2 30 <as in> Roll a d20 Level adjustment of +30 Max to roll the drop down list will be up to 30 i think i know how to do that with add item... but how do i make that effect the dice roll outcome?

The Second list will be minor adjustment to the dice roll additionally by <minus 1> / 2 / 4 / 6 Effectively

The problem i am having at this point is ... ListBox1 do i have to add them trough additem because im getting a warning <security i believe> currently i have them assigned by collection in the propertys...

this is what the code looks like now
Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rndRandomClass As New Random()
        Dim intDice1 As Integer = rndRandomClass.Next(1, 20)
        Dim intDice2 As Integer = rndRandomClass.Next(1, 20)

        TextBox1.Text = intDice1.ToString()

        Select Case intDice1
            Case 1
                TextBox2.Text = "Trap"
            Case 2
                TextBox2.Text = "Nothing"
            Case 3
                TextBox2.Text = "Perishable"
            Case 4
                TextBox2.Text = "Gold"
            Case 5
                 TextBox2.Text = "Normal item"
            Case 6
                TextBox2.Text = "Magical item"
            Case 7
                TextBox2.Text = "Magical item"
            Case 8
                TextBox2.Text = "Magical item"
            Case 9
                TextBox2.Text = "Magical item"
            Case 10
                TextBox2.Text = "Magical item"
            Case 11
                TextBox2.Text = "Magical item"
            Case 12
                TextBox2.Text = "Magical item"
            Case 13
                TextBox2.Text = "Magical item"
            Case 14
                TextBox2.Text = "Magical item"
            Case 15
                TextBox2.Text = "Magical item"
            Case 16
                TextBox2.Text = "Magical item"
            Case 17
                TextBox2.Text = "Magical item"
            Case 18
                TextBox2.Text = "Magical item"
            Case 19
                TextBox2.Text = "Magical item"
        End Select
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
End Class



Somehow i beleve this can help but i dont know what to do with it... ListBox1.Items.Add(toss.ToString)

also thanks for the welcome to the forums...

Velendar Halberd the Goblin King
The Dungeon Master Bard
Very Rusty VB user
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Keith » Thu Dec 23, 2010 6:31 pm

Ok put us out of our missery is it VB6 or VB.Net why do I have to keep on repeating myself? :demon:
I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Image
Keith
Administrator
 
Posts: 869
Joined: Tue Oct 13, 2009 12:15 am
Location: Stoke on Trent, England
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Fri Dec 24, 2010 12:17 am

Oops im working with Ultimate 2010 VB net part of it... i was saying used vb6 in the past and i just upgraded :D

Velendar Halberd the Goblin King
The Dungeon Master Bard
Very Rusty VB user
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Keith » Fri Dec 24, 2010 1:53 am

Ok carry on, I don't use VB.Net even thoughI have 2008 and 2010, Mark sould help you out with this. ;)
I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Image
Keith
Administrator
 
Posts: 869
Joined: Tue Oct 13, 2009 12:15 am
Location: Stoke on Trent, England
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Fri Dec 24, 2010 5:46 am

OK

how can i get this to effect the above code?

Code: Select all
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,_ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

        Dim num As Integer = CInt(ListBox1.SelectedItem)

        TextBox1.Text = ListBox1.SelectedItem         'using the selected item property


    End Sub
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Mark » Fri Dec 24, 2010 2:49 pm

Why bother with SelectedItem?
Code: Select all
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        TextBox1.Text = ListBox1.Text
    End Sub
Mark
Moderator
 
Posts: 129
Joined: Wed Dec 01, 2010 5:40 pm
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Fri Dec 24, 2010 6:31 pm

there will be 4 drop down Listboxes that will make variable adjustments to the dice roll
one will be + 1 to + 30 another will be -1 / +2 / +4 / +6
Exc...
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Mark » Fri Dec 24, 2010 6:34 pm

Not following you there. You are going to have to do a lot better explaining what you need.
Mark
Moderator
 
Posts: 129
Joined: Wed Dec 01, 2010 5:40 pm
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Fri Dec 24, 2010 10:40 pm

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rndRandomClass As New Random()
Dim intDice1 As Integer = rndRandomClass.Next(1, 20)
Dim intDice2 As Integer = rndRandomClass.Next(1, 20)

TextBox1.Text = intDice1.ToString()

Select Case intDice1
Case 1
TextBox2.Text = "Trap"

I know in there someplace a calculation formula can be added that on a listbox you can drop down a numerical adjustment such a +1 to 1 to 20 roll
The first listbox will have 1, 2, 3, 4, ... 19, 20 the associated # lets say a 1 selected in the listbox it adds a +1 to the 1-20 roll the random 1-20 will become a 2-21

I hope that helps :D
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Mark » Sat Dec 25, 2010 1:56 am

Still not sure I understand but give this a try
Code: Select all
Public Class Form1
    Const DiceLow As Integer = 1
    Const DiceHigh As Integer = 20
    Dim intLow As Integer = 0
    Dim intHigh As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer

        For i = 1 To 20
            ListBox1.Items.Add(i.ToString())
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rndRandomClass As New Random()

        intLow = DiceLow + (ListBox1.SelectedIndex + 1)
        intHigh = DiceHigh + (ListBox1.SelectedIndex + 1)
        Dim intDice1 As Integer = rndRandomClass.Next(intLow, intHigh)
        'Dim intDice2 As Integer = rndRandomClass.Next(1, 20)

        TextBox1.Text = intDice1.ToString()

        'Select Case intDice1
        '    Case 1
        '        TextBox2.Text = "Trap"
        '    Case 2
        '        TextBox2.Text = "Nothing"
        '    Case 3
        '        TextBox2.Text = ""
        'End Select
    End Sub
Mark
Moderator
 
Posts: 129
Joined: Wed Dec 01, 2010 5:40 pm
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Keith » Sat Dec 25, 2010 12:38 pm

One thing you must learn when using VB is to give all your controls a useful/meaningful names don't use the default names as its a bit confusing for yourself and others.

Merry Christmas. Image
I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Image
Keith
Administrator
 
Posts: 869
Joined: Tue Oct 13, 2009 12:15 am
Location: Stoke on Trent, England
Medals: 1
6 Star (1)

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Sun Dec 26, 2010 1:16 am

Ignore this post i am placing my code for reference

Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rndRandomClass As New Random()
        Dim intDice1 As Integer = rndRandomClass.Next(1, 20)
        Dim intDice2 As Integer = rndRandomClass.Next(1, 20)

        TextBox1.Text = intDice1.ToString()

        Select Case intDice1
            Case 1
                TextBox2.Text = "Trap"
            Case 2
                TextBox2.Text = "Nothing"
            Case 3
                TextBox2.Text = "Perishable"
            Case 4
                TextBox2.Text = "Gold"
            Case 5
                TextBox2.Text = "Normal item"
            Case 6
                TextBox2.Text = "Magical item"
            Case 7
                TextBox2.Text = "Magical item"
            Case 8
                TextBox2.Text = "Magical item"
            Case 9
                TextBox2.Text = "Magical item"
            Case 10
                TextBox2.Text = "Magical item"
            Case 11
                TextBox2.Text = "Magical item"
            Case 12
                TextBox2.Text = "Magical item"
            Case 13
                TextBox2.Text = "Magical item"
            Case 14
                TextBox2.Text = "Magical item"
            Case 15
                TextBox2.Text = "Magical item"
            Case 16
                TextBox2.Text = "Magical item"
            Case 17
                TextBox2.Text = "Magical item"
            Case 18
                TextBox2.Text = "Magical item"
            Case 19
                TextBox2.Text = "Magical item"
            Case 20
                TextBox2.Text = "Magical item"
        End Select
    End Sub

    '    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,_ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

    'Dim num As Integer = CInt(ListBox1.SelectedItem)

    '        TextBox1.Text = ListBox1.SelectedItem         'using the selected item property


    '    End Sub

End Class
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Sun Dec 26, 2010 1:19 am

Keith you make a great point i will see if i can better explain again and rename some of the stuff in the code to help

Thanks guys and MERRY CRISTMAS....
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Sun Dec 26, 2010 1:32 am

OK Let me see if i can explain a little better about what i wanna do...

A person sits at a table with a few Books and some dice...

He <the person> gets out his book with the correct chart on it then gets a 20 sided dice

Lets say the Monster he just fought was Level 1 he rolls the 20 sided dice and adds a +1 to the roll and the result will be between 2 and 21... he will want to look up on the chart the appropriate Reward he will receive...

> Establish a button that rolls a 1 to 20
> Establish a Listbox that you can select between 0 and 10 <for ease> this number will adjust the 1 to 20 roll
> that total number will place in a text box and then look up on a chart within program select the Appropriate reward then print that Reward result to a text box

The code above for refrence was what i had... it did as i asked for the roll and the result but i could not adjust the roll in any way... i don't know how to make the listbox do that

I might be speaking Roleplayer Language to some but i think it did put it into alittle better trems... :P

MERRY CRISTMAS!!!! :band:
THE GOBLIN KING
VELENDAR HALBERD
THE DUNGEON MASTER BARD
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby velendar » Sun Dec 26, 2010 9:56 pm

Perhaps case is not the way to do what i need done... i have seen java and i dont know it but i have looked at some of the code... perhaps there is a way in visual basic to do something like this...

Random number 1, 20
if less than 14 then print this in text box "Whatever"
if greater than or equal to 15 then print this "whatever"
if Greater than or equal to 20 then print this "Ultimate Whatever"

does this make sense i feel my Ancient experience with basic syntax programing bleeding in there...

lol
velendar
Newcomer
 
Posts: 13
Joined: Wed Dec 22, 2010 9:12 am

Re: VB Visual Studio Help - Random Item / Treasure Roller

Postby Keith » Mon Dec 27, 2010 2:56 am

Well the Select Case is a very useful function in VB6 so I would give it a go. ;)
I've been programming with VB for 17 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

Image
Keith
Administrator
 
Posts: 869
Joined: Tue Oct 13, 2009 12:15 am
Location: Stoke on Trent, England
Medals: 1
6 Star (1)

Next

Return to VB.NET

Who is online

Users browsing this forum: No registered users and 1 guest

cron