Search This Blog

Saturday, October 10, 2009

Socket example (Chat application) in vb.net

Two application one on server and other on client (can be run both on same machine). Just run server first. After run write text and click on send, text will appear on client applcation as well.
Chat applcaition / chat server in vb.net

SERVER code

Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Const portNumber As Integer = 8000
Public tcpListener As New TcpListener(portNumber)
Public tcpClient As TcpClient
Public networkStream As NetworkStream
' Read the stream into a byte array
Public bytes(1000000) As Byte
Public clientdata As String
Public responseString As String ' = TextBox2.Text '"Connected to server."
Public sendBytes As [Byte]()
Public flag As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If flag = 0 Then
tcpListener.Start()
tcpClient = tcpListener.AcceptTcpClient()
networkStream = tcpClient.GetStream()
Timer1.Enabled = True
flag = 1
End If

responseString = TextBox2.Text
sendBytes = Encoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
TextBox1.Text = TextBox1.Text & vbCrLf & "SERVER:" & TextBox2.Text '& vbCrLf
TextBox2.Text = ""

End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If networkStream.DataAvailable = True Then
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client to the console.
clientdata = Encoding.ASCII.GetString(bytes)
Array.Clear(bytes, 0, bytes.Length)
TextBox1.Text = TextBox1.Text & vbCrLf & "CLIENT: " & clientdata '& vbCrLf
'Console.WriteLine(("Client sent: " + clientdata))
'responseString = TextBox2.Text '"Connected to server."
'sendBytes = Encoding.ASCII.GetBytes(responseString)
'networkStream.Write(sendBytes, 0, sendBytes.Length)
' Timer1.Enabled = False
End If

' TextBox1.Text = TextBox1.Text & TextBox2.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
tcpClient.Close()
tcpListener.Stop()
Me.Close()
End Sub
End Class

=========================================

Client Code (Change IP accordingly in [ tcpClient.Connect("127.0.0.1", 8000) ] line)


Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Public flag As Integer = 0
Public tcpClient As New System.Net.Sockets.TcpClient()
Public networkStream As NetworkStream '= tcpClient.GetStream()
Public bytes(100000) As Byte
Public returndata As String ' = Encoding.ASCII.GetString(bytes)
Public sendBytes As [Byte]()

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If flag = 0 Then
tcpClient.Connect("127.0.0.1", 8000)
networkStream = tcpClient.GetStream()
flag = 1
Timer1.Enabled = True
End If

' Do a simple write.
sendBytes = Encoding.ASCII.GetBytes(TextBox2.Text)
networkStream.Write(sendBytes, 0, sendBytes.Length)
'
TextBox1.Text = TextBox1.Text & vbCrLf & "CLIENT" & TextBox2.Text '& vbCrLf
TextBox2.Text = ""
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If networkStream.DataAvailable = True Then
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes)
Array.Clear(bytes, 0, bytes.Length)
TextBox1.Text = TextBox1.Text & vbCrLf & "SERVER: " & returndata '& vbCrLf
' Timer1.Enabled = False
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
tcpClient.Close()
Me.Close()
End Sub
End Class


=======================
2 textboxes are used. one with multiline property ON
and and button to send message

DoEvents In VB.NET

DOEVENTS is similar as it is in the VB6.
Here is the simple code in VB.NET to test DOEVENT.
(Four buttons start, stop loop and reset variable, a message pop up during the loop is ON)


Public Class Form1
Public x As Integer = 0
Public y As Integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
While x = 0
y = y + 1
Label1.Text = y
System.Windows.Forms.Application.DoEvents()
End While
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
x = 0
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
x = 1
MessageBox.Show("Loop Stopped")
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
MessageBox.Show("vikas")
End Sub

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
'MessageBox.Show("Activated")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("Form Loaded")
End Sub
End Class

Friday, July 10, 2009

Thursday, July 9, 2009

Update ms ACCESS using vb.net

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
' MessageBox.Show("open")
Else
MessageBox.Show("open already")
End If

