Showing posts with label module. Show all posts
Showing posts with label module. Show all posts

Tuesday, 23 February 2016

How to Read Event Viewer in VB.NETIn Feburary 2016 23,

In Feburary 2016 23,
Start Microsoft Visual Basic Express and click 'New Project...' on the left pane of your screen. Double-click 'Windows Forms Application' to start your new project.
Double-click 'Button' on the 'Tools' pane to create a new button. Double-click 'ListBox' on the 'Tools' pane to create a new list box control. Double-click 'Button1' to open the 'Form1.vb' module.
Press 'Ctrl+A' and press 'Delete' to delete all code.
Copy and paste the following code to your 'Form1.vb' module.Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim eventLogApp As New System.Diagnostics.EventLog('Application')Dim eventLogEntry As System.Diagnostics.EventLogEntryDim eventCntr As Integer = 1For Each eventLogEntry In eventLogApp.EntriesMe.ListBox1.Items.Add('Event Number:' & eventCntr)Me.ListBox1.Items.Add(eventLogEntry.EntryType.ToString)Me.ListBox1.Items.Add(eventLogEntry.TimeGenerated.ToString)Me.ListBox1.Items.Add(eventLogEntry.Source.ToString)Me.ListBox1.Items.Add(eventLogEntry.Category.ToString)Me.ListBox1.Items.Add(eventLogEntry.EventID.ToString)Me.ListBox1.Items.Add(eventLogEntry.MachineName.ToString)Me.ListBox1.Items.Add(eventLogEntry.Message.ToString)Me.ListBox1.Items.Add('-----------------------------------------------')eventCntr = eventCntr + 1Me.ListBox1.Refresh()NextEnd Sub
End Class
Start your program by pressing 'F5' and then clicking 'Button1' to display event log entries through a list box.
In Feburary 2016 23,

Friday, 19 February 2016

How to Use VBA to Import Data From Excel Into AccessIn Feburary 2016 19,

In Feburary 2016 19,
Launch Microsoft Office Excel and type 'data1' in A2, and 'data2' in B2. Press 'Ctrl' and 'S' to open the 'Save As' dialog Window and save the workbook in 'C:\Temp\' as 'dataToImport.xlsx.' Click 'Save' and close Excel.
Launch Microsoft Office Access, click 'Blank Database' and click the 'Create' button. Click 'Database Tools,' and click 'Visual Basic' to open the VB Editor Window. Click the 'Insert' menu and then click 'Module' to insert a new code module. Click the 'Tools' menu, click 'References,' and check the box next to 'Microsoft Excel
Object Library.'
Start by typing the following VBA code to create new sub procedure:Private Sub importExcelData()
Type the following to create variables you will use to read Excel: Dim xlApp As Excel.ApplicationDim xlBk As Excel.WorkbookDim xlSht As Excel.Worksheet
Type the following to create variables you will use in Access:Dim dbRst As RecordsetDim dbs As DatabaseDim SQLStr As String
Type the following to define database objects and also define the Excel workbook to use:Set dbs = CurrentDbSet xlApp = Excel.ApplicationSet xlBk = xlApp.Workbooks.Open('C:\Temp\dataToImport.xlsx')Set xlSht = xlBk.Sheets(1)
Create a new table with two columns in Access to import data from Excel. Type the following VBA code to create the table using the 'DoCmd' object:SQLStr = 'CREATE TABLE excelData(columnOne TEXT, columnTwo TEXT)'DoCmd.SetWarnings FalseDoCmd.RunSQL (SQLStr)
Open the table you just created by using a the Recordset object. Type the following to open the table and add a new row:Set dbRst = dbs.OpenRecordset('excelData')dbRst.AddNew
Type the following to get values from the Excel workbook, save them to your table and update the record:xlSht.Range('A2').SelectdbRst.Fields(0).Value = xlSht.Range('A2').ValuexlSht.Range('B2').SelectdbRst.Fields(1).Value = xlSht.Range('B2').ValuedbRst.Update
End your procedure by typing the following VBA code:dbRst.Closedbs.ClosexlBk.CloseEnd Sub
Press 'F5' to run the procedure. The data in your Excel workbook has just been imported into your Access table.
In Feburary 2016 19,

Thursday, 18 February 2016

How to Run a Client Server in NetBeansIn Feburary 2016 18,

In Feburary 2016 18,
Click the 'Start' button and 'All Programs' to expand the Windows application menu. Click the 'NetBeans' folder, then the 'NetBeans' application icon. This will launch NetBeans in a new window.
Right-click the 'EJB' project module and select 'New,' then 'Session Bean.' The NetBeans project configuration screen displays on screen.
Type 'MySession' in the 'EJB Name' box.
Type 'ejb' in the 'Package:' drop-down menu.
Click the 'Stateless' radio button under 'Session Type:.'
Click the 'Remote in project' check box under 'Create Interface:.' Select the 'EJBRemoteInterface' project from the drop-down list and then click the 'Finish' button.
Right-click the 'EntAppClient' enterprise application project and choose 'Run' from the drop-down menu. NetBeans builds the project that contains your application and runs it on a client server.
In Feburary 2016 18,

Sunday, 7 February 2016

How to Add Fields to a Table in Access with Visual BasicIn Feburary 2016 07,

In Feburary 2016 07,
Open Microsoft Visual Basic Express, and click 'New Project...' in the left pane of your screen. Double-click 'Console Application.' Press 'Ctrl' and 'A' and then press 'Delete' to remove the current code.
Copy and paste the following code to your 'Module1.vb' module to execute a query and add two fields to the 'Products' table in the Northwind database.Imports System.Data.OleDbModule Module1
Sub Main()Dim northwindConn As OleDbConnectionDim sqlComm As OleDbCommandDim strSQL As StringnorthwindConn = New OleDbConnection('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;')northwindConn.Open()strSQL = 'ALTER TABLE Products ' & _'ADD COLUMN Product_I Text (30), Product_II Text (30);'sqlComm = New OleDbCommand(strSQL, northwindConn)sqlComm.ExecuteNonQuery()MsgBox('Added two fields successfully to the Products table.')northwindConn.Close()End Sub
End Module
Edit the following line of code and type the path to your database:OleDbConnection('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;')Press 'F5' to run your program.
In Feburary 2016 07,

Friday, 5 February 2016

How to Use FTP From VBAIn Feburary 2016 05,

In Feburary 2016 05,
Open Microsoft Excel.
Click 'Tools,' 'Macro' and then 'Visual Basic.' This will open the VBA programming environment.
Click 'Tools' and 'Reference.' Scroll down and select the 'Microsoft Internet Transfer Control' and click 'OK.'
Click 'Insert' and 'Module.' You are now in a programming code module.Type or copy and paste the following in the code module:Function UploadFile(ByVal HostName As String, _
ByVal UserName As String, _ByVal Password As String, _ByVal LocalFileName As String, _ByVal RemoteFileName As String) As BooleanDim FTP As InetSet FTP = New InetWith FTP.Protocol = icFTP.RemoteHost = HostName.UserName = UserName.Password = Password.Execute .URL, 'Put ' + LocalFileName + ' ' + RemoteFileNameDo While .StillExecutingDoEventsLoopUploadFile = (.ResponseCode = 0)End WithSet FTP = Nothing
End Function
In Feburary 2016 05,