|
You have not explained in any detail what you mean by "read line by line from Web Browser tool". However, I would suggest using the WebBrowser Class[^], which allows you to interact with any internet site.
|
|
|
|
|
Did you mean from the WebBrowser control? Or from any browser-application that the user has opened?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Let's say that I have an object called Employee with the properties Name and Department.
Next I have a List(Of Employee) with say 5 employees in it. Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps they are all members of the same department, etc. This is an unknown.
How can I get the distinct departments from my list ?
There is List.Distinct, but it seems I can only get distinct entire objects (employees) through that.
Any help much appreciated.
Best regards,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Probably by creating another List (or other collection class) which only contains departments. Go through all your employee records adding the department to the second list.
|
|
|
|
|
|
Johan Hakkesteegt wrote: Each of these 5 employees are member of one of 10 possible different departments. Perhaps they are each member of a different department, perhaps
they are all members of the same department, etc. This is an unknown. One employee in one department, not one employee in multiple departments. Check.
Imports System.Collections.Generic
Module Module1
Class Employee
Public Property Name As String
Public Property Department As String
End Class
Sub Main()
Dim zeList As New List(Of Employee)
zeList.Add(New Employee() With {.Name = "John", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Jane", .Department = "IT"})
zeList.Add(New Employee() With {.Name = "Pete", .Department = "Management"})
Dim departments As IEnumerable(Of String) = zeList.Select(Function(e) e.Department).Distinct()
For Each department As String In departments
Console.WriteLine(department)
Next
Console.ReadLine()
End Sub
End Module
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Last night I woke up and figured Richard's answer myself, but this is the "one-liner" that I was after.
Thanks Eddy !
My advice is free, and you may get what you paid for.
|
|
|
|
|
Eddy Vluggen wrote: zeList.Select(Function(e) e.Department).Distinct()
I looked and looked and wondered where the Function(e) comes from and what is it doing x=>
So I have not looked at VB since before linq was invented.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
How do I keep a class object "alive" in a Windows Service?
I have a simple class object (clsWatcher) that monitors a folder using an instantiation of the FileSystemWatcher class. It works great. When a change is made to the folder being "watched" it triggers a log entry.
When I use the clsWatcher as a form-level object in a standard Windows Forms EXE, it works perfectly as long as the windows form is open. When the form closes, it dies and no watching is done. Perfect.
When I transfer this class to a SYSTRAY application, it continues to work correctly. As long as the SYSTRAY application is not exited, the clsWatcher works properly. When I exit the SYSTRAY application, it dies and no watching is done. Perfect.
When I transfer this class to a Windows Service, it does not work as desired. The service starts, the clsWatcher instantiates, and then the service "finalizes" and the clsWatcher dies even though the service is still "started" and no errors were logged (I have an Application Log feature to send messages that can be observed during start up and errors.)
How do I keep the service/application "running" in order to keep the instantiated clsWatcher object alive?
|
|
|
|
|
ToolTimeTabor wrote: and then the service "finalizes" What does that mean? Does the service crash? Is yourservice.exe still in the list of processes in the task manager ("show processes of all users")?
|
|
|
|
|
ToolTimeTabor wrote: How do I keep the service/application "running" Create an infinite loop (and exit if Windows is shutting down). A service doesn't have a loop that keeps the app alive until someone "closes" it, as it should not be closed.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have a very similar windows service that does exactly what you are describing.
Dim watcher As New FileSystemWatcher()
watcher.Path = gsWatcherPath
watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
watcher.Filter = "*.txt"
AddHandler watcher.Created, AddressOf OnChanged
watcher.EnableRaisingEvents = True
Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
Call ProcessFile_Master(e.FullPath)
End Sub
Once you instantiate the FileSystemWatcher, there is nothing else to do, no loops, nothing extra.
The Sub, OnChanged, gets fired for each file that is changed in the "watched" directory.
Hope this helps.
|
|
|
|
|
I am trying to write code for multiple if/and statements, but don’t really know how. Any help would be very much appreciated!
I need the code to loop through these statements and enter the correct information in cell M5.
IF C9= ”SHIP EXACT” AND G13<c13, then="" m5="”ENTER" remake”
if="" c9="”" no="" backorders="" on="" stock="" unless="" zero="" were="" shipped”="" and="" g13<c13,="" remake="" required”
if="" ship="" tolerance”="" g13="" c13="">10%, then M5= “ENTER REMAKE”
IF C9= ”5% Ship Tolerance” AND G13/C13>5%, then M5= “ENTER REMAKE”
|
|
|
|
|
First, phase them in your natural language, such as English:
If I score 90 and above,
then my grade is 'A'
Else If I score 80 and above (but below 90 - this one can be omitted as it would have been considered in the first if statement)
then my grade is 'B'
else If I score 70 and above
then my grade is 'C'
...
Else (last condition no need to have condition, it is understood to be none of the above)
the my grade is 'F'
Finally, print out my grade
Once you are satisfied with these statement, then translate them to vb.net code.
refer: If...Then...Else Statement (Visual Basic)[^]
|
|
|
|
|
You should use
if [condition] then
[result]
else if [condition2] then
[result2]
end if
Since when is being together a prerequisite for being in love with someone?
|
|
|
|
|
Hi guys,
i have codes that displaying different images as gif in one picturebox. My problem is, how can i save this .gif i mydocuments?
here is my codes..
thank you in advance!
Public Class Form7
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.BackColor = Color.Ivory
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox1.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox2.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox3.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox4.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox5.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox6.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox7.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
TextBox8.Text = (OpenFileDialog1.FileName)
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Timer1.Enabled = True
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim max As Integer = 500
Dim rnd As New Random
Dim rand As Integer = rnd.Next(5, max + 1)
Dim i As Integer = 1
Dim number(max - 1) As Integer
For i = 0 To max - 1
If number(i) = rand Then
rand = rnd.Next(1, max + 1)
i = -1
ElseIf number(i) = 0 Then
number(i) = rand
rand = rnd.Next(1, max + 1)
If i = max - 1 Then
Exit For
End If
i = -1
End If
Next
Timer1.Interval = number(i)
i += 1
ChangeImage()
End Sub
Private Sub ChangeImage()
Static Dim iImage1 As Integer
Select Case iImage1
Case 0
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox1.Text)
iImage1 += 1
Case 1
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox2.Text)
iImage1 += 1
Case 2
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox3.Text)
iImage1 += 1
Case 3
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox4.Text)
iImage1 += 1
Case 4
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox5.Text)
iImage1 += 1
Case 5
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox6.Text)
iImage1 += 1
Case 6
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox7.Text)
iImage1 += 1
Case 7
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox8.Text)
iImage1 += 1
Case 8
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox9.Text)
iImage1 += 1
Case 9
PictureBox1.Visible = True
PictureBox1.Image = Image.FromFile(TextBox10.Text)
iImage1 = 0
End Select
End Sub
End Class
modified 13-May-14 3:20am.
|
|
|
|
|
You have already asked once - please don't repost
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
on my previous post, i'm asking help for making .gif using different images in one picturebox. And to my latest post, i'm asking how can i save .gif(in picturebox) as .gif to mydocuments/computer. It's totally different although its related to ".gif"
|
|
|
|
|
You could use the following code to save a GIF image in a Picture Box(PictureBox1)
PictureBox1.Image.Save(SpecialDirectories.MyDocuments + "\MyGif.gif", ImageFormat.Gif)
Note: Import the following
System.Drawing.Imaging
Microsoft.VisualBasic.FileIO
|
|
|
|
|
Where in the above code is the part that saves the image? Please do not just dump a lot of code and expect us to work out what it is supposed to do; provide proper detailed explanation.
|
|
|
|
|
hello everyone
I need your help to achieve my MapWinGIS project Visual Basic.NET,
I wonder how to write a procedure that allows viewing the positions on the map with the symbology of my choice and displayed according to the selection in the legend group using the CheckedChanged event categories.
thank you
|
|
|
|
|
hi, will somebody give me a code in vb which will be able to receive sms using a usb gsm modem?
please help. thanks.
|
|
|
|
|
No. That's not how it works around here.
We'll help you with problems with YOUR code, but not write it for you.
You're not writing our code for us while we're writing your code for you, so...
|
|
|
|
|
'class code
Imports System.IO.Ports
Imports System.Threading
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
ReadThread = New Thread(AddressOf ReadPort)
End Sub
Public Sub SendSMS(ByVal CellNumber As String, ByVal SMSMessage As String)
Dim MyMessage As String = Nothing
If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
If IsOpen = True Then
SMSPort.WriteLine("AT")
Thread.Sleep(1000)
SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'setting modem for sms mode
Thread.Sleep(1000)
'SMSPort.WriteLine("AT+CSCA=""+254722500059" & vbCrLf) 'setting the message service center number
SMSPort.WriteLine("AT+CMGS=""" & CellNumber & """" & vbCrLf)
Thread.Sleep(1000)
'SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCrLf)
_ContSMS = False
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
Thread.Sleep(1000)
_Continue = False
RaiseEvent Sending(False)
'MessageBox.Show("Successfully sent")
End If
End Sub
Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing
Try
Catch ex As Exception
While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (
SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize)
SerialIn =
SerialIn & System.Text.Encoding.ASCII.GetString(
RXBuffer)
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Try
End Sub
Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property
Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub
Public Sub Close()
If IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
'window form
'Form Code
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports
Imports mordemsms.SMSCOMMS
Public Class Form1
Private Sub sendbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sendbtn.Click
Dim sms As SMSCOMMS
sms = New SMSCOMMS("COM12")
sms.Open()
sms.SendSMS(TextBox1.Text, TextBox2.Text)
sms.Close()
End Sub
End Class
ok. this is the code i have written to receive an sms. i want to add the function to receive a sms on the same modem. i am unable to go on. somebody help please.
|
|
|
|
|
Hello !
I'm using Entity framework 6 with Sql server 2008r2.
But I have noticed that even a small query ( with only 2-3 records ) need about 25 seconds to execute.
This happens everytime when I execute a query for the first time.The second time is more fast. But if I open another form and execute another query , there's again a delay.
what can I do ?
Thank you !
|
|
|
|