February, 2007

How to make and run Visual Basic programs from MS Excel or Word programs

Within Word or Excel there is a Visual Basic
Editor, together with tools, for writing Visual Basic programs and running
them. This brief note is aimed at showing how to get started and a little of
what is possible. It does not aspire to teach the ins and outs of how to
program in Visual Basic – there are plenty of books available on that.

The Visual Basic Editor is also present in MS
Access and Powerpoint.

Part A – getting started.

1. Start Excel.

2. On the task bar click Tools\Macro\Visual
Basic Editor. You will get the Visual Basic Editor containing a blank
worksheet.

3. On the task bar click on Insert\User Form.
You will get a form, called UserForm1, and a toolbox superimposed on the
worksheet. Drag the toolbox to one side.

4. Click on UserForm1 and drag the lower,
right hand corner to make the form larger.

5. In the toolbox click on the ‘ab’ icon (the
textbox icon) and then click on UserForm1 – a text box is dropped onto the
form, and its name is TextBox1. Move the textbox to the top left corner and
then drag the lower right corner to enlarge it.

6. In the toolbox click on the command button
icon (middle of the 2nd row) and then click on a free part of
UserForm1 – a command button is placed there, called CommandButton1.

7. Double click on the command button; you
will get a white form, or code window, with the following brace:

 

Private Sub CommandButton1_click()

 

End Sub

 

Between these two lines we write our program
code. As an example:

(a)

Private
Sub CommandButton1_click()

 

Line = Line + “Output is “

For j = 1 to 10

   Line = Line + Str(j)

Next j

TextBox1.Text = Line

 

End
Sub

(b)

Click on the taskbar Run\Run. The program runs and you get UserForm1
with the textbox and command button.

 

(c) Click the command button: the program executes and displays in the
textbox the expected

Output
is 1 2 3 4 5 6 7 8 9 10

 

(d) click the ‘x’ on the top right corner of
UserForm1 to stop the program.

Part B – running the ‘Make Values’ program.

1. Double click on the CommandButton1 to
bring up the code window. Delete the program we have just written in, but leave
the braces there. Paste in, or type in, the program ‘Make Values’ from the
Crypto Drop Box.

2. On the Task Bar click View\Project
Explorer and in the box that appears click on UserForm1 to get our form back.

3. On the Task Bar click on View\Properties
to get a small box called ‘Properties_TextBox1’. In this box

-
click ‘MultiLine’ and choose true

-
click Font and a small button will appear on the font line. Click this button
to get a dialogue box, in which choose Courier New and size 10.

4. Now click Run\Run to run the program and
click CommandButton1.

5. The program will create indices for each
of the three words STUBTOES, FOURDOOR and DUOAORBB. Then from the perm
5089721463 the values of the three words will be
calculated. Finally the program displays all this data as follows:

 

word(0) = STUBTOES

word(1) = FOURDOOR

word(2) = DUOAORBB

 

derived alpha=STUBOEFRDA

 

index(0)= 0 1 2 3 1 4 5 0

index(1)= 6 4 2 7 8 4 4 7

index(2)= 8 2 4 9 4 7 3 3

 

if perm = 5 0 8 9 7 2 1 4 6 3

 

value(0) = 50890725

value(1) = 17846774

value(2) = 68737499

Part C – running the ‘Make Perms’ program.

Proceed as described above.

The program will display all the perms for 5
digits. Perms for a different number of digits (say 8) can be displayed by
changing the 6th line in the program to

 

length = 8

 

To solve an addition cryptarithm this program
would be combined with the ‘Make Values’ program and the display section
adjusted to show the solution rather than all the perms.

Part D – conclusion.

I am indebted to photon for pointing out to
me that Word and Excel contain this hidden nugget of Visual basic.

This little introduction is to help you get
started. Computer solving programs, such as BION and I describe in our columns,
are just one type to work on. Equally rewarding are interactive programs that
take the labour out of pencil and paper work, and leave you to solve with your
own initiative rather than the computer’s muscle. photon is an arch-exponent of
this art.

