VB.NET - Get second hyperlink from string and set as LinkLabel text property - vb.net

I have a tool that takes in an email and sorts the data into the appropriate fields. In the email, there are normally two hyperlinks that launch the ticket editor in IBM notes. One is a local link and one is a server link. The following code is able to get the local link as it is the first hyperlink that contains 'notes://' but I need to get the one for the server as well, which also starts with 'notes://".
For i = 0 To lines.Count + 1
If lines(i).StartsWith("notes://") Then
StartLine = i
Exit For
End If
Next
link_OpenRequestUsingNotes.Text = lines(StartLine)
I thought of writing some code to check the line about it to see if it matches a specific string, maybe with Regex?
For the local link it needs to look for:
"using a Notes client (local replica)"
For the server link it needs to look for:
"using a Notes client (Server):"
The hyperlink is below this text so it would need to look for those and then get the text on the next line.
These links are then set as the text for two link labels that the users can press and go to that link.
If someone could please help me find a way to get the server link, it would be greatly appreciated.

You can use this code:
link_OpenRequestUsingNotes_Local.Text = "" 'fields for local link
link_OpenRequestUsingNotes_Server.Text = "" 'field for server link
For i = 0 To lines.Count - 1
If lines(i).StartsWith("using a Notes client (local replica)") Then
link_OpenRequestUsingNotes_Local.Text = lines(i + 1)
ElseIf lines(i).StartsWith("using a Notes client (Server)")
link_OpenRequestUsingNotes_Server.Text = lines(i + 1)
End If
If link_OpenRequestUsingNotes_Local.Text <> "" AndAlso link_OpenRequestUsingNotes_Server.Text <> "" Then
Exit For
End If
Next i

You could use code like this to find the first two links:
Dim notes = Function(x) x.StartsWith("notes://")
Dim index As Integer = lines.FindIndex(notes)
If index <> -1 AndAlso index < (lines.Count - 1) Then
Dim firstLink As String = lines(index + 1)
' ... do something with "firstLink"...
Debug.Print(firstLink)
index = lines.FindIndex(index + 2, notes)
If index <> -1 AndAlso index < (lines.Count - 1) Then
Dim secondLink As String = lines(index + 1)
' ... do something with "secondLink"...
Debug.Print(secondLink)
End If
End If

I managed to fix it myself
Just add 1 to i (StartLine = i + 1) to go to the line below!
'Notes Server Link
For i = 0 To lines.Count - 1
If lines(i).StartsWith("Click here to open the request using a Notes client (Server):") Then
StartLine = i + 1
Exit For
End If
Next
link_OpenServerLink.Text = lines(StartLine)

Related

Take list box selection, add value to other list box without allowing duplicates

I have two list boxes on a form I am making. The first list box is linked to a table with various company names. The goal I am after is after double clicking a companies name, the value is inserted in the second list box.
It worked fine until I tried to add code to prevent duplicates from appearing in the second list box, so you couldn't accidentally insert the same company twice. I have tried several different iterations, but with no luck. Anyone able to help with this one? My end goal would be for a msgbox to pop up alerting the user that duplicates are not allowed.
Private Sub ContractorLstbx_DblClick(Cancel As Integer)
Dim found As Boolean
found = False
Dim ID As Long
Dim Contractor As String
For Each newItem In Me.ContractorLstbx.ItemsSelected
For j = 0 To Me.SelectedContractorLst.ListCount - 1
If (Me!ContractorLstbx.ItemData(newItem).Column(1) = Me.SelectedContractorLst.ItemData(j).Column(1)) Then
found = True
Exit For
End If
Next j
If found = False Then
ID = Me.ContractorLstbx.ItemData(newItem)
Me.SelectedContractorLst.AddItem ContractorLstbx!.ItemData(newItem).Column(0) & ";" & Me!ContractorLstbx.ItemData(newItem).Column(1)
End If
found = False
Next newItem
End Sub
This is the full code for your solution. I tried it on test sample and working fine. just copy and paste the code. If you need your comparison to be case sensitive (I mean A <> a) then use Option Compare Binary as in my code below. If it is required to be case insensitive (A = a) just leave the default Option Compare Database or better force it using Option Compare Text
Option Compare Binary
Private Sub ContractorLstbx_DblClick(Cancel As Integer)
Dim found As Boolean
found = False
Dim ID As Long
Dim Contractor As String
For i = 0 To Me.ContractorLstbx.ItemsSelected.Count - 1
For j = 0 To Me.SelectedContractorLst.ListCount - 1
If (Me.ContractorLstbx.Column(1, Me.ContractorLstbx.ItemsSelected(i)) = Me.SelectedContractorLst.Column(1, j)) Then
found = True
Exit For
End If
Next j
If found = False Then
ID = Me.ContractorLstbx.ItemData(Me.ContractorLstbx.ItemsSelected(i))
Me.SelectedContractorLst.AddItem (ContractorLstbx.Column(0, Me.ContractorLstbx.ItemsSelected(i)) & ";" & Me.ContractorLstbx.Column(1, Me.ContractorLstbx.ItemsSelected(i)))
End If
found = False
Next i
End Sub