If cn.State = ConnectionState.Open Then
'MessageBox.Show(objCh1_FULL.isON & " " & objCh1_FULL.isScale)
'QUERY TO UPDATE ALL SETTINGS
cmd = New OleDbCommand("UPDATE allSettings set Channel_on_off = '" & objCh1_FULL.isON & "', Channel_name= '" & objCh1_FULL.Name & "', Div_Shunt='" & objCh1_FULL.isModeDivider & "', Divider_Ratio='" & objCh1_FULL.Ratio & "', Amplitue='" & _
objCh1_FULL.Ampl & "', Measuring_Time='" & objCh1_FULL.MeasureTime & "', UnderShoot='" & objCh1_FULL.UnderShoot & "', Polarity='" & objCh1_FULL.isPositivePolarity & "', Trigger_Level ='" & objCh1_FULL.trigger & "', Suggested='" & objCh1_FULL.suggested & _
"', Suggested_Manual='" & objCh1_FULL.suggested_sel & "', Offset='" & objCh1_FULL.Offset & "', Internal_Divider='" & objCh1_FULL.InternalDivider & "', Max_Voltage='" & objCh1_FULL.maxVolt & "', BIL_Level='" & objCh1_FULL.billevel & _
"', Auto_Manual='" & objCh1_FULL.isScale & "' where File_type='Full_A'", cn)

dr = cmd.ExecuteReader


dr.Close()
cn.Close()

Connecting And Reading MS ACCESS using vb.net

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Im_ETM\dbase\settings.mdb;")
'provider to be used when working with access database
If cn.State = ConnectionState.Closed Then
cn.Open()
Else
MessageBox.Show("Opened Already")
End If

If cn.State = ConnectionState.Open Then
'MessageBox.Show("open")

cmd = New OleDbCommand("select * from allSettings where File_type='Full_A'", cn)
dr = cmd.ExecuteReader
readDatabase(cmd, cn, dr, objCh1_FULL)
cmd = New OleDbCommand("select * from allSettings where File_type='Full_B'", cn)
dr = cmd.ExecuteReader

If dr.HasRows Then
While dr.Read()
' MessageBox.Show(dr(0) & dr(1) & dr(2))
' loading data into TextBoxes by column index

objch.isON = dr(2)
' MessageBox.Show(objch.isON)
objch.name = dr(3)
objch.ismodedivider = dr(4)
end while
end if


dr.Close()
cn.Close()

Deleting a table and Copy all data from other table MS ACCESS using vb.net

Dim AccessConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbase\settings.mdb;")
AccessConnection.Open()
Dim AccessCommand = New System.Data.OleDb.OleDbCommand("DELETE * from allSettings", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()


AccessCommand = New System.Data.OleDb.OleDbCommand("INSERT INTO allSettings SELECT * FROM allSettings_default", AccessConnection)
'AccessCommand = New System.Data.OleDb.OleDbCommand("SELECT * INTO allSettings FROM allSettings_default", AccessConnection)
AccessCommand.CommandType = CommandType.Text
AccessCommand.ExecuteNonQuery()
AccessConnection.Close()

Wednesday, July 8, 2009

WallPapers - Nature Colors



Funny Papers / Exam Solutions.. images Part II





Funny Papers / Exam Solutions.. images





Hide Navigation Bar of the Blog

Add following code in the HTML code where other style code is written,
Use Edit HTML in custmization

#navbar-iframe {
height:0px;
visibility:hidden;
display:none;
}


Hide Navigation Bar of the Blog

Add following code in the HTML code where other style code is written,
Use Edit HTML in custmization

#navbar-iframe {
height:0px;
visibility:hidden;
display:none;
}


Page Setup, Print Preview & Print code in vb.net

Page Setup, Print Preview & Print code in vb.net

' PGAE SETUP CODE
'ADD Control PrintDocument, Pagesetup, PrintDialog

Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem7.Click
'PAGE SETUP
With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With

With PageSetupDialog1
.PageSettings = PrintDocument1.DefaultPageSettings
End With
Try
If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
End If
Catch es As Exception
MessageBox.Show(es.Message)
End Try
End Sub


'PRINT PREVIEW CODE
Private Sub ToolStripMenuItem13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem13.Click

PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.WindowState = FormWindowState.Maximized
PrintPreviewDialog1.ShowDialog()

End Sub

'PRINT CODE

Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem5.Click
'PRINT
Try
PrintDocument1.Print()
Catch es As Exception
MessageBox.Show(es.Message)
End Try
'pd = New Printing.PrintDocument
' GetFormImage()

