I am a drafter using autocad and I know a littttttle bit of VB6. We just happen to have it installed on our computers and I wanted to create an application that can do this:

  1. Takes the # input from text1 and text2 and waits for the user to hit "Ok" (command click)

  2. Upon clicking, the information from Text2 gets multiplied by 0.75, and the total sum is then compared to Text1 with a less than or equals to equation.

  3. the comparison then Decides if the sendkeys will say "G152B" or "CB152B" to Notepad

Without words i guess?...

text2.text * "0.75" = SUM (this is the part im not really entire sure how to do, variable maybe?)

text1 and text2 filled out by user, user hits ok

command1_click()
If Sum <= text1.text then
sendkeys "g152b" else
Sendkeys "cb152b"

Dani AI

Generated

Nice, this is an easy automation but there are a few practical gotchas worth calling out beyond the examples already posted by and .

First, validate and convert carefully. Trim the textbox text, reject clearly non-numeric input, then convert with a locale-aware routine. In VB6 CDbl follows the system locale; Val does not, so using the wrong converter will break if anyone types a comma as the decimal separator. Wrap conversions in error handling and give a clear message so drafters know what to fix.

Second, avoid floating-point surprises. If these numbers represent measurements or money, prefer fixed-point (VB6 Currency) or compare scaled integers (multiply both sides by 100 or 1000) so tiny binary rounding errors don’t flip the <= test. Decide up front how many decimal places you actually need and apply the same rounding on both values before comparing.

Third, SendKeys is fragile. It works for quick proofs but fails intermittently in real workflows if the target window doesn’t have focus. If you stay in VB6, start the target with Shell, then use AppActivate (with the Shell task id or exact window title) and wait a short loop (DoEvents/Sleep) until the window is active before sending keys. Use synchronous SendKeys where available so your app waits until keystrokes are processed. Also ensure you send the exact case required (use uppercase to avoid CapsLock confusion).

Finally, consider alternatives for reliability. If the goal is to control AutoCAD, embedding the check inside AutoLISP/VBA/.NET (as shows) is more robust than external SendKeys. For a small external helper, VB6 is fine if you add the validation, fixed-point comparison, and an activation/wait step before sending. Test with edge cases and a couple of users to catch locale and timing issues.

Recommended Answers

All 2 Replies

The first thing you need to do is to make sure that the content of both the textboxes are indeed numeric.
The function for that is called IsNumeric and returns a boolean value.

Second. In order to perform any calculations you need to convert the numeric strings in the textboxes. And because you are multiplying with a decimal value, you need to convert them into Double.

So.The calculation would look something like this.

Dim product As Double

If IsNumeric(textbox2.Text) = True Then
    product = CDbl(Val(textbox2.Text)) * 0.75

    If IsNumeric(textbox1.Text) = True Then
        If product <= CDbl(Val(textbox1.Text)) Then
            Shell "notepad", vbNormalFocus
            SendKeys "g152b"
        Else
            Shell "notepad", vbNormalFocus
            SendKeys "cb152b"
    End If
End If

If you need to limit the number of decimals this might produce you can use the Round() function.
product = Round(product, <number of decimals, 0 is default>)

Hi, I know you asked for something in vb6, but anyone who runs the code needs to install the VBA Enabler, so I wrote something in LiSP that could do the trick as well. If you make it an application, then anyone can run it, just send them the VLX.
The first bit is the lsp code. In the first line the word "ProgramName" can be changed to whatever you want to call your program.
In the 4th line (load_dialog) that would be the path to your dcl file. I use that when testing, but before you pick File > Make Application, you would comment that line and uncomment the line below it.

(prompt "Loading ProgramName  Enter 'compare' to start.")
(defun C:compare ()

 (setq dcl_id (load_dialog "N:\\__New LiSP programs\\daniweb\\compare.dcl")) ;comment this line when making an application
 ;(setq dcl_id (load_dialog "test.dcl")) ;uncomment when you make an application
 (if (not (new_dialog "compare" dcl_id) ) (exit)) ;should match the first line in dcl
 (mode_tile "input1" 0)
 (mode_tile "input2" 0)
 (action_tile "fileName" "(setq fileName $value)")
 (action_tile "input1" "(setq input1 $value)")
 (action_tile "input2" "(setq input2 $value)")
 (action_tile "accept" "(exit_Main)")
 (action_tile "cancel" "(done_dialog 0)")
 (setq next (start_dialog))
 (unload_dialog dcl_id)
 (if (= next 1)
  (progn
   (setq fnamePath (strcat (getvar "dwgprefix") fileName "." "txt"))
   (setq output (open fnamePath "w"))
   (if (<= (distof input2 2) (distof input1 2))
    (setq rtnVal "g152b")
    (setq rtnVal "cb152b")
   )
   (princ rtnVal output)
   (close output)
   (setq a1 (strcat fnamePath "\nHas been created."))
   (alert a1)
   (princ)
  )
 ) ;ends if next = 1
) ;ends program

(defun exit_main()
 (done_dialog 1)
) ;ends function

This is the DCL file that goes with the LiSP

compare : dialog {
    label = "Number Compare";
    :edit_box {
        key = "fileName";
            label = "Filename (prefix)";
        edit_width = 10;
        }
    :edit_box {
        key = "input1";
            label = "Enter first value:";
        edit_width = 10;
        }
    :edit_box {
        key = "input2";
            label = "Enter second value";
        edit_width = 10;
        }
    ok_cancel;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.