AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

AutoLisp Message Box.

Message Box

This library of AutoLisp Functions closely emulates the Visual Basic Message Box Function. It will display 5 different types of message boxes and allows you to enter 3 text message lines and customise the Message Box title.
The message boxes available are :

  • Ok Only
  • Ok Cancel
  • Rentry Cancel
  • Yes No
  • Yes No Cancel

The syntax for usage is as follows:

	(function name "message1" "message2" "message3" "title")

For example:

	(lspokcancel "This is the first line" "This is the second line"
		     "This is the third line" "This is the title")

Here is a detailed explanation of each message box:


Ok Only.

Message Box

Syntax : (lspOkOnly "message1" "message2" "message3" "title")
This message box returns nothing as it is used to convey a message only


Ok Cancel.

Message Box

Syntax : (lspOkCancel "message1" "message2" "message3" "title")
This message box returns True if OK selected and nil if Cancel selected


Rentry Cancel.

Message Box

Syntax : (lspRentryCancel "message1" "message2" "message3" "title")
This message box returns True if Rentry selected and nil if Cancel selected


Yes No.

Message Box

Syntax : (lspYesNo "message1" "message2" "message3" "title")
This message box returns True if Yes selected and "F" if No selected


Yes No Cancel.

Message Box

Syntax : (lspYesNoCancel "message1" "message2" "message3" "title")
This message box returns True if Yes selected, "F" if No selected
and nil if Cancel selected.


Source Coding.

Here is the DCL Source Coding:

lspOkCancel : dialog {

	key = "main";

	: column {

	: text {
	key = "message1";
	       }

	: text {
	key = "message2";
	       }

	: text {
	key = "message3";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "OK";
	key = "accept";
	width = 12;
	fixed_width = true;
	mnemonic = "O";
	is_default = true;
	}

	: button {
	label = "Cancel";
	key = "cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////////

lspYesNo : dialog {

	key = "main";

	: column {

	: text {
	key = "message1";
	       }

	: text {
	key = "message2";
	       }

	: text {
	key = "message3";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "Yes";
	key = "yes";
	width = 12;
	fixed_width = true;
	mnemonic = "Y";
	is_default = true;
	}

	: button {
	label = "No";
	key = "no";
	width = 12;
	fixed_width = true;
	mnemonic = "N";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////

lspOkOnly : dialog {

	key = "main";

	: column {

	: text {
	key = "message1";
	       }

	: text {
	key = "message2";
	       }

	: text {
	key = "message3";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "OK";
	key = "accept";
	width = 12;
	fixed_width = true;
	mnemonic = "O";
	is_default = true;
	alignment = centered;
	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////////

lspYesNoCancel : dialog {

	key = "main";

	: column {

	: text {
	key = "message1";
	       }

	: text {
	key = "message2";
	       }

	: text {
	key = "message3";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "Yes";
	key = "yes";
	width = 12;
	fixed_width = true;
	mnemonic = "Y";
	is_default = true;
	}

	: button {
	label = "No";
	key = "no";
	width = 12;
	fixed_width = true;
	mnemonic = "N";
  	}

	: button {
	label = "Cancel";
	key = "cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////

lspRentryCancel : dialog {

	key = "main";

	: column {

	: text {
	key = "message1";
	       }

	: text {
	key = "message2";
	       }

	: text {
	key = "message3";
	       }
	}
   	: row {

	: spacer { width = 1; }

	: button {
	label = "Rentry";
	key = "rentry";
	width = 12;
	fixed_width = true;
	mnemonic = "R";
	is_default = true;
	}

	: button {
	label = "Cancel";
	key = "Cancel";
	width = 12;
	fixed_width = true;
	mnemonic = "C";
	is_cancel = true;
  	}

	: spacer { width = 1;}

	}

  		 }

////////////////////////////////////////////

And the Autolisp Code:
(defun lspOkCancel (message1 message2 message3 main)

  (setq dcl_id (load_dialog "msgbox.dcl"))
  (if (not (new_dialog "lspOkCancel" dcl_id))
    (exit)
  )

  (set_tile "message1" message1)
  (set_tile "message2" message2)
  (set_tile "message3" message3)
  (set_tile "main" main)

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  (action_tile
    "accept"
    "(done_dialog)
     (setq result T)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun lspYesNo (message1 message2 message3 main)

  (setq dcl_id (load_dialog "msgbox.dcl"))
  (if (not (new_dialog "lspYesNo" dcl_id))
    (exit)
  )

  (set_tile "message1" message1)
  (set_tile "message2" message2)
  (set_tile "message3" message3)
  (set_tile "main" main)

  (action_tile
    "no"
    "(done_dialog)
     (setq result \"F\")"
  )
  (action_tile
    "yes"
    "(done_dialog)
     (setq result T)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun lspOkOnly (message1 message2 message3 main)

  (setq dcl_id (load_dialog "msgbox.dcl"))
  (if (not (new_dialog "lspOkOnly" dcl_id))
    (exit)
  )

  (set_tile "message1" message1)
  (set_tile "message2" message2)
  (set_tile "message3" message3)
  (set_tile "main" main)

  
  (action_tile
    "yes"
    "(done_dialog)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun lspYesNoCancel (message1 message2 message3 main)

  (setq dcl_id (load_dialog "msgbox.dcl"))
  (if (not (new_dialog "lspYesNoCancel" dcl_id))
    (exit)
  )

  (set_tile "message1" message1)
  (set_tile "message2" message2)
  (set_tile "message3" message3)
  (set_tile "main" main)

  (action_tile
    "no"
    "(done_dialog)
     (setq result \"F\")"
  )
  (action_tile
    "yes"
    "(done_dialog)
     (setq result T)"
  )
  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun lspRentryCancel (message1 message2 message3 main)

  (setq dcl_id (load_dialog "msgbox.dcl"))
  (if (not (new_dialog "lspRentryCancel" dcl_id))
    (exit)
  )

  (set_tile "message1" message1)
  (set_tile "message2" message2)
  (set_tile "message3" message3)
  (set_tile "main" main)

  (action_tile
    "cancel"
    "(done_dialog)
     (setq result nil)"
  )
  (action_tile
    "rentry"
    "(done_dialog)
     (setq result T)"
  )
  (start_dialog)
  (unload_dialog dcl_id)
  (princ)
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(princ)

If you would like the source coding for the the Message Box routine, just
place your mouse here, and click....Enjoy.

 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website