End Sub

'NOW PRINTPAGE EVENT HANDLER CODE means what to preview

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As _
System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'PrintPage is the foundational printing event. This event gets fired for every
' page that will be printed
' MessageBox.Show("vikas")
' declaring a static variable to hold the position of the last printed char
Dim font As New Font("Verdana", 14)
' initializing the font to be used for printing
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With print_Graphs_cpy2.PrintDocument1.DefaultPageSettings
' initializing local variables that contain the bounds of the printing area rectangle
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
' initializing local variables to hold margin values that will serve
' as the X and Y coordinates for the upper left corner of the printing
' area rectangle.
marginLeft = .Margins.Left
marginTop = .Margins.Top
' X and Y coordinate
End With

If print_Graphs_cpy2.PrintDocument1.DefaultPageSettings.Landscape Then
Dim intTemp As Int32
intTemp = PrintAreaHeight
PrintAreaHeight = PrintAreaWidth
PrintAreaWidth = intTemp
' if the user selects landscape mode, swap the printing area height and width
End If

Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
' calculating the total number of lines in the document based on the height of
' the printing area and the height of the font
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
' initializing the rectangle structure that defines the printing area
Dim fmt As New StringFormat(StringFormatFlags.LineLimit

'LET THIS FUNCTION IS CREATE A IMAGE OF A FROM, A POST IS ALSO THERE FOR THIS, AND CREATE A IMAGE NAMED formImage
GetFormImage()
e.Graphics.DrawString("PRINTING", font, Brushes.Black, 4, 15)
e.Graphics.DrawImage( formImage, 4, 100)

'YOU CAN ADD ANY OTHER THINGS LIKE THAT

End Sub

How to create a image of form in vb.net?

'DLL FUNCTION USED TO CREATE A FORM IMGAE
Public Declare Function BitBlt Lib "gdi32.dll" Alias _
"BitBlt" (ByVal hdcDest As IntPtr, _
ByVal nXDest As Integer, ByVal nYDest As _
Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hdcSrc As IntPtr, ByVal nXSrc As Integer, _
ByVal nYSrc As Integer, _
ByVal dwRop As System.Int32) As Long

Public formImage As Bitmap
Public Sub GetFormImage()
'CRATING A IMAGE OF THE FORM TO PRINT
' print_Graphs_cpy2 is a form
Dim g As Graphics = print_Graphs_cpy2.CreateGraphics

Dim s As Size = print_Graphs_cpy2.Size
formImage = New Bitmap(s.Width - 50, s.Height, g)
Dim mg As Graphics = Graphics.FromImage(formImage)
Dim dc1 As IntPtr = g.GetHdc
Dim dc2 As IntPtr = mg.GetHdc
' added code to compute and capture the form
' title bar and borders
Dim widthDiff As Integer = _
(print_Graphs_cpy2.Width - print_Graphs_cpy2.ClientRectangle.Width - 50)
Dim heightDiff As Integer = _
(print_Graphs_cpy2.Height - print_Graphs_cpy2.ClientRectangle.Height)
Dim borderSize As Integer = widthDiff \ 2
Dim heightTitleBar As Integer = heightDiff - borderSize
BitBlt(dc2, 0, 0, _
print_Graphs_cpy2.ClientRectangle.Width - 50 + widthDiff, _
print_Graphs_cpy2.ClientRectangle.Height + heightDiff, dc1, _
0 - borderSize, 0 - heightTitleBar, 13369376)

g.ReleaseHdc(dc1)
mg.ReleaseHdc(dc2)

formImage.Save("c:\grpah.jpg")

End Sub

Save a ZedGraph as a picture in vb.net

Dim objBitmap As Bitmap = New Bitmap(850, 1100)
Dim g As Graphics = Graphics.FromImage(objBitmap)
Public PB As System.Windows.Forms.PictureBox
PB.Image = ZedGraphControlA.GetImage()
g.DrawImage(PB.Image, 0, 747)
objBitmap.Save("c:\Graph.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)

Create a PDF using iTextSharp in C#

Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO

'download and add as reference iTextSharp DLL

'//Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin
'Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
' Try
'{
'PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create));
'//Open Document to write
'doc.Open;

'//Write some content
'Paragraph paragraph = new Paragraph("This is my first line using Paragraph.");
'Phrase pharse = new Phrase("This is my second line using Pharse.");
'Chunk chunk = new Chunk(" This is my third line using Chunk.");
'// Now add the above created text using different class object to our pdf document
'doc.Add(paragraph);
'doc.Add(pharse);
'doc.Add(chunk);
'}
'catch (DocumentException dex)

'{


'//Handle document exception
'}
'catch (IOException ioex)

'{
'//Handle IO exception
'}
'catch (Exception ex)

'{
'//Handle Other Exception
'}
' Finally
'{
'doc.Close(); //Close document
'}

Create a PDF using iTextSharp in vb.net

Imports iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.xml
Imports System.Text
Imports System.IO

'Download the iTextSharp DLL in add as reference

Public Sub create_pdf()
Dim rct As New Rectangle(850, 1100)
'Create Document class obejct and set its size to letter and give space left, right, Top, Bottom Margin

'file_name_pdf variable name of the pdf set as per necessity, rct is size of pdf
Dim doc As New Document(rct, 3, 3, 3, 3)
Try
If file_name_pdf <> "" Then
Dim file As System.IO.FileInfo = New FileInfo(file_name_pdf)
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream(file.DirectoryName & "\" & file.Name & ".pdf", FileMode.Create))
Else
Dim wri As PdfWriter = PdfWriter.GetInstance(doc, New FileStream("c:\Graph.pdf", FileMode.Create))
End If

'Open Document to write
doc.Open()
'Write some content
Dim paragraph As New Paragraph("Paragraph.")
Dim pharse As New Phrase("Pharse.")
Dim chunk As New Chunk(" Chunk.")

' Dim img As iTextSharp.text.Image = Nothing
' Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing
' Dim rect As iTextSharp.text.Rectangle = Nothing


doc.Add(paragraph)
doc.Add(pharse)
doc.Add(chunk)
Dim gif As Image

'file_name_pdf variable name of the pdf set as per necessity
If file_name_pdf <> "" Then
'MessageBox.Show(file_name_pdf)
gif = Image.GetInstance(file_name_pdf + ".jpg")
Else
gif = Image.GetInstance("c:\" + "Graph.jpg")
End If
'Adding a gif file
doc.Add(gif)
Catch dex As DocumentException
'Handle document exception
Catch ioex As IOException
'Handle IO exception
Catch ex As Exception
'Handle Other Exception
Finally
'Close document
doc.Close()
End Try
End Sub

Tuesday, July 7, 2009

Convert date and time in the desired format in vb,net

dd/MM/yyyy
String.Format("{0:dd/MM/yyyy}", DateTime.Now)


MM/dd/yyyy
String.Format("{0:MM/dd/yyyy}", DateTime.Now)

dd/MM/yy
String.Format("{0:dd/MM/yy}", DateTime.Now)


time
String.Format("{0:t}", DateTime.Now)

With Day, month
String.Format("{0:F}", DateTime.Now)

i.eFriday, December 19, 2008 10:48:46 AM


Monday, July 6, 2009

Add a Control array at run time using vb.net e.g picturebox

Public PRINT_GRAPH_NOS As Integer = 12
Public PB(14) As System.Windows.Forms.PictureBox

Public Sub create_graph_image()
PB = New System.Windows.Forms.PictureBox(14) {}

For i As Integer = 0 To PRINT_GRAPH_NOS - 1
Me.Controls.Add(PB(i))
PB(i) = New PictureBox
With PB(i)
.Size = New Size(5, 5)
.BackColor = Color.Red
.Visible = True
.BringToFront()
.Show()
PB(i).Tag = "filename"
AddHandler PB(i).Paint, AddressOf PictureboxAdd
End With

Next
end sub

Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub

Create a image of Zedgraph

ZedGraphControlA.GetImage()

PictureBox1.Image=ZedGraphControlA.GetImage()

Add a Control at run time using vb.net e.g picturebox

'Declare a picturebox
Public PictureBox2 As New Windows.Forms.PictureBox

'e.g Adding a zed graph as image in that picturebox
Public Sub create_graph_image()

With PictureBox2
.Height = 100
.Width = 100
.BackColor = Color.BlanchedAlmond
.Visible = True
.BorderStyle = BorderStyle.Fixed3D
PictureBox2.Tag = "filename"
AddHandler PictureBox2.Paint, AddressOf PictureboxAdd

End With

Me.Controls.Add(PictureBox2)
' Dim g As Graphics

' g = CType(PictureBox2, PictureBox).CreateGraphics

PictureBox2.Image = Me.ZedGraphControlB.GetImage()
' PictureBox2.Visible = True
End Sub
Public Sub PictureboxAdd(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
Dim p As Windows.Forms.PictureBox = DirectCast(sender, Windows.Forms.PictureBox)
Dim fnt As New Font("Times New Roman", 10, FontStyle.Regular)
e.Graphics.DrawString(p.Tag, fnt, Brushes.Black, 20, 20)
End Sub

Saturday, July 4, 2009

Create a Password Textbox in vb.net

This can be easily done by setting the PasswordChar Property of Textbox

Set that propety to a PASSWORD char to be displayed

OR

write this code, after this textbox will show that particular char

TextBox1.PasswordChar = "*"

Friday, July 3, 2009

Downloading, Installing and Configuring Apache and php on Windows

1) Downloading

Apache
http://httpd.apache.org/download.cgi
Download -- Win32 Binary including OpenSSL 0.9.8i (MSI Installer)

Php
http://in2.php.net/get/php-5.2.8-win32-installer.msi/from/a/mirror
Download -- in.php.net

2) Installing

Apache
Double click on msi installer and follow the instruction.
Give your machines hostname and domain name when asked.
Finish it.

Php
Double click on php installer and follow the instruction.
Select the apache server when asked form the server list.
Finish it.

3)Configuring

Apache
Write "localhost" in browser - It shows like "It Works"

Now configure the Apache for php Add the lines in httpd.conf (in conf dir)

#Add this line where other LoadModule line are, this is for apache2.2, this dll comes when u installed php, in php folder, check the path as well

LoadModule php5_module "c:/Program Files/php/php5apache2_2.dll"

#DocumentRoot where you php files must be placed
#by default is, and can be changed to desired folder

DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"

#Add this line where other AddType statements are
AddType application/x-httpd-php .php

#AT the end of file add this, check php path
PHPIniDir "c:/Program Files/php"

Now restart the apache server, double click on
ApacheMonitor.exe
in bin folder of Apache dir, if already start, Maximise it from the Task bars icons

Restart the apache to make changes effective.


make a file php file eg v.php
write in it

phpinfo();

save file in C:/Program Files/Apache Software Foundation/Apache2.2/htdocs, which is default php folder

Now type in browser to get result....
localhost/v.php

How to clear array in c?

int ary[100]

memset((void*)&ary, 0, sizeof(int)*100);


How to clear array in vb.net?

Array.Clear(array_name, start_index,end_index)




Thursday, July 2, 2009

Does C, C++ support unsigned float?

No, because there is no equivalent machine code operations for the CPU to execute.

Comment?

Monday, June 29, 2009

Zedgraph a simple example, code

Zedgraph a simple example, code
VB.net code
===========CODE==============
Dim myPane As GraphPane
myPane = ZedGraphControlA.GraphPane
'title
myPane.Title="GRAPH"
myPane.YAxis.Title.Text = "Y"
myPane.XAxis.Title.Text = "X"
'set scale
myPane.XAxis.Scale.Max = 10
myPane.XAxis.Scale.Min = -10
myPane.YAxis.Scale.Max = 10
myPane.YAxis.Scale.Min = -10


'create a list
Dim list1 As New PointPairList
Dim i as integer

For i = 0 To 1
x = 0
y1 = 0
list1.Add(x, y1)
next i

'add a curve
myCurveA = myPane.AddCurve("", list1,color.blue, SymbolType.None)

'points to add
pts= myCurveA.Points

pts.Clear()

'add points
pts.Add(3,3)
pts.Add(4,4)
pts.Add(5,5)
pts.Add(6,6)

myPane.AxisChange()
' Make sure the Graph gets redrawn
ZedGraphControl1.Invalidate()

Friday, June 19, 2009

Ek Soch.................

Some Optical Illusions....

Illusion 1.

To find what is hidden, attentively fix the 4 black spots of the center during 30 seconds, Then look at a blank white wall, or a piece of paper, or on the white space near image. What do you see?
On the white zone which appears, you should see a famous character of the History (to accentuate the effect you can close or blink eyes)



==========================================================

Illusion 2.

If you continue to focus on the cross in the center of the image you will notice that ..

the violet circles will soon DISAPPEAR completely..


Thursday, June 18, 2009

Commands giving user information

* w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.
* who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.
* finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'.
* last -1 username --- tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins.
* talk username --- lets you have a (typed) conversation with another user
* write username --- lets you exchange one-line messages with another user
* elm --- lets you send e-mail messages to people around the world (and, of course, read them). It's not the only mailer you can use, but the one we recommend. See the elm page, and find out about the departmental mailing lists (which you can also find in /user/linguistics/helpfile).

Commands giving user information

* w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.
* who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.
* finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'.
* last -1 username --- tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins.
* talk username --- lets you have a (typed) conversation with another user
* write username --- lets you exchange one-line messages with another user
* elm --- lets you send e-mail messages to people around the world (and, of course, read them). It's not the only mailer you can use, but the one we recommend. See the elm page, and find out about the departmental mailing lists (which you can also find in /user/linguistics/helpfile).

Thursday, June 11, 2009

Message on the terminal.

Mesg X blinking on all your consoles.
Add these in ~/.profile

mesg X
[ `who -T |grep "$LOGNAME\ *+" |wc -l` -ge 1 ] && mesg X

Message on the terminal.

Mesg X blinking on all your consoles.
Add these in ~/.profile

mesg X
[ `who -T |grep "$LOGNAME\ *+" |wc -l` -ge 1 ] && mesg X

Saturday, June 6, 2009

Creating a DLL in VC++, and using it in VB.net, C#.net

STEP 1. Start a new project in VC++ as "win32 DLL"

STEP 2. Declare function in header file i.e class1.h as

extern "C" __declspec(dllexport) int add_2_nos(int a, int b);
extern "C" __declspec(dllexport) int mul_2_nos(int a, int b);

Let rest things as it is.

STEP 3. Define functions in cpp file i.e in class1.cpp as

#include "class1.h"
extern "C" __declspec(dllexport) int add_2_nos(int a, int b)
{ int c;
c=a+b;
return c;
}


extern "C" __declspec(dllexport) int mul_2_nos(int a, int b)
{ int c;
c=a*b;
return c;
}


STEP 4. Save file & Build & Build DLL

This will create a DLL in the release folder.

-----------------------------------------------------------
DLL in vb.net

STEP 1. Create a new project as "windows application" and code as

Imports System
Imports System.Runtime.InteropServices
Public Class a
DllImport("c:\MyDLL\vc_dll.dll", CharSet:=CharSet.Auto) _ 'in angular brackets
Public Shared Function add_2_nos(ByVal a As Integer, ByVal b As Integer) As Integer
End Function
End Class



Public Class Form1
'on button click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim b As Integer

b = a.add_2_nos(2, 3)
MessageBox.Show(b.ToString)
End Sub
End Class

STEP 2. Save it run it , click on button

-----------------------------------------------------------

DLL in C#

STEP 1. Create a new project as "windows application" and code as

using System;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("C://MyDLL/vc_dll.dll")]
public static extern int add_2_nos(int a, int b);

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int a;
a= add_2_nos(3,40);
MessageBox.Show(a.ToString());

}
}
}

