Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Tuesday, September 13, 2011

How to Declare Variables As a Form In VBA


Microsoft Visual Basic for Application (VBA) controls use variables to store temporary information in the Access procedures, Word modules or Excel workbooks during the application execution. You need to use the word "Dim" (Dimension) followed by the chosen variable name and the word "As" followed by the variable type in order to declare a VBA variable. The VBA control variables represent a control on a form, report or section within another control. By declaring a variable as a form, you can reuse the existing VBA control objects.

Instructions

    • 1
      Click the "Start" button in Windows and select "Microsoft Office" and then "Microsoft Visual Basic for Applications."
    • 2
      Enter the following code in the window:
      Dim order As Form
      DoCmd.OpenForm "Customers"
      Set order = Forms!Customers
      Form_Customers.Visible = True
      Form_Customers.Caption = "New Customers"
    • 3
      Click "File" and "Save" to save the VBA script with the "order" form variable.

Variable Number Types in VBA


VBA is the programming language that enables a person to customize Microsoft Office products to suit specific and individual needs. Visual Basic for Applications comes standard within the Microsoft Office Suite of products. It's used in Excel to create graphs or perform repeat calculations, and is used in Word, PowerPoint and others to customize formatting or prompt users before performing an action. Within the VBA language, number types include bytes, singles, doubles, integers, currency and dates.
  1. Bytes, Singles and Doubles

    • A byte Is a positive number that ranges from 0 to 255. When working with applications where you know any calculations will not result in any number larger than 255, declaring your number variable type as a byte will be OK. Bytes represent 1 space for each number in memory. Singles represent 2 storage spaces in memory and have a range from approximately -3.4 to -1.4 and from 1.4 to 3.4. If you know the results of your calculations or items you are referencing will not fall outside of these ranges, then use the single number type. Doubles hold longer decimal points within memory and range approximately from -1.79 to -4.9 or from 1.79 to 4.9.

    Integer

    • The integer number type represents 2 spaces in memory and will hold whole numbers ranging from -32,767 to 32,767. This number type is helpful for rounding off calculations or creating forms that only are in need of whole numbers within this specified range.

    Currency

    • The currency number type is used when performing calculations involving money or calculations where there is a need for specified accuracy. The range on this number type is approximately from -900 trillion to 900 trillion. Using the currency number type has a wider range than the rest of the number types and will prevent accidental errors in coding by allowing enough room for the calculation result to display and to be stored.

    Date

    • The date number types represents 8 spaces in memory storage. It stores dates and times as a "real" number in the format of "DATE.TIME." The way the date format is displayed can also be customized to display "dd/mm/year" or "dd/mm/time" and others.

Saturday, September 3, 2011

How to Make a Batch File



A batch file is a MS-DOS, OS/2 and Windows text file that is edited by a user with commands that are run each time the file is run. The file can run a sequence of commands and are typically used to run repetitive processes automatically. The file extension for MS-DOS is .bat, and for Windows 9x, it is .bat. The commands are interpreted line by line and are executed as they are written in the file. The file can be written in any text editor, such as Notepad in Windows





Instructions



MS-DOS



1

Open a command window. In the command line, type the "edit" command followed by filename.bat then press enter. "Filename" is your chosen name of the new batch file. This will open the blue edit screen. For example: "edit test.bat" creates a batch file called "test" and allows you to edit the file. Enter the line without the quotation marks.



2

Enter the commands you want the batch file to run when it is executed, one command per line. For example:



@echo off

echo Hello

Pause

@echo on



This code displays the word "Hello" until the user presses a key, then terminates.



3

Click "File" then "Exit" once you have finished. When the program asks whether or not to save the file, click "Yes."



4

Type the batch file's name into the command line then press "Enter." If the file has been created correctly then the instructions within the file will be executed.



Windows



1

Click the "Start" button on the Windows taskbar. Go to your program files list, find and open Notepad. Alternatively, you may click "Start," then click "Run" then type "notepad" into the command line and press "Enter."



2

Type the instructions you wish the file to execute each time it is run. For example:



@echo off

echo Hello

Pause

@echo on



This code displays the word "Hello" then waits for a user to press a key, then terminates.



3

Click "File" then click "Save as" from the drop-down menu. Choose the location where you want to save the file.



4

Click "All Files" from the "Save as type:" box. Enter a file name for the file then click the "Save" button. Put a ".bat" at the end of the file name.



5

Double-click the file's icon or type the file name into the "Run" command line in the "Start" menu to test the file.