|
Hi,
Following sample shows the use of Winsock in vb6. Just copy, paste & Test.
To Test in local mode (if currently u don't have two machines connected) Make "yourproject.exe" & run in double instance then: in 1 instance click Listen(Command2) And another click Connect(Command2). Then Type text in Text3 and click on Send(Command3).
Option Explicit
Private Sub Command1_Click()
Winsock1.Connect Me.Text1, Me.Text2
End Sub
Private Sub Command2_Click()
Winsock1.LocalPort = Me.Text2
Winsock1.Listen
End Sub
Private Sub Command3_Click()
Winsock1.SendData Me.Text3.Text
Me.Caption = "Local Send" & Me.Text3.Text
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim AD As String
Winsock1.GetData AD
Me.Caption = "Remote: " & AD
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
On Error Resume Next
Winsock1.Close
Winsock1.Accept requestID
Me.Caption = "Request accepted"
End Sub
Private Sub Winsock1_Close()
Me.Caption = "Closed"
End Sub
Private Sub Winsock1_Connect()
Me.Caption = "Chat Started at " & Time
End Sub
|
|
|
|
|
i bind a datagridview(window form) to a datable. but i added extra checkbox column from design . i notice it does not check whn i run it
|
|
|
|
|
Normally this should work, even if your datatable (rows) is empty.
How did you work things out, exactly?
|
|
|
|
|
i have resolve. i need to check editing thanks
|
|
|
|
|
I am using the following borrowed code to insert an image into an RTF, as that aspect of RTF seemed way beyond me
[code]Public Sub InsertImage(ByVal _image As Image)
Dim _rtf As New StringBuilder()
' Append the RTF header
_rtf.Append(RTF_HEADER)
' Create the font table using the RichTextBox's current font and append
' it to the RTF string
_rtf.Append(GetFontTable(Me.Font))
' Create the image control string and append it to the RTF string
_rtf.Append(GetImagePrefix(_image))
' Create the Windows Metafile and append its bytes in HEX format
_rtf.Append(GetRtfImage(_image))
' Close the RTF image control string
_rtf.Append(RTF_IMAGE_POST)
Me.SelectedRtf = _rtf.ToString()
End Sub
Private Function GetImagePrefix(ByVal _image As Image) As String
Dim _rtf As New StringBuilder()
' Calculate the current width of the image in (0.01)mm
Dim picw As Integer = CType(Math.Round((_image.Width / xDpi) * HMM_PER_INCH), Integer)
' Calculate the current height of the image in (0.01)mm
Dim pich As Integer = CType(Math.Round((_image.Height / yDpi) * HMM_PER_INCH), Integer)
' Calculate the target width of the image in twips
Dim picwgoal As Integer = CType(Math.Round((_image.Width / xDpi) * TWIPS_PER_INCH), Integer)
' Calculate the target height of the image in twips
Dim pichgoal As Integer = CType(Math.Round((_image.Height / yDpi) * TWIPS_PER_INCH), Integer)
' Append values to RTF string
_rtf.Append("{\pict\wmetafile8")
_rtf.Append("\picw")
_rtf.Append(picw)
_rtf.Append("\pich")
_rtf.Append(pich)
_rtf.Append("\picwgoal")
_rtf.Append(picwgoal)
_rtf.Append("\pichgoal")
_rtf.Append(picw)
_rtf.Append(" ")
Return _rtf.ToString()
End Function
<DllImportAttribute("gdiplus.dll")> _
Private Shared Function GdipEmfToWmfBits(ByVal _hEmf As IntPtr, ByVal _bufferSize As UInt32, ByVal _buffer As Byte(), ByVal _mappingMode As Integer, ByVal _flags As EmfToWmfBitsFlags) As UInt32
End Function
''' <summary>
''' Wraps the image in an Enhanced Metafile by drawing the image onto the
''' graphics context, then converts the Enhanced Metafile to a Windows
''' Metafile, and finally appends the bits of the Windows Metafile in HEX
''' to a string and returns the string.
''' </summary>
''' <param name="_image"></param>
''' <returns>
''' A string containing the bits of a Windows Metafile in HEX
''' </returns>
Private Function GetRtfImage(ByVal _image As Image) As String
Dim _rtf As StringBuilder = Nothing
' Used to store the enhanced metafile
Dim _stream As MemoryStream = Nothing
' Used to create the metafile and draw the image
Dim _graphics As Graphics = Nothing
' The enhanced metafile
Dim _metaFile As Metafile = Nothing
' Handle to the device context used to create the metafile
Dim _hdc As IntPtr
Try
_rtf = New StringBuilder()
_stream = New MemoryStream()
' Get a graphics context from the RichTextBox
Using _graphics1 As Graphics = Me.CreateGraphics()
' Get the device context from the graphics context
_hdc = _graphics1.GetHdc()
' Create a new Enhanced Metafile from the device context
_metaFile = New Metafile(_stream, _hdc)
' Release the device context
_graphics1.ReleaseHdc(_hdc)
End Using
' Get a graphics context from the Enhanced Metafile
Using _graphics1 As Graphics = Graphics.FromImage(_metaFile)
' Draw the image on the Enhanced Metafile
_graphics1.DrawImage(_image, New Rectangle(0, 0, _image.Width, _image.Height))
End Using
' Get the handle of the Enhanced Metafile
Dim _hEmf As IntPtr = _metaFile.GetHenhmetafile()
' A call to EmfToWmfBits with a null buffer return the size of the
' buffer need to store the WMF bits. Use this to get the buffer
' size.
Dim _bufferSize As UInt32 = GdipEmfToWmfBits(_hEmf, 0, Nothing, MM_ANISOTROPIC, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault)
' Create an array to hold the bits
Dim _buffer As Byte() = New Byte(CInt(_bufferSize)) {}
' A call to EmfToWmfBits with a valid buffer copies the bits into the
' buffer an returns the number of bits in the WMF.
Dim _convertedSize As UInt32 = GdipEmfToWmfBits(_hEmf, _bufferSize, _buffer, MM_ANISOTROPIC, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault)
For i As Integer = 0 To _buffer.Length - 1
' Append the bits to the RTF string
_rtf.Append([String].Format("{0:X2}", _buffer(i)))
Next
Return _rtf.ToString()
Finally
If _graphics IsNot Nothing Then
_graphics.Dispose()
End If
If _metaFile IsNot Nothing Then
_metaFile.Dispose()
End If
If _stream IsNot Nothing Then
_stream.Close()
End If
End Try
End Function
[/code]
sorry for so much code, anyway if i use that, the image is huge, here is a sample untouched image
i tried inserting the image with wordpad and copying the picw, pich, pichgoal, and picwgoal values from the wordpad generated RTF, but then the image looked almost squeezed together. i did notice the image hex values seemed quite different, i can't simply copy as the image itself will be different each run, I am at a loss, any help is appreciated
|
|
|
|
|
Yuck.
Put your code in a code block and write in paragraphs.
Also, put the question at the top and refer to code below, it makes it much more likely people will help.
They will not want to wade through treacle to get to the question.
Anyways, hav you tried to shrink the image?
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Formating the code would help but never mind. Looks like a typo.
djdrew wrote: Append values to RTF string
_rtf.Append("{\pict\wmetafile8")
_rtf.Append("\picw")
_rtf.Append(picw)
_rtf.Append("\pich")
_rtf.Append(pich)
_rtf.Append("\picwgoal")
_rtf.Append(picwgoal)
_rtf.Append("\pichgoal")
_rtf.Append(picw)
_rtf.Append(" ")
Should be :
_rtf.Append("{\pict\wmetafile8")
_rtf.Append("\picw")
_rtf.Append(picw)
_rtf.Append("\pich")
_rtf.Append(pich)
_rtf.Append("\picwgoal")
_rtf.Append(picwgoal)
_rtf.Append("\pichgoal")
_rtf.Append(pichgoal)
_rtf.Append(" ")
|
|
|
|
|
thank you both, i apologize as i'm very new here and not used to posting at all, i'll try to get more familiar with the proper way and give your solution a try as well, i can't believe i didn't notice that
|
|
|
|
|
Hi,everyone!I used a treeview control in a splitcontainer,I want it to work like frame web:when I click one node,some controls display on right.I wrote the NodeMouseClick Event like these:
Private Sub treeQiaoTi_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeQiaoTi.NodeMouseClick
If e.Node.Text = "abc" Then
panJieGuan2.Visible = False
Panel1.Visible = True
Else
Panel1.Visible = False
panJieGuan2.Visible = True
End If
End Sub
When I clicked the node "abc",the panel1 displayed on right,but after I clicked other nodes,panJieGuan2 is not shown.
panel1 and panJieGuan2 were all on splitcontainer right panel,panJieGuan2 was above panel1.
PLZ give me some suggestions and help me !!THX!
|
|
|
|
|
Have a look at this link click here
but a snippet here shows how to read a selected node into a label
Public Class Form12 Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
#End Region
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As_
System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
Label1.Text = "You are here->" & " " & e.Node.FullPath
'displaying the path of the selected node
Label2.Text = "Current node selected:" & " " & e.Node.Text
'displaying the selected node
End Sub
End Class
As barmey as a sack of badgers
|
|
|
|
|
Hi,Simon!Emmmmm...I think your suggestion is that I should write other event to get selectnode?
|
|
|
|
|
something else you could try is on your current method is
messagebox.show TreeView1.SelectedNode.Text
where treeview1 is the name of your treeview
As barmey as a sack of badgers
|
|
|
|
|
Simon,I use msgbox to show the select node,I found that it got forcus on mouse click,emm...,I means when I click "123",the e.node is really "123",and this time the controls occured.
But I found another question.For example,Panel 2 was on Panel 1,Panel 2 relies on Panel 1.I want when I clicked node 1,Panel 1 should display;when I clicked node 2,Panel 2 should display.Could you tell me how could do this?
Thanks a lot!
|
|
|
|
|
If panel1 is a child of panel2 OR Panel2 is a child of Panel1 you'll never see child panelin your form.
Check the following Code:
Private Sub treeQiaoTi_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeQiaoTi.NodeMouseClick
Me.Text = e.Node.Text
If e.Node.Text = "abc" Then
panJieGuan2.Visible = False
Panel1.Visible = True
Panel1.BringToFront()
Else
Panel1.Visible = False
panJieGuan2.Visible = True
panJieGuan2.BringToFront()
End If
End Sub
This is not Necessary yet:
Private Sub treeQiaoTi_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeQiaoTi.AfterSelect
End Sub
Use <pre lang="vb"> Visual Basic Code Here.</pre>
|
|
|
|
|
Hi,Aslam,thank you very much!
|
|
|
|
|
Hi friends,
Kindly help me for this.
I have one excel sheet which has only 1 row (first row) which is heading.
I have another excel sheet which has header row and data rows.
I wanted to copy from the second excel sheet to first excel sheet based on the header using vba.
Please help me...
Thanks in Advance!!
Regards,
|
|
|
|
|
Even tou ur problem was not clear i tried to help you with what i have understood.
You want to copy a sheet from a sheet, if a sheet has three columns below is the code.
Dim i As Integer
i = 1
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i,1)=sheet2.cells(i,1)
sheet1.cells(i,2)=sheet2.cells(i,2)
sheet1.cells(i,3)=sheet2.cells(i,3)
i=i+1
wend
If you want to keep the header as it is in sheet1 and want to copy the whole thing next to it, below is the code:
Dim i As Integer
i = 1
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i+1,1)=sheet2.cells(i,1)
sheet1.cells(i+1,2)=sheet2.cells(i,2)
sheet1.cells(i+1,3)=sheet2.cells(i,3)
i=i+1
wend
cheers
'S wayez
'http://wayezquotes.blogspot.com
|
|
|
|
|
if you dont want to disturb both the header then
i=2
if you want to compare headers of both
if sheet1.cells(1,1)=sheet2.cells(1,1) then
Dim i As Integer
i = 2
While Trim(sheet2.Cells(i, 1)) <> ""
sheet1.cells(i,1)=sheet2.cells(i,1)
sheet1.cells(i,2)=sheet2.cells(i,2)
sheet1.cells(i,3)=sheet2.cells(i,3)
i=i+1
wend
End if
|
|
|
|
|
Hi,
Thank you so much for replying me..
but i wanted to copy data from one excel file to another excel file...
example in Excel file1, Sheet1 I have data for Emp Id, Emp Name etc.,
I have Excel file2, Sheet1 with only the headers in the first row like Emp Id, Emp Name ...etc..Which is exists some path in the hard drive.
When I open Excel file1 and clicking some button, the data in the Excel file1 sheet1 should go to the Excel file2 sheet1 under approximate columns...
Hope its understandable....
Kindly Reply....
Thanks lot again..
Regards,
|
|
|
|
|
Hi,
it's quite simple as long as the columns of both workbooks are consistent, i.e. if the first column of Workbook1.WorkSheet1 has to go to the first column of Workbook2.Worksheet1, etc. The following snippet works and can give you a first idea:
Sub CopyToTarget()
Dim tgt As Excel.Workbook
Dim target As String
Dim rng As Range
' define the range to copy here
' with End(xlDown) you catch all the rows as long as there are no empty cells.
Set rng = ActiveSheet.Range(Cells(2, 1), Cells(2, 1).End(xlDown))
' open the target workbook as object; in this case the workbook has to exist already!
Set tgt = Application.Workbooks.Open("D:\Target.xls")
' copy the range to the required cell
rng.Copy tgt.Worksheets("Tabelle1").Cells(2, 1)
' save and close the target workbook
tgt.Save
tgt.Close
' delete objects that are no longer needed
Set rng = Nothing
Set tgt = Nothing
End Sub If you have to identify the right column first, use the ranges method 'find' to determine the cell where you want to copy the data. In VBA, you will want to use IntelliSense as much as you can - it really helps you to find your way!
|
|
|
|
|
Hi Michael,
Thanks a lot!!
Its working....but yes as u said..the sequence of the columns will not be simillar as per the source work book...some time the target workbook has more compare to source workbook...now i want to compare the column names and if matching then copy its range under that column...
Thanks again..really its great help...
Regards,
Priya
|
|
|
|
|
Good Priya jii!
As michael said but if you want to check with headers Just check the range in target sheet and compare to data sheet if exists paste.
if ActiveSheet.Range(Cells(1, 1)="Emp Num" then
Set rng = ActiveSheet.Range(Cells(2, 1), Cells(2, 1).End(xlDown))
Set tgt = Application.Workbooks.Open("D:\Target.xls")
rng.Copy tgt.Worksheets("Tabelle1").Cells ' tgt.Save
tgt.Close
end if
|
|
|
|
|
If you want to keep it even more flexible, you rather use 'find' - in case your EmpNum stands in a different column. Here's the modified idea, also checking for non existing header as Ahmed assumed. You can extend it in many different ways.
Sub CopyToTarget()
Dim tgt As Excel.Workbook
Dim rng As Range
Dim srcHeader As Range
Dim tgtHeader As Range
Dim dataCol As Integer
' define the range to copy here, supplying the column no you wish to copy
' with End(xlDown) you catch all the rows as long as there are no empty cells.
dataCol = 1
Set srcHeader = ActiveSheet.Cells(1, dataCol)
Set rng = srcHeader.Range(Cells(2, dataCol), Cells(2, dataCol).End(xlDown))
' open the target workbook as object; in this case the workbook has to exist already!
Set tgt = Application.Workbooks.Open("D:\Target.xls")
' find the header of the given dataCol in row 1 of the target worksheet
Set tgtHeader = tgt.Worksheets("Table1").Rows(1).EntireRow.Find(srcHeader.Value)
' copy the range to the required cell
' if not found then notice the user
If tgtHeader Is Nothing Then
MsgBox "Header not found in target workbook."
Else
rng.Copy tgt.Worksheets("Table1").Cells(2, tgtHeader.Column)
End If
' save and close the target workbook
tgt.Save
tgt.Close
' delete objects that are no longer needed
Set rng = Nothing
Set srcHeader = Nothing
Set tgtHeader = Nothing
Set tgt = Nothing
End Sub Maybe you google for samples of the Range object, they might even inspire you .
|
|
|
|
|
Hi Priya,
regarding your question from direct mail, how you should re-arrange the colunms, I want to give you a first idea again - not knowing if it's the best way ever, but it seems simple and pragmatic:
Sub ReArrange()
Dim strHeaders() As String
Dim sortOrder As String
Dim i As Integer
' define how the columns / headers are to be arranged
sortOrder = "EmpID,EmpName,EmpSalary"
' read the string into an array
strHeaders = Split(sortOrder, ",")
' loop through the array
For i = LBound(strHeaders) To UBound(strHeaders)
' take care: i will be 0 first (array index starting with 0)
' so you can't assign i to a colunm --> i + 1 is fine
MsgBox "Header of column " & i + 1 & " = " & strHeaders(i)
' here you find the respective header and copy your headers and/or data.
' I guess you can adapt the code sample from before already, can you?
Next
End Sub Hope that helps you - and don't forget to vote !
|
|
|
|
|
Hi Michael,
Thanks. Yes the one sheet which i have is so complicated format of row and column and data too...its not structured...So I need more effort for this to get done..Let me try and post if struckup inbetween...
Still I manage to do, but the code I writing is becoming so lengthy ...
Thanks again.
Regards,
Priya.
|
|
|
|
|