|
Simply use the network classes to open up a connection on that port and start to receive the network stream.
Here is the example from MSDN using the TCPClient class;
Shared Sub Connect(server As [String], message As [String])
Try
Dim port As Int32 = 13000
Dim client As New TcpClient(server, port)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)
Console.WriteLine("Sent: {0}", message)
data = New [Byte](256) {}
Dim responseData As [String] = [String].Empty
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)
stream.Close()
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try
Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub
And an example using the UDPClient class;
Dim udpClient As New UdpClient(11000)
Try
udpClient.Connect("www.contoso.com", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?")
udpClient.Send(sendBytes, sendBytes.Length)
Dim udpClientB As New UdpClient()
udpClientB.Send(sendBytes, sendBytes.Length, "AlternateHostMachineName", 11000)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
Console.WriteLine(("This is the message you received " + _
returnData.ToString()))
Console.WriteLine(("This message was sent from " + _
RemoteIpEndPoint.Address.ToString() + _
" on their port number " + _
RemoteIpEndPoint.Port.ToString()))
udpClient.Close()
udpClientB.Close()
Catch e As Exception
Console.WriteLine(e.ToString())
End Try
|
|
|
|
|
Guys and Gals,
i have the following example VB.NET 2008
' Add a button column.
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.HeaderText = ""
buttonColumn.Name = "Status Request"
buttonColumn.Text = "Request Status"
buttonColumn.UseColumnTextForButtonValue = True
datagridview1.columns.add(buttoncolumn)
Runs with no errors but the text doesn't show up. Any ideas?
Thanks
Simon
modified on Wednesday, March 31, 2010 7:25 AM
|
|
|
|
|
Simon_Whale wrote: Runs with no errors but the text doesn't show up. Any ideas?
Yup, you set the HeaderText [^] property to Nothing . Try something like this;
buttonColumn.HeaderText = "Hello World"
I are Troll
|
|
|
|
|
|
You're right. I've taken the example, compiled it using SharpDevelop, the example shows the exact same code;
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.HeaderText = ""
buttonColumn.Name = "Status Request"
buttonColumn.Text = "TestText"
buttonColumn.UseColumnTextForButtonValue = True The HeaderText is the caption of the column, my bad. And yes, this code should have changed the caption of the button within the buttoncolumn.
It seems that the example works. Can you post your version of the code?
I are Troll
|
|
|
|
|
Thanks for this Ed
Private Sub Properties_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'set the screen size according to values in the app.config
Me.Width = My.Settings.x
Me.Height = My.Settings.y
'load in the list of countries they can use
'Dim cList As New List(Of ClientHome.vb.Countries)
'Dim x As New ClientHome.vb.Buildings
'cList = x.Countries
'cbCountries.DataSource = cList
'x = Nothing
'expiry date
'dtBldExpiry.Value = DateAdd(DateInterval.Day, 365, dtBldStart.Value)
'dtCntExpiry.Value = DateAdd(DateInterval.Day, 365, dtCntStart.Value)
'the question textbox in the grid
Dim xy As New DataGridViewTextBoxColumn
xy.HeaderText = "Question"
Me.DataGridView1.Columns.Add(xy)
'drop down list on grid
Dim xx As New DataGridViewComboBoxColumn
xx.Name = "YesNo"
xx.Items.Add("Yes")
xx.Items.Add("No")
Me.DataGridView1.Columns.Add(xx)
'the Answer Question
Dim yx As New DataGridViewTextBoxColumn
yx.HeaderText = "Answer"
Me.DataGridView1.Columns.Add(yx)
'the view button
' Add a button column.
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.Name = "Requests"
buttonColumn.Text = "Requests"
buttonColumn.UseColumnTextForButtonValue = True
DataGridView1.Columns.Add(buttonColumn)
End Sub
thats it Ed, there is a datagridview control on the form
Many Thanks
Simon
|
|
|
|
|
Simon_Whale wrote: there is a datagridview control on the form
With or without the correct caption on the buttons? I'll send my version by mail
I are Troll
|
|
|
|
|
There is no captions on the button for the code i sent but im after putting a caption on the button for the users to press
once again many thanks for your help
SImon
|
|
|
|
|
Ed,
Thank you, you are a genius worked out the problem from your example.
During my experimentation / design layouts i wasn't adding a datasource to the grid. so it was displaying the first empty row.
I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected.
could you assume this is how its suppose to work?
Many Thanks
Simon
|
|
|
|
|
Simon_Whale wrote: Thank you, you are a genius worked out the problem from your example.
Glad that it helped, but you're the one who worked it out
Simon_Whale wrote: I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected.
could you assume this is how its suppose to work?
It's one way that it can work - there's a lot of ways to fill a datagridview. And yes, it would be a good way; it's easy to read, easy to comprehend and thus, easy on maintenance.
I are Troll
|
|
|
|
|
I'm having the same problem. I read the postings, but I don't understand how this was solved.
Here is my code snipet:
Dim dgBtnCol As New DataGridViewButtonColumn()
dgBtnCol.Name = "SelBtn"
dgBtnCol.Text = "Select"
DataGridView1.Columns.Add(dgBtnCol)
Me.DataGridView1.DataSource = DT ' The datatable is already populated with data at this point
The grid displays, but the caption on the button is nothing. How did the original poster solve this ?
I forgot to add the following line of code ....
<br />
dgBtnCol.UseColumnTextForButtonValue = True
Regards,
David
|
|
|
|
|
Below is what i have working in a project
Private Sub CreateGrid(ByRef data As DataView)
'the questionno
Dim BrokerNo As New DataGridViewTextBoxColumn
BrokerNo.HeaderText = "Broker Ref"
BrokerNo.DataPropertyName = "brokerref"
BrokerNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(BrokerNo)
'the question textbox in the grid
Dim BrokersName As New DataGridViewTextBoxColumn
BrokersName.HeaderText = "Broker Name"
BrokersName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
BrokersName.DataPropertyName = "brokername"
Me.DataGridView1.Columns.Add(BrokersName)
'drop down list on grid
Dim BrokerStatus As New DataGridViewTextBoxColumn
BrokerStatus.DataPropertyName = "status"
BrokerStatus.HeaderText = "Status"
BrokerStatus.Name = "Status"
Me.DataGridView1.Columns.Add(BrokerStatus)
'the Answer Question
Dim Address As New DataGridViewTextBoxColumn
Address.Name = "Address"
Address.DataPropertyName = "address"
Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(Address)
Dim TelNo As New DataGridViewTextBoxColumn
TelNo.HeaderText = "Tel No"
TelNo.DataPropertyName = "telno"
TelNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Me.DataGridView1.Columns.Add(TelNo)
Dim buttonColumn As New DataGridViewButtonColumn()
buttonColumn.HeaderText = "View"
buttonColumn.Text = "View"
buttonColumn.UseColumnTextForButtonValue = True
buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
buttonColumn.FlatStyle = FlatStyle.Standard
DataGridView1.Columns.Add(buttonColumn)
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
DataGridView1.DataSource = data
End Sub
As barmey as a sack of badgers
|
|
|
|
|
Thanks for the quick reply.
After looking at my code more closely, I was missing the following:
<br />
dgBtnCol.UseColumnTextForButtonValue = True
My code is now working.
Thanks.
|
|
|
|
|
Another workaround is to set the NullValue of the column to the desired text.
In a project of mine I have a DataGridView where the user can add rows manually. The text for the button didn't appear and nothing seemed to work. I then remembered that there is always a NullValue property and after I set this, the text appeared on the button
DataGridViewCellStyle8.NullValue = "Some Text"
Me.AddStillstand.DefaultCellStyle = DataGridViewCellStyle8
Me.AddStillstand.HeaderText = ""
Me.AddStillstand.Text = "Some Text"
Just in case someone else is having a similar issue
|
|
|
|
|
Hi,
I was pondering quite some time over this issue. The NullValue property did the trick
Thanks for posting this!
Kind regards,
Bob Stanneveld
|
|
|
|
|
The code is working. just make sure that you apply this after assigning the datasource to your grid control.
Step 1. After assign datasource to grid.
// Add a button column.
DataGridViewButtonColumn buttonColumn =
new DataGridViewButtonColumn();
buttonColumn.HeaderText = "";
buttonColumn.Name = "Status Request";
buttonColumn.Text = "Request Status";
buttonColumn.UseColumnTextForButtonValue = true;
dataGridView1.Columns.Add(buttonColumn);
step2.
just after adding the columns register your click event like below.
// Add a CellClick handler to handle clicks in the button column.
dataGridView1.CellClick +=
new DataGridViewCellEventHandler(dataGridView1_CellClick);
step 3.
now on below event,
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
make sure which button is clicked when multiple are there.
if (e.RowIndex < 0 || e.ColumnIndex !=
dataGridView1.Columns["Status Request"].Index) return;
// Retrieve the task ID.
Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value;
// Retrieve the Employee object from the "Assigned To" cell.
Employee assignedTo = dataGridView1.Rows[e.RowIndex]
.Cells["Assigned To"].Value as Employee;
========================
Ref: http://msdn.microsoft.com/en-us/library/ms171619.aspx[^]
hello give me code
|
|
|
|
|
Mate this was solved last year
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Not really a visual basic problem, but i didnt know what forum to use, but my code is in vb.net
I have a program which has to print a bunch of documents, after printing a random number of documents this error is thrown: "Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) "
I have written this testprogram which throws the same error
Imports wrd = Microsoft.Office.interop
...
Private Shared moapp As wrd.Word.Application
Private Shared odoc As wrd.Word.Document
...
Private Sub test()
moapp = New wrd.Word.ApplicationClass().Application
For i As Integer = 0 To 100
odoc = moapp.Documents.Add("\\bur-131.cmc.Be\Tools\INFORMATICA\ZZorg\bevestziek.doc")
moapp.Selection.GoTo(What:=wrd.Word.WdGoToItem.wdGoToBookmark, Name:="bwNaam")
With moapp.ActiveDocument.Bookmarks
.DefaultSorting = wrd.Word.WdBookmarkSortBy.wdSortByName
.ShowHidden = False
End With
moapp.Selection.TypeText(Text:="whoopie" & i.ToString())
sOriginalPrinter = moapp.ActivePrinter
moapp.ActivePrinter = "\\S31W40F\PRINT075"
With moapp.ActiveDocument.PageSetup
.FirstPageTray = 261 '257
.OtherPagesTray = 261 '257
End With
moapp.Application.PrintOut(FileName:="", Range:=wrd.Word.WdPrintOutRange.wdPrintAllDocument, Item:= _
wrd.Word.WdPrintOutItem.wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wrd.Word.WdPrintOutPages.wdPrintAllPages, _
ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0)
While moapp.BackgroundPrintingStatus = 0
End While
moapp.ActivePrinter = sOriginalPrinter
odoc.SaveAs("C:\somelocation\temp.doc")
odoc.Close()
Next
System.Runtime.InteropServices.Marshal.ReleaseComObject(odoc)
odoc = Nothing
moapp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(moapp)
moapp = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()
End Sub
Sometimes it throws the error when opening the document, the other time when printing the document..
The problem occurs on a Vista Enterprise SP1, Office 2003 and only on a HP Laserjet 2430dtn printer. On another type of printer the code runs perfect, also on a win2000 the code runs perfect. I tried installing other drivers for this printer, same problem...
Does anyone have an idea what i can try to solve or work around this problem. I know my code works when i close word and close the document and call the garbagecollector for each document, but then it takes about 17 seconds per document to print out...
If i don't print at all it also works
Thanks in advance.
|
|
|
|
|
Hi,
I am new to Visual Basic 2005. I need help in displaying the hierarchical data from the database in treeview and also update the tables back when a new node is added/deleted. I am using Oracle as background. Please help me to get some study material or sample code.
|
|
|
|
|
How can I validate that a user has entered a correct phone number into a text box? The existing form uses a textbox to input the phone number. Apparently the only valid entries are in the following form: xxx-xxx-xxxx
I am not sure how to pass values into a procedure or function.
Can someone help?
Thank you
|
|
|
|
|
If you are using VB.NET, you can use "regular expressions" to validate your field matches a particular format... if you are using VB6 (why??), then you will need to have an event behind your form that passes the textbox's value to a function for parsing.
|
|
|
|
|
As Damian S said, you can use regular expressions in VB.Net. Try this function :
Private Function ValidatePhoneNumber(ByVal StringToTest As String) As Boolean
Dim expression As New Regex("(\(\d{3}\)|\d{3})[- ]\s?\d{3}[- ]\d{4}")
Dim match As Match = expression.Match(StringToTest)
If match.Success Then
Return True
Else
Return False
End If
End Function
Then you can call your function like this :
If TextBox1.Text <> String.Empty Then
If ValidatePhoneNumber(TextBox1.Text) Then
MsgBox("Correct phone number.")
Else
MsgBox("Not valid phone number")
End If
End If
If you want to learn more about regular expressions then I recommend you download a copy of Expresso (google it). It is an excellent tool for learning them.
Hope this helps.
|
|
|
|
|
Thank you Damian. I will try your example and look at regular expressions.
|
|
|
|
|
Regular expressions are the best way to go, as you can then embed some real phone number rules such as area code validation and so on.
Alternatively if you are only dealing with the one format allowed then I suggest you use a masked textbox so the end user can't even enter the wrong format.
|
|
|
|
|
Thanks Napolean Solo.
I will try regular expressions.
|
|
|
|