[RESOLVED] Check the value of a Variable then take some action
How can i check the value of a Variable
then take some Action
without using IF THEN or Select Case
Typically ;
Lets say X = 5
IF X = 5 Then Exit Sub
however,
how can i know value of X
then take some action according to value of X
without using IF THEN or Select Case statements
is this possible ??
Re: Check the value of a Variable then take some action
Code:
While X = 5
Exit Sub
Wend
Re: Check the value of a Variable then take some action
So you want to test the value of a variable (i.e. a "Condition") without using an Conditional coding constructs? Why?
Whenever you find yourself asking "how" to do something outside the VB "box", take a step back and ask yourself "why?". It might be that it's legitimate and you really do have to break new ground (which is difficult and time-consuming); more often, there's a far easier soltion to be found elsewhere (which is quicker and cheaper).
Your example showed simple integer values, but if you're working with classes, then you might be able to do something like this:
Code:
[ Class1.cls ]
Public Sub Beep()
End Sub
[ Class2.cls ]
Public Sub Beep()
End Sub
[frmMain.frm]
Sub Form_Load()
Dim v1 as Variant
If ( ... ) Then
Set v1 = New Class1
Else
Set v1 = New Class2
End If
v1.Beep
End Sub
Re: Check the value of a Variable then take some action
This will work if x is always >0
Code:
Private Sub cmdCommand1_Click()
Dim iTestVal As Integer, x As Integer
Const FailValue = 5
On Error GoTo ExitPoint
x = 5 'substitute other values to test
iTestVal = 1 / (x Mod FailValue)
MsgBox "Got Here"
'other code here
Exit Sub
ExitPoint:
MsgBox "Booted"
End Sub
Re: Check the value of a Variable then take some action
Quote:
Originally Posted by
ColinE66
This will work if x is always >0
Code:
Private Sub cmdCommand1_Click()
Dim iTestVal As Integer, x As Integer
Const FailValue = 5
On Error GoTo ExitPoint
x = 5 'substitute other values to test
iTestVal = 1 / (x Mod FailValue)
MsgBox "Got Here"
'other code here
Exit Sub
ExitPoint:
MsgBox "Booted"
End Sub
ColinE66 , thank you very much, works great, its just what i was looking for !
Quote:
Bonnie West
While X = 5
Exit Sub
Wend
Bonnie West, will checkout your code also , thank you !
Quote:
Phill.W
Whenever you find yourself asking "how" to do something outside the VB "box",
take a step back and ask yourself "why?".
It might be that it's legitimate and you really do have to break new ground
i purchased a few VB Decompilers , and have been decompiling my programs
and IF THEN and SELECT CASE statements show up the same,
just looking for an unique way to prevent decompilation or make it harder for the average Hacker.
trying to hide inner working/code of a Registration routine
Re: Check the value of a Variable then take some action
Actually I was just playing - Bonnies code is much simpler and does the same thing!
Re: Check the value of a Variable then take some action
I wonder if this form of Select Case generates different machine code from If..Then:
Code:
Select Case True
Case X = 0: 'Do something
Case X = 1: 'Do something
Case X = 2: 'Do something
Case X = 3: 'Do something
Case X = 4: 'Do something
Case X = 5: 'Do something
Case Else: 'Do default
End Select
Re: Check the value of a Variable then take some action
Quote:
Originally Posted by
ColinE66
Actually I was just playing - Bonnies code is much simpler and does the same thing!
i need to checkout what both of your codes look like in decompilations ?
i think i can better use parts of your solution in my code
Re: Check the value of a Variable then take some action
If it's obfuscation you're after then probably, yes...
Re: Check the value of a Variable then take some action
Quote:
Originally Posted by
ColinE66
If it's obfuscation you're after then probably, yes...
obfuscation in .EXE , sometimes gets flagged as Virus by some AntiVirus softwares
just trying to create a simple, foolproof solution.
Re: Check the value of a Variable then take some action
Re: Check the value of a Variable then take some action
An alternative to Bonnie's code:
Code:
X = 5
Do While X = 5
Exit Sub
Loop
I recall getting criticized here for using While...Wend because it was supposedly considered archaic.
Re: Check the value of a Variable then take some action
@ Code Doc
I believe there's no point in optimizing that because the goal is to obfuscate. ;) That's why ColinE66's attempt is better in that respect. :)
Re: Check the value of a Variable then take some action
While that would work I have a hard time seeing any way that you could write any program that would be worth using without using lots of conditional constructs. The code would be huge and almost impossible to work with in most projects not to mention slow.
I also have yet to see a decompiler that decompile a VB6 exe to any thing other than ASM
Re: Check the value of a Variable then take some action
Maybe he only wants to use it in one part of his code? Say, for instance, the code that validates whether the user has a licensed copy of the program...
Re: Check the value of a Variable then take some action
Anyone that interested in hacking won't be put off by anything you can do :)
Write the registration stuff in another language that compiles to a standalone .exe you can shell out to (the free Lazarus/FreePascal springs to mind) - that'll confuse them for a bit :)
Re: Check the value of a Variable then take some action
Quote:
ColinE66
Maybe he only wants to use it in one part of his code? Say, for instance, the code that validates whether the user has a licensed copy of the program...
yes, that's what i'm doing !
Quote:
Originally Posted by
geek648
Anyone that interested in hacking won't be put off by anything you can do :)
Write the registration stuff in another language that compiles to a standalone .exe you can shell out to (the free Lazarus/FreePascal springs to mind) - that'll confuse them for a bit :)
"Write the registration stuff in another language that compiles to a standalone .exe "
i thought about doing that also a few years back....might eventually try it , that and using 2 .EXE's together
A lot of the Source Code in Forms shows up when decompiled !
its very important to place all your important or critical Code in .BAS Modules,
the Decompilers have a hard time decompiling BAS Modules correctly.
use Public variables and Constants to access in critical BAS Modules
then don't use Parameters in Subs in the BAS Modules that contain your most critical Code .
just Call that Sub in the BAS Module by its name without any parameters
the Decompilers can't "see" a plain empty Call from a Form to a Sub in a BAS Module
it does not show up in any decompilations
They can't even tell at what point in Form's Code you called that plain Sub without Parameters
the Form's Call code is completely hidden from them.
but if you have just one Parameter in a Sub in a BAS Module ... the Form Call shows up in decompilation
Re: Check the value of a Variable then take some action
Quote:
Originally Posted by
Bonnie West
I wonder if this form of Select Case generates different machine code from If..Then:
Code:
Select Case True
Case X = 0: 'Do something
Case X = 1: 'Do something
Case X = 2: 'Do something
Case X = 3: 'Do something
Case X = 4: 'Do something
Case X = 5: 'Do something
Case Else: 'Do default
End Select
all the Select Case statements are converted into IF THEN statements by Compiler
then Decompiler just sees IF THEN statements , no Select Cases
in decompilations
all you see are IF THEN's , DO While : LOOP , For Next
and all String's data
one more thing , if you use Class 's , all your Functions names show up,
making it easier to understand in decompilation.
if you use .BAS Module, original names of Subs do not show up
making it harder to understand in decompilation.
i'll mark Thread Resolved , thanks.