STEP 2. Save it run it click on button.........

-------------------------------------------------------------------

Dll in copied in MyDLL folder in c: drive.

This dll can also be used in LabView

Wednesday, June 3, 2009

Creating & Using DLL in VB.NET

How to create and use DLL in VB.NET?

STEP 1. Create a VB.NET project as "Class Library".
Write this code as example (change accordingly). You will get Class1 there just need add a fuction here vikas_add (adding 2 numbers & returning result). DLL will have same name as your project name.
-----------------------------------
Public Class Class1
Public Function vikas_add(ByVal a As Integer, ByVal b As Integer) As Integer
Return a + b
End Function
End Class
-------------------------------------

STEP 2. Save and Build the project. This will create DLL. (prob. in Release folder).

STEP 3. Register your DLL.
For this i follow these steps--
1) Start -> Run -> Regedit --- This will open Registry Editor
2) Locate HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders
3) Right click AssemblyFolders and select New -> Key
4) Give any name. (i gave MyDLLs)
5) Select MyDLLs, double click on default in right pane, give path like (c:\MyDLL) which i have given.
6) Close Registry editor
7) Create a folder c:\MyDLL and copy you dll created above in this folder.

STEP 3. Create a new project as "Windows Application".
Add Reference as--> Project --> Add reference.
In .NET Tab you will get Component name as ClassLibrary1 and Path as your folder and DLL. Select that and click on OK. You can check in All Files in Project Explorer, in references.

