Results 1 to 18 of 18

Thread: [RESOLVED] Check the value of a Variable then take some action

  1. #1

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    Resolved [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.

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  3. #3
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    813

    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

  4. #4
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    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

  5. #5

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    Re: Check the value of a Variable then take some action

    Quote Originally Posted by ColinE66 View Post
    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

  6. #6
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    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

  7. #7
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  8. #8

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    Re: Check the value of a Variable then take some action

    Quote Originally Posted by ColinE66 View Post
    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

  9. #9
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    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

  10. #10

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    Re: Check the value of a Variable then take some action

    Quote Originally Posted by ColinE66 View Post
    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.

  11. #11
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    Re: Check the value of a Variable then take some action

    I see. Good luck :-)
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  12. #12
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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.
    Doctor Ed

  13. #13
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    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

  15. #15
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,272

    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

  16. #16
    Lively Member
    Join Date
    Apr 2011
    Posts
    75

    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

  17. #17

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    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 !


    Quote Originally Posted by geek648 View Post
    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.

  18. #18

    Thread Starter
    Lively Member MaxRaceSoftware's Avatar
    Join Date
    Feb 2007
    Posts
    83

    Re: Check the value of a Variable then take some action

    Quote Originally Posted by Bonnie West View Post
    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
  •  



Click Here to Expand Forum to Full Width