Access: Hiding the header on the first page of a section works initially...and then fails. Any thoughts?

I am using code based on widely used methods described here and elsewhere to suppress a page header on the first page of a report section in Access 2016. The code works fine for the first three sections but then removes the header on the second page rather than the first and gets the section page count wrong, including the first page of the following section in the total. If I eliminate the .visible=False statement, the section page numbering is fine, so it feels like removing the header section is messing up the pagination in a way that Access is not adjusting for? Has anyone else had this problem and if so, is there a solution?
Many thanks in advance
Simon
Private Sub PageHeaderSection_Format(Cancel As Integer, FormatCount As Integer)
Dim i As Integer
If Me.Pages = 0 Then
ReDim Preserve GrpArrayPage(Me.Page + 1)
ReDim Preserve GrpArrayPages(Me.Page + 1)
GrpNameCurrent = Me!txtCompany_name2
If GrpNameCurrent = GrpNamePrevious Then
GrpArrayPage(Me.Page) = GrpArrayPage(Me.Page - 1) + 1
GrpPages = GrpArrayPage(Me.Page)
For i = Me.Page - ((GrpPages) - 1) To Me.Page
GrpArrayPages(i) = GrpPages
Next i
Else
GrpPage = 1
GrpArrayPage(Me.Page) = GrpPage
GrpArrayPages(Me.Page) = GrpPage
End If
Else
Me!txtCheck = "Group Page " & GrpArrayPage(Me.Page) & " of " & GrpArrayPages(Me.Page)
If GrpArrayPage(Me.Page) = 1 Then
Me.PageHeaderSection.Visible = False
'Me.PageFooterSection.Visible = True
Else
Me.PageHeaderSection.Visible = True
'Me.PageFooterSection.Visible = False
End If
End If
GrpNamePrevious = GrpNameCurrent
End Sub

Copying a portion of a string using vba