CODE eg
---------------------------------------------------
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim obj As New ClassLibrary1.Class1 'Here classLibrary1.class1 is your DLL class which have vikas_add function

Dim txt1, txt2, res As Integer
txt1 = TextBox1.Text
txt2 = TextBox2.Text
'MessageBox.Show(obj.vikas_add(txt1, txt2))
res = obj.vikas_add(txt1, txt2)
Label2.Text = "Result of Numbers=" & res.ToString

End Sub
End Class


---------------------------------------------------

STEP 4. Save and Run........

----------------------------------------------------------------------------
There is also a way in VB.NET to use DLL, by add these 2 statemets, but dint work for me, every time i m getting entry point error. But with above i able to use DLL's function.
Whts tht?
can anybody comments?


Imports System.Runtime.InteropServices

_
Public Shared Function vikas_add(ByVal aa As Integer, ByVal bb As Integer) As Integer
End Function

Thursday, May 28, 2009

Amazing Treessss.....



Then &&&&&& Now

Now and then a thought comes to my mind
What if I could the clock unwind!!
Return to being a child once more
Ah! that wondrous age of four!



Then...
Life meant playing and reciting nursery rhymes
Dabbling with crayons and making colorful drawings.

Now...
To play one needs to be organized too
Join a play school at the tender age of two!



