|
-
Feb 1st, 2013, 05:58 AM
#1
Thread Starter
Lively Member
[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 ??
Last edited by MaxRaceSoftware; Feb 1st, 2013 at 06:03 AM.
-
Feb 1st, 2013, 06:12 AM
#2
Re: Check the value of a Variable then take some action
Code:
While X = 5
Exit Sub
Wend
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Feb 1st, 2013, 06:59 AM
#3
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
-
Feb 1st, 2013, 11:19 AM
#4
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
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Feb 1st, 2013, 12:28 PM
#5
Thread Starter
Lively Member
Re: Check the value of a Variable then take some action
 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 !
Bonnie West
While X = 5
Exit Sub
Wend
Bonnie West, will checkout your code also , thank you !
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
-
Feb 1st, 2013, 12:39 PM
#6
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!
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Feb 1st, 2013, 12:42 PM
#7
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
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Feb 1st, 2013, 12:44 PM
#8
Thread Starter
Lively Member
Re: Check the value of a Variable then take some action
 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
-
Feb 1st, 2013, 12:47 PM
#9
Re: Check the value of a Variable then take some action
If it's obfuscation you're after then probably, yes...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Feb 1st, 2013, 12:51 PM
#10
Thread Starter
Lively Member
Re: Check the value of a Variable then take some action
 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.
-
Feb 1st, 2013, 12:54 PM
#11
Re: Check the value of a Variable then take some action
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Feb 1st, 2013, 05:46 PM
#12
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.
-
Feb 1st, 2013, 06:13 PM
#13
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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Feb 1st, 2013, 06:47 PM
#14
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
-
Feb 1st, 2013, 06:58 PM
#15
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...
If you don't know where you're going, any road will take you there...
My VB6 love-children: Vee-Hive and Vee-Launcher
-
Feb 2nd, 2013, 05:20 AM
#16
Lively Member
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
-
Feb 2nd, 2013, 05:47 AM
#17
Thread Starter
Lively Member
Re: Check the value of a Variable then take some action
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 !
 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
Last edited by MaxRaceSoftware; Feb 2nd, 2013 at 05:54 AM.
-
Feb 2nd, 2013, 03:05 PM
#18
Thread Starter
Lively Member
Re: Check the value of a Variable then take some action
 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.
Last edited by MaxRaceSoftware; Feb 2nd, 2013 at 03:18 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|