PC Review


Reply
Thread Tools Rate Thread

Creating a button...

 
 
Markv
Guest
Posts: n/a
 
      20th Jun 2008
Hi all.

Does anyone have the formula to create a button on your work sheet that upon
clicking on it will give you a result?

ie. dice rolls, I would click on the button and the dice will roll.

Thanks.

 
Reply With Quote
 
 
 
 
Nayab
Guest
Posts: n/a
 
      20th Jun 2008
On Jun 20, 12:15*pm, Markv <Ma...@discussions.microsoft.com> wrote:
> Hi all.
>
> Does anyone have the formula to create a button on your work sheet that upon
> clicking on it will give you a result?
>
> ie. dice rolls, I would click on the button and the dice will roll.
>
> Thanks.


Mark, button can be made but only button can't make things roll. U can
internally rite some vb code/macro to make things happen and then u
need to attach the click of this button to this macro. Otherwise u can
insert control buttons and on click of these buttons u can write the
corresponding code
 
Reply With Quote
 
Markv
Guest
Posts: n/a
 
      20th Jun 2008
thanks Mate, do you know the VB code for this. I have never used this type
programming

"Nayab" wrote:

> On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > Hi all.
> >
> > Does anyone have the formula to create a button on your work sheet that upon
> > clicking on it will give you a result?
> >
> > ie. dice rolls, I would click on the button and the dice will roll.
> >
> > Thanks.

>
> Mark, button can be made but only button can't make things roll. U can
> internally rite some vb code/macro to make things happen and then u
> need to attach the click of this button to this macro. Otherwise u can
> insert control buttons and on click of these buttons u can write the
> corresponding code
>

 
Reply With Quote
 
Nayab
Guest
Posts: n/a
 
      20th Jun 2008
On Jun 20, 2:41*pm, Markv <Ma...@discussions.microsoft.com> wrote:
> thanks Mate, do you know the VB code for this. I have never used this type
> programming
>
>
>
> "Nayab" wrote:
> > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > Hi all.

>
> > > Does anyone have the formula to create a button on your work sheet that upon
> > > clicking on it will give you a result?

>
> > > ie. dice rolls, I would click on the button and the dice will roll.

>
> > > Thanks.

>
> > Mark, button can be made but only button can't make things roll. U can
> > internally rite some vb code/macro to make things happen and then u
> > need to attach the click of this button to this macro. Otherwise u can
> > insert control buttons and on click of these buttons u can write the
> > corresponding code- Hide quoted text -

>
> - Show quoted text -


Mark, I am not sure what exactly is ur requirement. Do you want to
display randomly picked values between 1,6 when you click a button?

If this is the case then, choose control toolbox and select the button
and draw it on the worksheet. Right click on this button and slect
view code.

On the code page, u see::::
Private Sub CommandButton1_Click()

End Sub


Change this to::::::::::::::::::


Private Sub CommandButton1_Click()
Dim rand_dice As Double
rand_dice = Rnd()
If rand_dice < 1 / 6 Then
rand_dice = 1
ElseIf rand_dice < 2 / 6 Then
rand_dice = 2
ElseIf rand_dice < 3 / 6 Then
rand_dice = 3
ElseIf rand_dice < 4 / 6 Then
rand_dice = 4
ElseIf rand_dice < 5 / 6 Then
rand_dice = 5
Else
rand_dice = 6
End If

MsgBox rand_dice

End Sub

 
Reply With Quote
 
Markv
Guest
Posts: n/a
 
      20th Jun 2008
Hey there...Thanks that is spot on. cause i have created a virtual business
where you control,buy and sell stock and run a business. The trick here is to
see how long you can run without getting bancrupt. You can also buy personal
things and so on...

however to play this I had to replace real dies with excell type formulas
and macros
thanks again.

"Nayab" wrote:

> On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > thanks Mate, do you know the VB code for this. I have never used this type
> > programming
> >
> >
> >
> > "Nayab" wrote:
> > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > Hi all.

> >
> > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > clicking on it will give you a result?

> >
> > > > ie. dice rolls, I would click on the button and the dice will roll.

> >
> > > > Thanks.

