1 / 20

Internal Functions

Internal Functions. Integer Functions. Converting to Integers Function Result Explanation x=Int(6.5) 6 Rounds Down x=Int(-6.5) -7 x=Fix(6.5) 6 Truncates at Decimal x=Cint(6.5) 7 Changes to Integer x=Cint(-6.5) -6 x=Round(6.5) 7 .5 rounds up . Some Math Functions.

dschooley
Download Presentation

Internal Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Internal Functions

  2. Integer Functions Converting to Integers Function Result Explanation x=Int(6.5) 6 Rounds Down x=Int(-6.5) -7 x=Fix(6.5) 6 Truncates at Decimal x=Cint(6.5) 7 Changes to Integer x=Cint(-6.5) -6 x=Round(6.5) 7 .5 rounds up

  3. Some Math Functions Abs(intAge1 - intAge2) Absolute Value Sqr(144) Square Root Exp(10) Natural Log^e Log(10) Natural Log.

  4. Trig Functions • print sin(90 * 3.1415926/180) • sngArc= atn(90 * 3.1415926/180) • x=cos (90 * 3.1415926/180) • y=sin(90 * 3.1415926/180) • myTan=tan(90 * 3.1415926/180) You must convert to radians. Aaaargh. maybe a constant or making a function would be handy • cRads = 3.1415926/180 x=cos(90 * cRads) • y=sin(ToRadians(90))

  5. Data Type Functions • IsDate(x) Can convert to a Date • IsEmpty(x) Never Initialized • IsNull(x) Holds Null Value • IsNumeric(x) Can convert to a Number • VarType(x) Returns number for type of variable

  6. Shortcut Functions • Iif • StrChoice=Iif(intCondition =1, “yes”, “no”) • Choose • StrChoice=Choose(intNumber, “one”, “two”, “three”, “four”)

  7. Data Conversion converts Data From one type to another • blnYesNo = Cbool(intNumber) • Cbyte() • Ccur() • Cdate() • CDbl() • Cdec()

  8. CBool() CByte() CCur() CDate() CDbl() CDec() CInt() CLng() CStr() CVar() Common - CInt and CStr Data Conversion converts Data From one type to another blnYesNo = Cbool(intNumber)

  9. String Functions • Len(“Kevin”) 5 • CStr(1) “1” • Str(1) “ 1” • Str(-1) “-1” • Val(“1”) 1

  10. Ascii Functions • Chr(13) return line • Chr(65) “A” • Useful for multilingual functions and characters not on keyboard. • Asc(“A”) 65

  11. Substring Functions • Left(“Monkey”, 4) “Monk” • Right(“Monkey”, 3) “key” • Mid(“Monkey”, 2, 2) “on”(start at 2, for 2 characters) • Mid can be a command: strVehicle=“boat”Mid(strVehicle, 3,1) = “o”

  12. More String Functions • Ltrim(“ hello”) • Rtrim(“hello “) • Trim (“ hello “) • All return “hello” • Ltrim(“ hello “) returns what? • StrReverse(“Kevin”) returns “neviK”

  13. Dates and Times • Literals must be in the pound signs!#09/26/00# • The computer recognizes a lot of formats. • Date Short for Date(), etc. • Time • Now Date & Time

  14. Dealing with time • Timer returns number of seconds since midnight on your computers clock. • DateAdd(“yyyy”, 10, Now) adds 10 years. You can also add months (“m”) and 8 other intervals to any given date. • DateDiff(“m”, #01/01/80#, Now) • DatePart(“w”, #09/01/00#) produces 6, which stands for Friday. Sunday is 1.

  15. More on Dates • Used to make sure addition of dates is correct. • DateSerial(1988+intYears, 1+intMonths, 1+intDays) • DateSerial(2000, 9, 26+10) = 10/6/00 • DateSerial(2000, 9, 26+100) = 1/4/01 • DateValue(#September 26, 2000#)=9/26/00

  16. TimeSerial() and TimeValue() • Similar to DateSerial() and DateValue()

  17. Formatting • You can format your output. This is particularly useful for numbers. • You can indicate how many decimal places you wish to show, you can indicate phone numbers and zip codes. You can divide up long credit card numbers. You can do much more.

  18. Format(expression, format) • The format argument accepts the following for formatting strings: @ Makes sure a character or blank appears. & An available character appears. ! Forces filling a field from left to right. < Forces characters to lowercase > Forces characters to uppercase : Shows time colon / Shows date slashes There are also 23 date format indicators to indicate what part of the date you want and how you want it.

  19. Format(expression, format) • The format argument accepts the following for formatting numbers: no format No formatting 0 Forces digit to appear # available digit position . decimal position % multiply by 100, add “%” E+, E-, e+, e- Scientific Notation \ Show the next character -, +, $, space Shown as is

  20. Whew! • Reading Chapter 8 is necessary. If you understand the chapter you understand a large portion of Visual Basic. • As you read, experiment in the immediate window. • Don’t feel you have to memorize every function and detail.

More Related