Tuesday, November 4, 2008

Javascript Image

Following JS shows how to use images. An image can be picked from a website or from local drive.
Size of image can be given either by width or height or both. It can be left or right aligned.
To get image from local drive, source can be specified as src="file:///C:/Ruchi/calcu.jpg"

< html>
< img width="100pix" align="left" border="0" alt="calculator"
src="http://www.understandingmoney.gov.au/image/calculator.GIF">
Calculate
< body>
< input type = "textarea" onchange="javascript:func(this.value)" / >
< input type = "button" value="Go"/>
< div id= "mydiv"> < /div>
< /body>
< script type ="text/javascript">

function func(a)
{
var ansr = eval(a);
var e = document.getElementById("mydiv");
e.innerHTML = "Answer : " + ansr;
}
< /script>
< /html>

Sunday, November 2, 2008

JavaScript Calculator

This script creates a simple calculator in browser.

<html>
Calculate
<body>
<input type="textarea" onchange="javascript:funky(this.value);" />
<div id="mydata"></div>
</body>
<script>
function funky(a)
{
var ansr = eval(a);
var e = document.getElementById("mydata");
e.innerHTML = "Result of expression : " + a + " is :" + ansr ;
}
</script>
</html>

Wednesday, September 3, 2008

Using Excel Functions in VBA - vlookup

Say we have a Sheet1 with following data :

COL A COL B
bat ball
cat mouse
zebra crossing

To look up content of COL B for a particular value of COL A, V for vertical Vlookup function can be used.

Sub func_vlookup()

Workbooks("workbookname.xls").Activate
Worksheets("Sheet1").Activate

findthis = "cat"
in_range = Range("A1:B3")
rtn_from_col# = 2 ' indicates from which column value is being returned

MsgBox WorksheetFunction.vlookup(findthis, in_range, rtn_from_col#)
'pops up "mouse"

End Sub

Match function can be written similarly. Try it!

Friday, August 29, 2008

Using Excel Functions in VBA - Sum

Sub function_sum()
x = 2
y = 3
some = WorksheetFunction.Sum(x, y)
End Sub

Try to modify code to
1) Display the numbers being added and the sum.
2) Get numbers as user input and sum them up.

Find out how is concatenation done in VBA. It has already been used in previous examples.



Wednesday, August 27, 2008

Get Last Used Row

Sub get_last_used_row()
' to get the last non-blank row

LastRow1 = Cells(Cells.Rows.Count, "A").End(xlUp).Row
'this is the keyboard equivalent of selecting a range using shift and down arrow
'   Exercise What does "A" signify??

LastRow2 = UsedRange.Rows.Count

MsgBox "LastRow1 " & LastRow1
MsgBox "LastRow2 " & LastRow2

End Sub

Exercise - What is the difference between LastRow1 and LastRow2. Though they might give same results occasionally, the approach to get the last row is different. Find it out!


Tuesday, August 26, 2008

selcells

Sub selcells()
' this sub shows how to get a cell value
ActiveSheet.Select
cellval = Cells(1, "A")
MsgBox cellval
End Sub

Try writing a sub that copies value of A1 into B1 without use of an intermediate variable.

Monday, August 25, 2008

Select row, column

There are exercises too, today using what you learnt yesterday.


#1
Sub selrow()
ActiveSheet.Select
Range("A1:E1").Select
'exercise - add code to give message when row is selected
End Sub


#2
Sub selcol()
ActiveSheet.Select
Range("A1:A10").Select
'exercise - add code to give message when row is selected
End Sub


Also, if you have time, find out how you can select an entire column. In the above example, we're selecting just a small range.

Msgbox Inputbox

Open excel
Do Alt F11
Paste -

Sub pgmhello()

MsgBox "Hello"
' accept name from user
name1 = InputBox("Name Please")

' concatenate hello and user name
MsgBox "Hello" & name1

End Sub

Click green triangular button or PF5

Try it!