> >
> > > Mark, button can be made but only button can't make things roll. U can
> > > internally rite some vb code/macro to make things happen and then u
> > > need to attach the click of this button to this macro. Otherwise u can
> > > insert control buttons and on click of these buttons u can write the
> > > corresponding code- Hide quoted text -

> >
> > - Show quoted text -

>
> Mark, I am not sure what exactly is ur requirement. Do you want to
> display randomly picked values between 1,6 when you click a button?
>
> If this is the case then, choose control toolbox and select the button
> and draw it on the worksheet. Right click on this button and slect
> view code.
>
> On the code page, u see::::
> Private Sub CommandButton1_Click()
>
> End Sub
>
>
> Change this to::::::::::::::::::
>
>
> Private Sub CommandButton1_Click()
> Dim rand_dice As Double
> rand_dice = Rnd()
> If rand_dice < 1 / 6 Then
> rand_dice = 1
> ElseIf rand_dice < 2 / 6 Then
> rand_dice = 2
> ElseIf rand_dice < 3 / 6 Then
> rand_dice = 3
> ElseIf rand_dice < 4 / 6 Then
> rand_dice = 4
> ElseIf rand_dice < 5 / 6 Then
> rand_dice = 5
> Else
> rand_dice = 6
> End If
>
> MsgBox rand_dice
>
> End Sub
>
>

 
Reply With Quote
 
Nayab
Guest
Posts: n/a
 
      20th Jun 2008
On Jun 20, 4:42*pm, Markv <Ma...@discussions.microsoft.com> wrote:
> Hey there...Thanks that is spot on. cause i have created a virtual business
> where you control,buy and sell stock and run a business. The trick here is to
> see how long you can run without getting bancrupt. You can also buy personal
> things and so on...
>
> however to play this I had to replace real dies with excell type formulas
> and macros
> thanks again.
>
>
>
> "Nayab" wrote:
> > On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > thanks Mate, do you know the VB code for this. I have never used thistype
> > > programming

>
> > > "Nayab" wrote:
> > > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > Hi all.

>
> > > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > > clicking on it will give you a result?

>
> > > > > ie. dice rolls, I would click on the button and the dice will roll.

>
> > > > > Thanks.

>
> > > > Mark, button can be made but only button can't make things roll. U can
> > > > internally rite some vb code/macro to make things happen and then u
> > > > need to attach the click of this button to this macro. Otherwise u can
> > > > insert control buttons and on click of these buttons u can write the
> > > > corresponding code- Hide quoted text -

>
> > > - Show quoted text -

>
> > Mark, I am not sure what exactly is ur requirement. Do you want to
> > display randomly picked values between 1,6 when you click a button?

>
> > If this is the case then, choose control toolbox and select the button
> > and draw it on the worksheet. Right click on this button and slect
> > view code.

>
> > On the code page, u see::::
> > Private Sub CommandButton1_Click()

>
> > End Sub

>
> > Change this to::::::::::::::::::

>
> > Private Sub CommandButton1_Click()
> > Dim rand_dice As Double
> > rand_dice = Rnd()
> > If rand_dice < 1 / 6 Then
> > rand_dice = 1
> > ElseIf rand_dice < 2 / 6 Then
> > rand_dice = 2
> > ElseIf rand_dice < 3 / 6 Then
> > rand_dice = 3
> > ElseIf rand_dice < 4 / 6 Then
> > rand_dice = 4
> > ElseIf rand_dice < 5 / 6 Then
> > rand_dice = 5
> > Else
> > rand_dice = 6
> > End If

>
> > MsgBox rand_dice

>
> > End Sub- Hide quoted text -

>
> - Show quoted text -


Mark, just to make things better, please add randomize prior to the
call to Rnd(). So the new code will be ------

Private Sub CommandButton1_Click()
Dim rand_dice As Double
randomize
rand_dice = Rnd()
If rand_dice < 1 / 6 Then
rand_dice = 1
ElseIf rand_dice < 2 / 6 Then
rand_dice = 2
ElseIf rand_dice < 3 / 6 Then
rand_dice = 3
ElseIf rand_dice < 4 / 6 Then
rand_dice = 4
ElseIf rand_dice < 5 / 6 Then
rand_dice = 5
Else
rand_dice = 6
End If


MsgBox rand_dice


End Sub




The randomize ensures that a new seed is taken each time.