Then...
Mummy was my first teacher
Lovingly teaching me values which help in life later.

Now...
Mom's busy - working, socializing, and attending kitty parties
Child seems to be low on her priority!



Then...
If mummy had to go, grandma was there
Showering me with her love and care.

Now...
Left with housekeepers and maids
In front of the television passes the day.


Then...
I had never heard words like failure and rejection
Nor faced gruesome interviews for admission!

Now...
A three year old goes for tuition
To enter a prestigious school - the ultimate mission!



Then...
Holidays meant family get togethers, fun and enjoyment
At a relaxed pace honing our talents.

Now...
It's summer camps... professional guidance
Ever decreasing parental influence!



Then...
I had no computer games, no mobiles
No rat race to cover that extra mile!



Now...
Under peer pressure, childhood is wilting away
Competing with the Jones... whatever way!



Then...
The choices I was offered
did commensurate with my age.

Now...
Kids are burdened with choices
they are not mature enough to make!



Now and then I ponder
why kids are being propelled towards adulthood
Even before they have had a proper childhood?

Days.....

New Year's Day - January 1
Australia Day - January 26
Groundhog Day - February 2
Darwin Day - February 12
Valentine's Day - February 14
Texas Independence Day - March 2
International Women's Day - March 8
Pi Day - March 14
Saint Patrick's Day - March 17
April Fools Day - April 1
Children's Book Day - April 2
Earth Day - April 22
Labour Day - May 1
Mother's Day - May 11
Telecommunication Day - May 17
International Day for Biological Diversity - May 22
Towel Day - May 25
World Ocean Day - June 8
Canada Day - July 1
U.S.A. Day of Independence - Fourth of July
Victory over Japan Day - August 14/August 15
World Rubber Day - September 12
International Talk Like a Pirate Day - September 19
European Day of Languages - 26 September
German Unity Day - October 3
Boss' Day- Oct 16
Mole Day - October 23
Halloween - October 31
All Saints' Day - November 1
Day of the Dead - November 1(All Saints' Day) or November 2(All Souls' Day).
All Souls' Day - November 2
Armistice Day (also Remembrance Day) - November 11
Veterans Day - November 11
Transgender Day of Remembrance - November 20
Cities for Life Day - November 30


AND MANY MORE..................................