Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Reaper~ on December 23, 2004, 10:21 AM

Title: Add bet to winnings
Post by: Reaper~ on December 23, 2004, 10:21 AM

If frmAccount.lblWinning1.Caption = "$500" Then
Val (lblWinning1.Caption) + Val(txtBet.Text)
End If

If frmAcount.lblWinning1.Caption = "$300" Then
Val (lblWinning1.Caption) + Val(txtBet.Text)
End If

I tried that but I get a runtime error saying Object Required and it highlights


If frmAcount.lblWinning1.Caption = "$300" Then

Title: Re: Add bet to winnings
Post by: Hdx on December 23, 2004, 10:24 AM
frmAcount.lblWinning1.Caption
Is that an object? a valid one?
And please keep all your help requests in one thread >.<
~-~(HDX)~-~
Title: Re: Add bet to winnings
Post by: Reaper~ on December 23, 2004, 10:41 AM
Quote from: HdxBmx27 on December 23, 2004, 10:24 AM
frmAcount.lblWinning1.Caption
Is that an object? a valid one?
And please keep all your help requests in one thread >.<
~-~(HDX)~-~

Guess not, but what would be the way to add it under one of the winning procedures?

Something like...

ElseIf (Val(txtNumber.Text) <= Val(lblNumber.Caption) + 5) And (Val(txtNumber.Text) >= Val(lblNumber.Caption) - 5) Then
MsgBox ("5 Away! $300 has been sent to your account!")
frmAccount.lblWinning1.Caption = "$300"
Val(frmAccount.lblWinning1.Caption) = Val(txtBet.Text) + "$300"

?
Title: Re: Add bet to winnings
Post by: NicoQwertyu on December 23, 2004, 01:11 PM
Quote from: Reaper~ on December 23, 2004, 10:41 AM

frmAccount.lblWinning1.Caption = "$300"
Val(frmAccount.lblWinning1.Caption) = Val(txtBet.Text) + "$300"


There's a couple wierd things going on with that code.

Val(frmAccount.lblWinning1.Caption)
Val(txtBet.Text)


1.) Val() will always return 0 because it's including the dollar sign "$".
1a.) Fix it by leaving the first character of the caption out when calling Val.
1b.) Don't know how to do that? Google string manipulation in VB6.


Val(txtBet.Text) + "$300"


2.) Why are you trying to do numerical addition using a string?
Title: Re: Add bet to winnings
Post by: Reaper~ on December 23, 2004, 03:02 PM
Thanks for the tip on the dollarsign and I got it what I wanted to work by adding:

Public Function GetBet()
GetBet = Val(txtBet.Text)
End Function

Then I put 'GetBet' under..

frmAccount.lblWinning1.Caption = "$300" + GetBet

So, now it works :D
All I have to do is add a seperate dollarsign next to where the amount would go in frmAccount...
Title: Re: Add bet to winnings
Post by: Grok on December 24, 2004, 03:40 AM
Actually, it looks like what was wrong with the original code was spelling of frmAccount.
Title: Re: Add bet to winnings
Post by: Stealth on December 24, 2004, 12:18 PM
Use Option Explicit to avoid that happening again, and remember, the Tab key is your friend. :)
Title: Re: Add bet to winnings
Post by: R.a.B.B.i.T on December 24, 2004, 03:41 PM
So are variables.