Glad to help.
 
Reply With Quote
 
Markv
Guest
Posts: n/a
 
      20th Jun 2008
thanks a million..One more question.
Instead of displaying the result in a message box can it be shown in a cell?

If so please advise...

"Nayab" wrote:

> On Jun 20, 4:42 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > Hey there...Thanks that is spot on. cause i have created a virtual business
> > where you control,buy and sell stock and run a business. The trick here is to
> > see how long you can run without getting bancrupt. You can also buy personal
> > things and so on...
> >
> > however to play this I had to replace real dies with excell type formulas
> > and macros
> > thanks again.
> >
> >
> >
> > "Nayab" wrote:
> > > On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > thanks Mate, do you know the VB code for this. I have never used this type
> > > > programming

> >
> > > > "Nayab" wrote:
> > > > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > > Hi all.

> >
> > > > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > > > clicking on it will give you a result?

> >
> > > > > > ie. dice rolls, I would click on the button and the dice will roll.

> >
> > > > > > Thanks.

> >
> > > > > Mark, button can be made but only button can't make things roll. U can
> > > > > internally rite some vb code/macro to make things happen and then u
> > > > > need to attach the click of this button to this macro. Otherwise u can
> > > > > insert control buttons and on click of these buttons u can write the
> > > > > corresponding code- Hide quoted text -

> >
> > > > - Show quoted text -

> >
> > > Mark, I am not sure what exactly is ur requirement. Do you want to
> > > display randomly picked values between 1,6 when you click a button?

> >
> > > If this is the case then, choose control toolbox and select the button
> > > and draw it on the worksheet. Right click on this button and slect
> > > view code.

> >
> > > On the code page, u see::::
> > > Private Sub CommandButton1_Click()

> >
> > > End Sub

> >
> > > Change this to::::::::::::::::::

> >
> > > Private Sub CommandButton1_Click()
> > > Dim rand_dice As Double
> > > rand_dice = Rnd()
> > > If rand_dice < 1 / 6 Then
> > > rand_dice = 1
> > > ElseIf rand_dice < 2 / 6 Then
> > > rand_dice = 2
> > > ElseIf rand_dice < 3 / 6 Then
> > > rand_dice = 3
> > > ElseIf rand_dice < 4 / 6 Then
> > > rand_dice = 4
> > > ElseIf rand_dice < 5 / 6 Then
> > > rand_dice = 5
> > > Else
> > > rand_dice = 6
> > > End If

> >
> > > MsgBox rand_dice

> >
> > > End Sub- Hide quoted text -

> >
> > - Show quoted text -

>
> Mark, just to make things better, please add randomize prior to the
> call to Rnd(). So the new code will be ------
>
> Private Sub CommandButton1_Click()
> Dim rand_dice As Double
> randomize
> rand_dice = Rnd()
> If rand_dice < 1 / 6 Then
> rand_dice = 1
> ElseIf rand_dice < 2 / 6 Then
> rand_dice = 2
> ElseIf rand_dice < 3 / 6 Then
> rand_dice = 3
> ElseIf rand_dice < 4 / 6 Then
> rand_dice = 4
> ElseIf rand_dice < 5 / 6 Then
> rand_dice = 5
> Else
> rand_dice = 6
> End If
>
>
> MsgBox rand_dice
>
>
> End Sub
>
>
>
>
> The randomize ensures that a new seed is taken each time.
>
> Glad to help.
>

 
Reply With Quote
 
Nayab
Guest
Posts: n/a
 
      20th Jun 2008
On Jun 20, 5:39*pm, Markv <Ma...@discussions.microsoft.com> wrote:
> thanks a million..One more question.
> Instead of displaying the result in a message box can it be shown in a cell?
>
> If so please advise...
>
>
>
> "Nayab" wrote:
> > On Jun 20, 4:42 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > Hey there...Thanks that is spot on. cause i have created a virtual business
> > > where you control,buy and sell stock and run a business. The trick here is to
> > > see how long you can run without getting bancrupt. You can also buy personal
> > > things and so on...

>
> > > however to play this I had to replace real dies with excell type formulas
> > > and macros
> > > thanks again.

>
> > > "Nayab" wrote:
> > > > On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > thanks Mate, do you know the VB code for this. I have never used this type
> > > > > programming