I have to get username from MeetingItem.Recipient, I tried following to get it:
CStr(MeetingItem.Recipient.Address) and got this responce:
"/o=POST/ou=Zuerich/cn=Recipients/cn=eicherr" I have to do loop through all
recipients and get usernames for example if i do loor with code above Ill get:
"/o=POST/ou=Zuerich/cn=Recipients/cn=eicherr"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=kisslingie0e"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=katzensteink"
"/O=POST/OU=Bern/cn=Recipients/cn=junkerb"
"/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=tanzg6a7"
I need only last part of this strings, how can i do that?
note: kisslingie0e and tanzg6a7 this nicknames contains at the end unnecessary three characters that must also be avoided
Or is there another way to get usernames from MeetingItem.Recipient.Adress.
To get Email I did following:
For Each recip In recips
'Obtain the E-mail Address of a Recipient
Dim pa As Outlook.PropertyAccessor
Const PR_SMTP_ADDRESS As String = _
"http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
Set pa = recip.PropertyAccessor
Dim email as String
email = CStr(pa.GetProperty(PR_SMTP_ADDRESS))
Debug.Print email
End For
Use Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress to get the SMTP address.
Be prepared to handle nulls and errors.
To get the NT login name (domain account), read the PR_ACCOUNT MAPI property (DASL name http://schemas.microsoft.com/mapi/proptag/0x3A00001F) using Recipient.AddressEntry.PropertyAccessor.GetProperty.
You can also use Recipient.AddressEntry.GetExchangeUser().Alias
The easiest way to remove the leading text is to reverse the string and loop until you find a "/":
Dim email As String, username As String
Dim i As Integer
email = "/o=POST/ou=Group (FYHF23PDLT)/cn=Recipients/cn=kisslingie0e"
'Reverse string
email = StrReverse(email)
'Loop through string until / is found
For i = 1 To Len(email) Step 1
If Mid(email, i, 1) = "/" Then
Exit For
Else
username = username & Mid(email, i, 1)
End If
Next i
'Reverse username
username = StrReverse(username)
If you need to remove the "cn=", do something like this:
username = Split(username, "=")(1)
If the usernames never contain any numbers, you could remove the trail like this:
For i = 1 To Len(username) Step 1
'Loop until a number occurs
If IsNumeric(Mid(username, i, 1)) Then
'Use string until the number
username = Mid(username, 1, i - 1)
Exit For
End If
Next i
Here's another suggestion that works IF the source is consistent in having "Recipients/cn=" just prior to the desired string, it is followed by optionally stripping the last characters if they are numeric in the third or second to last character.
'find the location of constant, set vEM
vLoc = InStr(email, "Recipients/cn=")
vEM = Mid(email, vLoc + 14, 50)
'Check if third to last or second to last character is numeric
vOffset = 0
If IsNumeric(Mid(vEM, Len(vEM) - 2, 1)) Then
vOffset = 3
ElseIf IsNumeric(Mid(vEM, Len(vEM) - 1, 1)) Then
vOffset = 2
Else
vOffset = 0
End If
vEM = Left(vEM, Len(vEM) - vOffset)

Check if listbox contains textbox

I know I could use .FindString for this but for some reason it is not working.
Basically,if listbox items contains just a PART of textbox text,it does action.
Here's the example of not-working code :
Dim x As Integer = -1
x = ListBox1.FindString(TextBox1.Text)
If x > -1 Then
'dont add
ListBox2.Items.Add("String found at " & x.ToString)
Else
End If
The FindString method returns the first item which starts with the search string (MSDN). If you want to match the whole item, you would have to use FindStringExact (MSDN). If you want to perform more complex searches, you would have to iterate through all the elements in the ListBox.
UPDATE:
Code delivering the exact functionality expected by the OP.
For i As Integer = 0 To ListBox1.Items.Count - 1
If (ListBox1.Items(i).ToString.Contains(TextBox1.Text)) Then
ListBox2.Items.Add("String found at " & (i + 1).ToString) 'Indexing is zero-based
Exit For
End If
Next

How can I get the nickname and message from raw IRC data in vb.net

Well basically I've got a vb.net script connecting to IRC, and I'm working on making it a basic chat system, but I've run into a problem.
Say I receive this:
:nickname!name#tw-32151D9B.hsd1.vt.comcast.net PRIVMSG #channel :message
I want to grab specific information to output to the user.
I want to grab nickname and message
How can I go about doing this?
I thought about using regex, but I can't figure out how to make regex grab message since there's nothing after it.
I love IRC. The following code will do what you want assuming your raw data is in the variable strData.
Dim strNickName As String = String.Empty
Dim strMessage As String = String.Empty
Dim intToMessage As Integer = 0
Dim intParse As Integer = 0
intParse = InStr(strData, "!")
strNickName = Mid(strData, 2, (intStart - 2))
intToMessage = InStr(strData, "PRIVMSG #")
intParse = InStr(Mid(strData, intToMessage, (Len(strData) - intToMessage)), ":")
strMessage = Mid(strData, (intToMessage + intStart), (Len(strData) - (intToMessage + intStart - 1)))
You can use RegEx to get everything between the first : and !
(?<=:).*?(?=!)
and then look for everything between the last #channel : and the end of the line
(?<=#channel :).*?(?=$)
This is simple but should take into account that someone may use a semi-colon (:) in the message.