Help is available from the Visual Basic Editor
taskbar, from the MS Visual Basic web site and from numerous manuals.

squid.conf

Squid_1

http_port 3128 8080
icp_port 3130

hierarchy_stoplist cgi-bin ? % = + asp jsp php exe  phtml xml jhtml cgi pl dll
acl QUERYWWN urlpath_regex -i swf\? jpg\? gif\? Compose\? ad\? html\? fpl\?
acl QUERY urlpath_regex cgi-bin \?
#no_cache allow QUERYWWN
no_cache deny QUERY
cache_mem 6 MB
cache_swap_low 75
cache_swap_high 95
maximum_object_size 128 MB
minimum_object_size 0 KB
maximum_object_size_in_memory 32 KB
ipcache_size 8192
ipcache_low 95
ipcache_high 99
fqdncache_size 8192
query_icmp on
redirect_program /usr/local/adzap/scripts/wrapzap
redirect_program /usr/local/squirm/bin/squirm

redirect_children 20
pipeline_prefetch on

cache_effective_user nobody
cache_effective_group nogroup

cache_replacement_policy heap LFUDA
memory_replacement_policy heap GDSF
forwarded_for off

acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl purge method PURGE
acl SSL_ports port 443 563
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443 563     # https, snews
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
acl yahoo urlpath_regex yahoo
acl trading urlpath_regex trading
acl detik urlpath_regex detik

acl WIFI src 10.10.20.0/255.255.255.0
acl WARNET src 192.168.10.0/255.255.255.0
acl as_iix dst_as 4434 4622 4761 4787 4795 4800 4821 4832 4833 4855 7713 9251 9326 9340 9341 9448 9462 9875 9905 10137 10217 10220 10530 11919 17440 17451 17658 17671 17727 17826 17885 17910 17922 17988 17996 18004 18052 18059 18153 18156 18189 18347 18364 18393 18394 23691


http_access allow manager
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow purge
http_access deny purge
#http_access allow https
http_access allow WIFI
http_access allow WARNET
http_access allow localhost
http_access deny all

icp_access allow WIFI
icp_access allow WARNET
icp_access deny all

always_direct allow yahoo
always_direct allow trading
always_direct allow detik
always_direct deny all

cache_dir diskd /cache1 4500 64 384 Q1=64 Q2=72
cache_dir diskd /cache2 4500 64 384 Q1=64 Q2=72
cache_dir diskd /cache3 4500 64 384 Q1=64 Q2=72
cache_dir diskd /cache4 4500 64 384 Q1=64 Q2=72
cache_dir diskd /cache5 4500 64 384 Q1=64 Q2=72
cache_dir diskd /cache6 4500 64 384 Q1=64 Q2=72

store_dir_select_algorithm least-load
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
pid_filename /var/log/squid/squid.pid
cache_store_log none

#########################################
########External Functions###############
#########################################
ftp_user squid@sarkem.net
ftp_passive on
ftp_sanitycheck on
dns_nameservers 202.155.0.10 202.155.0.15 202.155.0.20

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
half_closed_clients off

log_fqdn off
always_direct deny all
never_direct allow yahoo

refresh_pattern ^ftp:// 1440 20% 10080
refresh_pattern ^gopher:// 1440 0% 1440
refresh_pattern /cgi-bin/ 60 70% 120
refresh_pattern . 0 20% 4320

icp_hit_stale on
range_offset_limit 4096 KB
visible_hostname djakarta.javamedia.net.id
quick_abort_min 16 KB
quick_abort_max 128 KB
quick_abort_pct 85

#quick_abort_min 0
#quick_abort_max 0
#quick_abort_pct 98

dns_retransmit_interval 5 seconds
dns_timeout 5 minutes

negative_ttl 5 minutes
positive_dns_ttl 6 hours
negative_dns_ttl 5 minutes
cache_mgr admin@sarkem.net
ie_refresh on

############################################
###########  DELAY POOLS  ##################
############################################
#This is the most important part for shaping incoming traffic with Squid
#For detailed description see squid.conf file or docs at http://www.squid-cache.org