>
> > > > > "Nayab" wrote:
> > > > > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > > > Hi all.

>
> > > > > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > > > > clicking on it will give you a result?

>
> > > > > > > ie. dice rolls, I would click on the button and the dice willroll.

>
> > > > > > > Thanks.

>
> > > > > > Mark, button can be made but only button can't make things roll.. U can
> > > > > > internally rite some vb code/macro to make things happen and then u
> > > > > > need to attach the click of this button to this macro. Otherwise u can
> > > > > > insert control buttons and on click of these buttons u can write the
> > > > > > corresponding code- Hide quoted text -

>
> > > > > - Show quoted text -

>
> > > > Mark, I am not sure what exactly is ur requirement. Do you want to
> > > > display randomly picked values between 1,6 when you click a button?

>
> > > > If this is the case then, choose control toolbox and select the button
> > > > and draw it on the worksheet. Right click on this button and slect
> > > > view code.

>
> > > > On the code page, u see::::
> > > > Private Sub CommandButton1_Click()

>
> > > > End Sub

>
> > > > Change this to::::::::::::::::::

>
> > > > Private Sub CommandButton1_Click()
> > > > Dim rand_dice As Double
> > > > rand_dice = Rnd()
> > > > If rand_dice < 1 / 6 Then
> > > > rand_dice = 1
> > > > ElseIf rand_dice < 2 / 6 Then
> > > > rand_dice = 2
> > > > ElseIf rand_dice < 3 / 6 Then
> > > > rand_dice = 3
> > > > ElseIf rand_dice < 4 / 6 Then
> > > > rand_dice = 4
> > > > ElseIf rand_dice < 5 / 6 Then
> > > > rand_dice = 5
> > > > Else
> > > > rand_dice = 6
> > > > End If

>
> > > > MsgBox rand_dice

>
> > > > End Sub- Hide quoted text -

>
> > > - Show quoted text -

>
> > Mark, just to make things better, please add randomize prior to the
> > call to Rnd(). So the new code will be ------

>
> > Private Sub CommandButton1_Click()
> > Dim rand_dice As Double
> > randomize
> > rand_dice = Rnd()
> > If rand_dice < 1 / 6 Then
> > rand_dice = 1
> > ElseIf rand_dice < 2 / 6 Then
> > rand_dice = 2
> > ElseIf rand_dice < 3 / 6 Then
> > rand_dice = 3
> > ElseIf rand_dice < 4 / 6 Then
> > rand_dice = 4
> > ElseIf rand_dice < 5 / 6 Then
> > rand_dice = 5
> > Else
> > rand_dice = 6
> > End If

>
> > MsgBox rand_dice

>
> > End Sub

>
> > The randomize ensures that a new seed is taken each time.

>
> > Glad to help.- Hide quoted text -

>
> - Show quoted text -


Dude, you can do watever u like (well not all things u can think of,
but majority of them) with the number.

as u have the number in the variable rand_dice, if you want to display
it in say A1 then replace the msgbox line with:

Sheets(1).Range("A1").value = rand_dice

and u will get the value in A1 of the 1st sheet of the workbook...

Cheers!
 
Reply With Quote
 
Markv
Guest
Posts: n/a
 
      20th Jun 2008
Thank you your tips is very detailed and thank you for your patience

"Nayab" wrote:

> On Jun 20, 5:39 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > thanks a million..One more question.
> > Instead of displaying the result in a message box can it be shown in a cell?
> >
> > If so please advise...
> >
> >
> >
> > "Nayab" wrote:
> > > On Jun 20, 4:42 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > Hey there...Thanks that is spot on. cause i have created a virtual business
> > > > where you control,buy and sell stock and run a business. The trick here is to
> > > > see how long you can run without getting bancrupt. You can also buy personal
> > > > things and so on...

> >
> > > > however to play this I had to replace real dies with excell type formulas
> > > > and macros
> > > > thanks again.

> >
> > > > "Nayab" wrote:
> > > > > On Jun 20, 2:41 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > > thanks Mate, do you know the VB code for this. I have never used this type
> > > > > > programming

> >
> > > > > > "Nayab" wrote:
> > > > > > > On Jun 20, 12:15 pm, Markv <Ma...@discussions.microsoft.com> wrote:
> > > > > > > > Hi all.

