im doing a deal or no deal game, i have managed to get the values to randomly appear and be associated with the buttons with duplicates.
my next stage i have got to get the bankers offer, by getting an average to appear from all the buttons currently showing(once they are clicked i need them to hide, and then not be included in the calculation for the offer).
With regards to getting the text on the button into an integer, how do i do this? and once done that, can i make the calculation only include the buttons currently showing??
I thought would be easiest to attach my recent updated code also.
To access only those buttons which are visible, use something like this;
Code:
For Each ctl As Control In Me.Controls
If ctl.GetType.ToString.ToLower = "system.windows.forms.button" Then
If ctl.Visible Then
'do stuff
End If
End If
Next
To safely get an integer from button text use;
Code:
Dim i As Integer
If Integer.TryParse(Button1.Text, i) Then
'Button text is an integer with value i
End If
thanks I didnt use that exact code, but it inspired me to get some over code.
I currently have:
Code:
Dim J As Integer
Dim Total As Double
Dim VisibleCount As Integer
Dim BankersOffer As String
Dim Sym As String
For J = 0 To btn.Count - 1
If btn(J).Visible = True Then
Total = Total + CDbl(btn(J).Text)
VisibleCount = VisibleCount + 1
End If
Next
BankersOffer = (Total / VisibleCount)
Sym = ("£")
Dim Offer As String = String.Concat(Sym, BankersOffer)
Me.lblArv.Text = CStr(Offer)
End Sub
which works fine, however the final offer im displaying had many decimal places. i need it not to have any, how do i add a formatting bit? im using visual studio, is it in the properties of the label im displaying on, or is this more coding i need to do?
Last edited by jason1987; Apr 14th, 2007 at 05:38 AM.
That formats the result of the calculation as a currency string (that's the "c") with no decimal places (that's the "0") and assigns the result to the Text property of the Label.
wow, thankyou very much, looks exactly how i want it now, i was never aware of the currency function. thanks
Thanks very much, that has sorted that issue out.
I now need to make a picture box appear with the same tag as the box that is clicked.
for example I have a button with the tag 0.01 and now picturebox1 with the tag 0.01 also.
How will i code this as it will be a different button each time with the 0.01 tag
I have 22 different tagged buttons and 22 different tagged picture boxs which im using to cover up something on my background when the button with the same tag is clicked