#We don’t want to limit downloads on our local network.

###acl magic_words1 url_regex -i 192.168

#We want to limit downloads of these type of files
#Put this all in one line

acl magic_words2 url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .rpm .zip .rar .avi .mpeg .mpe .mpg .qt .ram .rm .iso .raw .wav .mov .cab .swf .rhz .dat .hlp

#We don’t block .html, .gif, .jpg and similar files, because they
#generally don’t consume much bandwidth

#We want to limit bandwidth during the day, and allow
#full bandwidth during the night
#Caution! with the acl below your downloads are likely to break
#at 23:59. Read the FAQ in this bandwidth if you want to avoid it.

#acl day time 09:00-23:59

#We have two different delay_pools
#View Squid documentation to get familiar
#with delay_pools and delay_class.

#delay_pools 2

###########################################
##########First delay pool#################
###########################################

#We don’t want to delay our local traffic.
#There are three pool classes; here we will deal only with the second.
#First delay class (1) of second type (2).

#delay_class 1 2

#-1/-1 mean that there are no limits.

###delay_parameters 1 -1/-1 -1/-1

#delay_parameters 1 1000/64000 #semua network mendapat bandwidth sama di pool no 1. Sebesar 1 kbytes/sec (8 kbits/sec), dengan burstable file 64 kb.
#delay_parameters 1 32000/32000 1000/64000 #squid akan memakai bandwidth maksimum (32000*8) 256kbits dari semua bandwidth.
##delay_parameters 1 32000/32000 8000/8000 1000/64000 #setiap network akan dipaksa maksimum sebesar (8000*8) 64 kbits/sec

#magic_words1: 192.168 we have set before

#delay_access 1 allow magic_words1
#delay_access 1 allow day
#delay_access 1 deny !day

##############################
incoming_icp_average 3
incoming_http_average 2
incoming_dns_average 3
min_icp_poll_cnt 8
min_dns_poll_cnt 6
min_http_poll_cnt 6
#############################

#######################################################################
#######################################################################
#################      Second delay pool.   ###########################
#######################################################################

#we want to delay downloading files mentioned in magic_words2.
#Second delay class (2) of second type (2).

#delay_class 2 2

#The numbers here are values in bytes;
#we must remember that Squid doesn’t consider start/stop bits
#5000/150000 are values for the whole network
#5000/120000 are values for the single IP
#after downloaded files exceed about 150000 bytes,
#(or even twice or three times as much)
#they will continue to download at about 5000 bytes/s

#delay_parameters 2 5000/150000 5000/120000

#We have set day to 09:00-23:59 before.

#delay_access 2 allow day
#delay_access 2 deny !day
#delay_access 2 allow magic_words2

###################################################
##########  Tuning Squid Cache ####################
###################################################
wais_relay_host localhost
wais_relay_port 8000

request_header_max_size 10 KB
#request_body_max_size 1 MB
request_body_max_size 0 MB

range_offset_limit 17 MB
#connect_timeout 120 seconds
connect_timeout 180 seconds

read_timeout 10 minutes
#siteselect_timeout 4 seconds
request_timeout 30 seconds
pconn_timeout 180 seconds
peer_connect_timeout 60 seconds
persistent_request_timeout 1 minute
client_lifetime 1000 minutes
half_closed_clients off
reload_into_ims on
acl iix dst 202.0.0.0/8 203.0.0.0/8 # by pass IIX
always_direct allow iix
always_direct deny all 
offline_mode on

http_port 80 202.155.2.153
acl port80 port 80
http_access allow port80
always_direct allow all

shutdown_lifetime 10 seconds
memory_pools off

#acl blocksites dstdomain sex.com
#acl blocksites dstdomain .lalatx.com
#acl blocksites dstdomain .uh-oh.com
#acl blocksites dstdomain .playboy.com
#http_access deny blocksites

#acl blockdomains dstdomain "/etc/squid/blacklist/antidomain"
#http_access deny blockdomains
#acl deniedsites url_regex "/etc/squid/blacklist/antiurl"
#http_access deny deniedsites