> >
> > > > > > > > Does anyone have the formula to create a button on your work sheet that upon
> > > > > > > > clicking on it will give you a result?

> >
> > > > > > > > ie. dice rolls, I would click on the button and the dice will roll.

> >
> > > > > > > > Thanks.

> >
> > > > > > > Mark, button can be made but only button can't make things roll.. U can
> > > > > > > internally rite some vb code/macro to make things happen and then u
> > > > > > > need to attach the click of this button to this macro. Otherwise u can
> > > > > > > insert control buttons and on click of these buttons u can write the
> > > > > > > corresponding code- Hide quoted text -

> >
> > > > > > - Show quoted text -

> >
> > > > > Mark, I am not sure what exactly is ur requirement. Do you want to
> > > > > display randomly picked values between 1,6 when you click a button?

> >
> > > > > If this is the case then, choose control toolbox and select the button
> > > > > and draw it on the worksheet. Right click on this button and slect
> > > > > view code.

> >
> > > > > On the code page, u see::::
> > > > > Private Sub CommandButton1_Click()

> >
> > > > > End Sub

> >
> > > > > Change this to::::::::::::::::::

> >
> > > > > Private Sub CommandButton1_Click()
> > > > > Dim rand_dice As Double
> > > > > rand_dice = Rnd()
> > > > > If rand_dice < 1 / 6 Then
> > > > > rand_dice = 1
> > > > > ElseIf rand_dice < 2 / 6 Then
> > > > > rand_dice = 2
> > > > > ElseIf rand_dice < 3 / 6 Then
> > > > > rand_dice = 3
> > > > > ElseIf rand_dice < 4 / 6 Then
> > > > > rand_dice = 4
> > > > > ElseIf rand_dice < 5 / 6 Then
> > > > > rand_dice = 5
> > > > > Else
> > > > > rand_dice = 6
> > > > > End If

> >
> > > > > MsgBox rand_dice

> >
> > > > > End Sub- Hide quoted text -

> >
> > > > - Show quoted text -

> >
> > > Mark, just to make things better, please add randomize prior to the
> > > call to Rnd(). So the new code will be ------

> >
> > > Private Sub CommandButton1_Click()
> > > Dim rand_dice As Double
> > > randomize
> > > rand_dice = Rnd()
> > > If rand_dice < 1 / 6 Then
> > > rand_dice = 1
> > > ElseIf rand_dice < 2 / 6 Then
> > > rand_dice = 2
> > > ElseIf rand_dice < 3 / 6 Then
> > > rand_dice = 3
> > > ElseIf rand_dice < 4 / 6 Then
> > > rand_dice = 4
> > > ElseIf rand_dice < 5 / 6 Then
> > > rand_dice = 5
> > > Else
> > > rand_dice = 6
> > > End If

> >
> > > MsgBox rand_dice

> >
> > > End Sub

> >
> > > The randomize ensures that a new seed is taken each time.

> >
> > > Glad to help.- Hide quoted text -

> >
> > - Show quoted text -

>
> Dude, you can do watever u like (well not all things u can think of,
> but majority of them) with the number.
>
> as u have the number in the variable rand_dice, if you want to display
> it in say A1 then replace the msgbox line with:
>
> Sheets(1).Range("A1").value = rand_dice
>
> and u will get the value in A1 of the 1st sheet of the workbook...
>
> Cheers!
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a Button that is type="button" and does not call __doPostBack Nathan Sokalski Microsoft ASP .NET 1 11th Jan 2010 03:57 PM
Creating a button =?Utf-8?B?cGFwcGF6?= Microsoft Excel Programming 2 3rd Mar 2007 12:38 AM
RE: Creating a button =?Utf-8?B?VG9tIE9naWx2eQ==?= Microsoft Excel Programming 1 2nd Mar 2007 11:24 PM
Creating Command Bar Button/Poppu like the 'Send' button =?Utf-8?B?Qkc=?= Microsoft Outlook VBA Programming 0 21st Sep 2004 11:41 PM
Creating Command Bar Button/Poppu like the 'Send' button =?Utf-8?B?Qkc=?= Microsoft Outlook Program Addins 0 21st Sep 2004 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:55 AM.