| View previous topic :: View next topic |
| Author |
Message |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Sun Nov 11, 2007 10:23 am Post subject: VB6 Variable Testing Help |
|
|
Ok, I'm trying to make a variable tester which tests if a variable exists or not in a certain flash game. So the user types in a variable such as _root.score and presses the button which checks if it's real. Then it has a message popping up saying if it finds it or not.
I tried looking on the internet but couldn't find anything useful
My junk code:
| Code: | Private Sub Command1_Click()
If flash1.GetVariable(Text1.Text) Is Nothing Then
MsgBox ("Variable Not Found")
Else
MsgBox("Variable Found")
End If
End Sub |
I'm thinking my second line is wrong
Please help, I'm a noob at this -.-
|
|
| Back to top |
|
 |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Sun Nov 11, 2007 12:37 pm Post subject: |
|
|
| Code: | Private Sub cmdTestVar_Click()
On Error GoTo errorhandler
label1.Caption = General.game.GetVariable(txtVar.Text)
Exit Sub
errorhandler:
MsgBox "The variable doesnt exist!", vbInformation, txtVar.Text
End Sub |
|
|
| Back to top |
|
 |
Blader I post too much
Reputation: 2
Joined: 19 Jan 2007 Posts: 2049
|
Posted: Sun Nov 11, 2007 12:41 pm Post subject: |
|
|
Thanks
So I replace general.game with my shockwave name right?
Trying...
EDIT: It works!
Thanks again =)
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Nov 11, 2007 1:28 pm Post subject: |
|
|
Just a suggestion, you could setup the function to pass the object, the variable, a pointer to the return variable storage, and have the function also return true or false for more 'error' checking.
Something like this:
| Code: | Private Function CheckVariable(swObj As ShockwaveFlash, strVariable As String, ByRef valPtr As Variant) As Boolean
On Error GoTo ErrorHandle
Dim vValue As Variant
vValue = swObj.GetVariable(strVariable)
valPtr = vValue
CheckVariable = True
Exit Function
ErrorHandle:
CheckVariable = False
End Function |
An example use for Dragon Fable would be:
| Code: | Private Sub Command1_Click()
Dim bVariable As Boolean
Dim lngVarValue As Long
bVariable = CheckVariable(ShockwaveFlash1, "_root.character.intGold", lngVarValue)
If bVariable = True Then
MsgBox "Variable exists! Value: " & lngVarValue
Else
MsgBox "Variable didn't exist."
End If
End Sub |
_________________
- Retired. |
|
| Back to top |
|
 |
|