| Home | Family | Softwares | Resume | Activities |
1.
Input Function
Dim MyChar
Open "TESTFILE" For Input As
#1 ' Opens a file for reading
data
.
Do While Not
EOF(1)
' Loop until end of file
.
MyChar = Input(1,
#1)
' Get one character
.
Debug.Print
MyChar
' Print to the Immediate window
.
Loop
Close #1 ' Close file.
2
Input # Statement
Input #1, MyString, MyNumber ' Read data into two variables. Debug.Print MyString,
MyNumber
' Print data to the Immediate window.
3.
Line Input # Statement
'Reads a single line from an open sequential file
and assigns it to a String variable
.
Line Input #1,
TextLine
' Read line into variable .
Debug.Print
TextLine
' Print to the Immediate window.
'The following code opens the file TESTFILE in
sequential-input mode.
Open "TESTFILE" For Input As #1
'
Close before reopening in another mode.
Close #1
'This example opens the file in Binary mode for writing operations only.
Open "TESTFILE" For Binary Access Write As #1
' Close before reopening in another mode.
Close #1
To Add Components ListImage, Progress Bar etc.
1. Click On 1. projects. 2. Components 3. Browse 4. Select Following file "Comctl32.ocx" form C:\Winnt\System32
Automatically "Microsoft Windows Common Control 5-0(SP2) will be selected. Select Apply and close. New Active X controls will be added.
4.
To Escape character for Double Quotes "".
"ashish" " " ashish " "
5.
For Getting Variable Value in SQL Select Statement
emailadd =
"miles"
sqlstr1 =
("select * from copyinform where firstname ='" & emailadd & "'")
MsgBox sqlstr1
Set rst1 =
db.OpenRecordset(sqlstr1)
rst1.MoveLast
rst1.MoveFirst
MsgBox rst1.Fields("firstname").Value
6.
To insert Single Quote in a
query
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
' a = Your DSN , b= Your bind DN
in Log
in dialog , c= your password
a = "Beta1"
b = "cn=directory manager"
c =
"password"
cn.Open a, b, c
SQLStmt = "insert into customer (lastname,name) values (" & """" & "D'Souza" & """" & "," & _
"""" & "Frank" & """)"
'display constructed SQL
query
MsgBox SQLStmt
Set rs = cn.Execute(SQLStmt)
End Sub
7.
Height, Width Properties Example
This example sets the size of a form to 75 percent of screen size and centers the form when it is loaded. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Private Sub Form_Click ()
Width =
Screen.Width * .75 ' Set width of form.
Height =
Screen.Height * .75 ' Set height of form.
Left =
(Screen.Width - Width) / 2 ' Center form horizontally.
Top = (Screen.Height - Height) / 2 ' Center form vertically.
End Sub
8.Read From a Text File & Write Into a Text File Or Html File
Private Sub Form_Load()
Dim textline
Open ("h:/write_into_html.txt") For Input As #1
Open "h:/write.html" For Output As #2
Open "h:/write.txt" For Output As #3
Dim LinesFromFile, NextLine As String
filenum = 1
Do Until EOF(filenum)
Line Input #filenum, NextLine
LinesFromFile = NextLine
'For .html
file add "<BR>" tag for writing new line
Print #2, NextLine & "<BR>"
Print #3, NextLine
Loop
MsgBox "Program Over"
End Sub