s7.NET error tryind to read or write a var in vb.net - vb.net

When i try to read some value appear de error on image...
I already tried diferent ways and the result it´s all time the same(comment lines).
How i can read a value in vb.net and s7.1200?
thanks
error vb.net
Option Strict Off
Option Explicit On
Imports S7.Net
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WinForms
Imports System.Data
Imports VB = Microsoft.VisualBasic
Imports Microsoft.VisualBasic.PowerPacks
Imports System.Xml
Imports System.Text
Imports System.IO
Imports System.Security.Cryptography
Imports System.Threading
Module PLC_InOut
Public Sub PLCInOuts()
' Dim Result As BitArray()
' Result = PLC.Read("DB8.DBW0")
'\\\\\\\\\\\\\\Inputs
' Result = PLC.Read(DataType.DataBlock, 8, 0, VarType.Bit, 0, 16)
'Result = PLC.Read(DataType.DataBlock, 8, 0, VarType.Byte, 1, 0)
' Result = PLC.Read("DB7.DBX0.0")
'Dim Value1 As Byte = PLC.Read("DB8.DBW0")
Dim u1 As System.UInt16 = PLC.Read("DB8.DBW0")
Dim b1() As Byte = BitConverter.GetBytes(u1)
If test1_out Then
' PLC.Write(DataType.Output, 0, 0, VarType.Bit, True)
'PLC.Write("O0.0", 1)
'PLC.Write("%M47.6", True)
' PLC.Write("DB7.DBX0.0", True)
'PLC.WriteBit(DataType.DataBlock, 7, 0, 0, True)
End If
' ("db8.dbx0.0")
'\\\\\\\\\\\\\\outputs
' PLC.WriteBit(DataType.DataBlock, 7, 0, 0, test1_out)
End Sub
End Module
plc var_code

The problem was the plc hardware was not completely downloaded after changed the plc proprieties-protection & security parameters

Related

Replace exact word

I want to convert this string:
"http://www.example.com/sms.aspx?user=joey&pass=joey123&mbno=9792234567&msg=Test"
to this:
"http://www.example.com/sms.aspx?user={0}&pass={1}&mbno={2}&msg={3}"
But I am getting output like this:
"http://www.example.com/sms.aspx?user={0}&pass={0}123&mbno={2}&msg={3}".
I have used the following line of code for replacing:
Dim SMSUrlStr As String="http://www.example.com/sms.aspxuser=joey&pass=joey123&mbno=9792234567&msg=Test"
e.g. Regex.Replace(SMSUrlStr, joey, {0})
but it is also replacing "joey" from "joey123".
How can I make the replacement more specific?
Instead of looking at the input as a string, you could regard it as a URI. There are methods in the framework to work with URIs, and from that we can rebuild it into the form you need:
Imports System.Collections.Specialized
Imports System.Text
Imports System.Web
Module Module1
Sub Main()
Dim s = "http://www.example.com/sms.aspx?user=joey&pass=joey123&mbno=9792234567&msg=Test"
Dim u = New Uri(s)
Dim q = HttpUtility.ParseQueryString(u.Query)
Dim newQ = q.AllKeys.Select(Function(p, i) p & "={" & i & "}")
Dim newS = u.GetLeftPart(UriPartial.Path) & "?" & String.Join("&", newQ)
Console.WriteLine(newS)
Console.ReadLine()
End Sub
End Module
Outputs:
http://www.example.com/sms.aspx?user={0}&pass={1}&mbno={2}&msg={3}

Convert a string into a stream correctly

Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Namespace WindowScriptingObject
<Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _WindowScriptingObject
<DispId(1)> Function Decompress(ByVal value as String) As String
End Interface
<Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
ClassInterface(ClassInterfaceType.None), _
ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
Implements _WindowScriptingObject
Public WindowScriptingObject()
Public Function Decompress(ByVal value as string) As String Implements _WindowScriptingObject.Decompress
Dim x As String
' on error resume next
Dim xstream As New MemoryStream(Encoding.Unicode.GetBytes(value))
Dim mem2 As New IO.MemoryStream()
'Dim streamMe As New StreamWriter(mem2,Encoding.UTF8)
'streamMe.Write(value)
'StreamMe.Close()
'mem2.Position=0
Dim gz As New System.IO.Compression.GZipStream(xstream, IO.Compression.CompressionMode.Decompress)
Dim sr As New IO.StreamReader(gz)
x = sr.ReadLine
sr.Close()
'End Using
Decompress = x
End Function
End Class
End Namespace
I verified the string I sent over contains the correct values from my VBScript. However, its says the header is bad.
The above code has to be compiled for testing
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:library /out:"%userprofile%\desktop\t.dll" "%userprofile%\desktop\t.txt" /verbose
Then registered
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm" /codebase "%userprofile%\desktop\t.dll" /tlb:"%userprofile%\desktop\t.tlb" /v
Then invoked
c:\windows\SysWOW64\cscript.exe old.vbs
I put code in to read the contents from a file, even though that is not the end goal. When I did that the file decompressed correctly.
Dim xstream As New MemoryStream(Encoding.Unicode.GetBytes(value))
This line hear seems to be incorrectly converting my string to a stream.
The goal is to send a compressed string and return a uncompressed string.
The code above is invoked with this code
Const adTypeBinary = 1
Set wso = CreateObject("WindowScriptingObject")
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "e:\download\result.gz"
'objStream.Charset = "Windows-1252"
x = objStream.Read(900)
objStream.Close
For i=1 To Len(x)
t = t & Chr(AscW(Mid(x, i, 1)) And 255)
t = t & Chr((AscW(Mid(x, i, 1)) And 65280)/256)
Next
MsgBox wso.Decompress(t), , "vbs"
I tried this, and even converted the string to base64 to get it work.
Dim gzBuffer As Byte() = Convert.FromBase64String(value)
Using ms As New MemoryStream()
Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0)
ms.Write(gzBuffer, 4, gzBuffer.Length - 4)
Dim buffer As Byte() = New Byte(msgLength - 1) {}
ms.Position = 0
Using zipStream As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)
zipStream.Read(buffer, 0, buffer.Length)
End Using
Decompress=System.Text.Encoding.Unicode.GetString(buffer, 0, buffer.Length)
End Using
The data did not get converted correctly as I still have magic number in GZip header is not correct.
Dumped base64 encoded value into online decoder, and the string I passed in matches to decoded value.
Version 2
Forces me to base64 encode it, but then it works.
How do I remove this annoyance.
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Namespace WindowScriptingObject
<Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _WindowScriptingObject
<DispId(1)> Function Decompress(ByVal value as String) As String
End Interface
<Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
ClassInterface(ClassInterfaceType.None), _
ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
Implements _WindowScriptingObject
Public WindowScriptingObject()
Public Function Decompress(ByVal value as string) As String Implements _WindowScriptingObject.Decompress
Dim x As String
' on error resume next
Dim gzBuffer As Byte() = Convert.FromBase64String(value)
Using ms As New MemoryStream()
Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0)
ms.Write(gzBuffer, 0, gzBuffer.Length)
Dim buffer As Byte() = New Byte(msgLength - 1) {}
ms.Position = 0
Using zipStream As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)
zipStream.Read(buffer, 0, buffer.Length)
End Using
Decompress=System.Text.Encoding.ASCII.GetString(buffer, 0, buffer.Length)
End Using
' Dim xstream As New MemoryStream(value.ToArray())
Dim mem2 As New IO.MemoryStream()
'Dim streamMe As New StreamWriter(mem2,Encoding.UTF8)
'streamMe.Write(value)
'StreamMe.Close()
'mem2.Position=0
'Dim gz As New System.IO.Compression.GZipStream(xstream, IO.Compression.CompressionMode.Decompress)
'Dim sr As New IO.StreamReader(gz)
' x = sr.ReadLine
'sr.Close()
'End Using
'Decompress = x
End Function
End Class
End Namespace
Update this code works except the output size is 500K, and there's only 3100 bytes of text.
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Namespace WindowScriptingObject
<Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _WindowScriptingObject
<DispId(1)> Function Decompress(ByVal value as string) As String
End Interface
<Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
ClassInterface(ClassInterfaceType.None), _
ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
Implements _WindowScriptingObject
Public WindowScriptingObject()
Public Function Decompress(ByVal value as string) As String Implements _WindowScriptingObject.Decompress
' on error resume next
Dim gzBuffer() As Byte = System.Text.Encoding.Default.Getbytes(value)
Using ms As New MemoryStream()
Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0)
ms.Write(gzBuffer, 0, gzBuffer.Length)
msgbox(msgLength)
Dim buffer As Byte() = New Byte(msgLength - 1) {}
ms.Position = 0
Using zipStream As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)
zipStream.Read(buffer, 0, buffer.Length)
End Using
Decompress=System.Text.Encoding.Default.GetString(buffer, 0, buffer.Length)
End Using
End Function
End Class
End Namespace
For some reason msgLength is 559,903 in size, and the decompressed text is roughly 3100 bytes. This means BitConverter.toint32 is malfunctioning as gzBuffer is 865 bytes. The final output size is only know to the GZIPStream function as the text is compressed an the input size has no correlation to the output size.
The other question(s)
can this be coded more efficiently?
What can I do to prevent malicious code injection?
Limit output to the correct size?
If I add new functions do I need more Guid's?
How do I generate a new Guid?
In code block #3 I convert X to a string t and transfer value without conversion.
The output size seems to be based on bad information.
intOutputLength=zipStream.Read(buffer, 0, buffer.Length)
End Using
Decompress=System.Text.Encoding.Default.GetString(buffer, 0, intOutputLength)
At least this reduces the amount of data return to the main program.
Dim msgLength As Integer = BitConverter.ToInt32(gzBuffer, 0)
If I read this correctly the msgLength is determined by the first 4 characters of the input stream? Since the GZip header is always 1f 8b 08 00 this seems to be a horrible idea. If the output is every greater than 559k seems like a buffer overflow just waiting to happen.
I think this solves the terrible buffer size issue.
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports System.IO
Imports System.IO.Compression
Imports System.Text
Namespace WindowScriptingObject
<Guid("7448E08D-ED0F-4E23-B528-91937BB41756"), _
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _WindowScriptingObject
<DispId(1)> Function Decompress(ByVal value as string) As String
End Interface
<Guid("B146BF9E-78FC-4DB0-ABFE-9FF026B43E4D"), _
ClassInterface(ClassInterfaceType.None), _
ProgId("WindowScriptingObject")> Public Class WindowScriptingObject
Implements _WindowScriptingObject
Public WindowScriptingObject()
Public Function Decompress(ByVal value as string) As String Implements _WindowScriptingObject.Decompress
' on error resume next
Dim gzBuffer() As Byte = System.Text.Encoding.Default.Getbytes(value)
dim intOutputLength as integer
Dim intBlock as integer
Decompress=""
Using ms As New MemoryStream()
Dim msgLength As Integer = 4096
ms.Write(gzBuffer, 0, gzBuffer.Length)
Dim buffer As Byte() = New Byte(4096) {}
ms.Position = 0
Using zipStream As New System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Decompress)
intOutputLength=0
intBlock=4096
while intBlock=4096
intBlock=zipStream.Read(buffer, 0, buffer.Length)
Decompress+=System.Text.Encoding.Default.GetString(buffer, 0, intBlock)
intOutputLength+=intBlock
end while
End Using
End Using
End Function
End Class
End Namespace
I was able to get your code working by changing the VB.NET function and interface to look like this (mainly changing the parameter type):
<Guid("7448E08E-ED0F-4E23-B528-91937BB41756"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface _WindowScriptingObject
<DispId(1)> Function Decompress(ByVal value As Byte()) As String
End Interface
Public Function Decompress(ByVal value As Byte()) As String Implements _WindowScriptingObject.Decompress
Using xstream As New MemoryStream(value)
Using gz As New System.IO.Compression.GZipStream(xstream, IO.Compression.CompressionMode.Decompress)
Using sr As New IO.StreamReader(gz)
Return sr.ReadLine()
End Using
End Using
End Using
End Function
My test VBS looks like this
Const adTypeBinary = 1
Dim wso
Set wso = CreateObject("WindowScriptingObject")
Dim objStream, x
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile "c:\users\bluem\desktop\Notes.txt.gz"
x = objStream.Read(342737)
objStream.Close
WScript.StdOut.WriteLine wso.Decompress((x))
I'm not entirely sure why I needed to enclose the x parameter in two sets of parentheses, but I think it has something to do with forcing the parameter to be passed by value instead of by reference and helps it convert to a byte array. I was getting an error before I added the extra pair of parentheses.
Edit:
To answer some of your other questions:
I don't think you need to create a new GUID for a new function, only for a new interface or class.
To create a new GUID you can just copy an existing one and change part of it (to digits between 0 and F inclusive) to be unique, or you can go to https://www.guidgenerator.com/ or you can select "Create GUID" from Visual Studio's Tools menu.
If you can clarify your data length problem based on the new code (if a problem still exists), I might be able to answer.
It's been too long since I've written vbscript, so I don't know enough anymore to give fixes. However, I can point out some serious flaws in the vbscript part of this code.
It starts by reading up to 900 bytes from a .gz file, regardless of the actual length of file. Anything longer than a mere 900 bytes will be not read.
It performs this read in binary mode. Binary mode ignores any character set or encoding info, and just reads raw bytes, which is appropriate for a .gz file. However, the next thing that happens with this data is using the Len() function, which is for strings, not binary data; Len() is not the appropriate function here. Additionally, the data is next used in the For loop via the Mid() function. Mid() is likewise intended only for strings, and the x variant is not a string. vbscript string objects are more than just the raw characters; they include meta data for things like encoding, length, and character buffers, and those string functions rely on the objects being constructed properly with all metadata.
There's no way this vbscript produces correct results. Until that is resolved, there's no point in even looking at the vb.net code. Again, I'm too far gone to suggest a real solution, but I recommend trying to pass an unaltered byte array to the .Net side, rather than a string.

VB.net add a header/footer to every page of a PDF using iText7

I am trying to create a PDF with a header and footer. Both header and foot are images. Since my pdf creates a random amount of pages I need to automaticly add it to every page. I know I need to use some sort of eventhandler. Unfortunately I can't find any examples in the vb.net language, I only can find java/C# examples and I am really bad at reading/converting these language to vb.net. I am not a expert yet at programming.
Can anyone point me in the right direction.
Edit4: Removed random stuff no longer need to answer my question.
This piece of code below is all I got on creating the PDF itself.
Imports System.IO
Imports MySql.Data.MySqlClient
Imports iText.Kernel
Imports iText.Kernel.Pdf
Imports iText.Kernel.Font
Imports iText.Kernel.Font.PdfFont
Imports iText.Kernel.Font.PdfFontFactory
Imports iText.IO.Image
Imports iText.IO.Image.ImageData
Imports iText.IO.Image.ImageDataFactory
Imports iText.Layout.Element.Image
Imports iText.Layout
Imports iText.Layout.Element
Imports iText.Layout.Element.Table
Imports iText.Kernel.Events.Event
Imports iText.Kernel.Events.PdfDocumentEvent
Imports iText.Kernel.Geom.PageSize
Imports iText.Kernel.Geom.Rectangle
Imports iText.Kernel.Pdf.PdfDocument
Imports iText.Kernel.Pdf.PdfNumber
Imports iText.Kernel.Pdf.PdfWriter
Imports iText.Kernel.Pdf.Canvas.PdfCanvas
Imports iText.Kernel.Pdf.Canvas.PdfCanvasConstants
Imports iText.Kernel.Pdf.Xobject.PdfFormXObject
Imports iText.Layout.Canvas
Imports iText.Layout.Document
Imports iText.Layout.Style
Imports iText.Layout.Layout.LayoutArea
Imports iText.Layout.Layout.LayoutContext
Imports iText.Layout.Layout.LayoutResult
Imports iText.Layout.Renderer.CellRenderer
Imports iText.Layout.Renderer.DrawContext
Imports iText.Layout.Renderer.TableRenderer
Imports iText.Signatures.PdfSignatureAppearance
Public Sub NewiText7PdfCreation()
'Dim dest As String = "\\test\verkoop\offerte v2\Offerte " & offertenummer2 & "-" & offertenummer & " " & TextBox2.Text & ".pdf"
Dim dest As String = "iText7Test.pdf"
Dim writer As PdfWriter = New PdfWriter(dest)
Dim pdf As PdfDocument = New PdfDocument(writer)
Dim doc As Document = New Document(pdf)
Dim font As PdfFont = PdfFontFactory.CreateFont("C:\Windows\Fonts\calibri.ttf")
'header
Dim headerlocation As String = "Resources\Offerte-NL.png"
Dim headerimage2 As Image = New Image(ImageDataFactory.Create(headerlocation))
doc.Add(headerimage2)
'klant gegevens
doc.Add(New Paragraph("Debiteur gegevens").SetFont(font))
Dim debnr As String = TextBox1.Text
Dim bn As String = TextBox2.Text
Dim adr As String = TextBox3.Text
Dim pcwp As String = TextBox4.Text
Dim cp As String = TextBox5.Text
Dim km As String = TextBox6.Text
Dim klanttable As New Table(2)
klanttable.SetMaxWidth(350)
klanttable.SetHorizontalAlignment(0)
klanttable.SetFont(font)
klanttable.SetFontSize(8)
klanttable.SetWidth(350)
klanttable.SetMinWidth(120)
klanttable.AddCell("Debiteur nr.: ")
klanttable.AddCell(debnr)
klanttable.AddCell("(Bedrijfs)naam:")
klanttable.AddCell(bn)
klanttable.AddCell("Adres:")
klanttable.AddCell(adr)
klanttable.AddCell("Postcode & woonplaats:")
klanttable.AddCell(pcwp)
klanttable.AddCell("Contactpersoon:")
klanttable.AddCell(cp)
klanttable.AddCell("Kenmerk:")
klanttable.AddCell(km)
Dim cell As New Cell
klanttable.SetMarginTop(10)
klanttable.SetMarginBottom(10)
doc.Add(klanttable)
doc.Close()
End Sub
Edit:
Found a nice tutorial on the iText website.
https://developers.itextpdf.com/content/itext-7-jump-start-tutorial-net/chapter-3-using-renderers-and-event-handlers
I just don't quite get how to insert that piece of code into my own piece of code. I think I need to create a new class that handles the event.
But how do I need to call this event.
I just add the follow line to my code:
Implements IEventHandler
And this new sub.
Public Sub HandleEvent([event] As [Event]) Implements IEventHandler.HandleEvent
Throw New NotImplementedException()
End Sub
How do I adjust the sub to handle the page-start event and page-end event ( if it's even still called that way)
Edit: I just imported all the stuff just to be sure I got everything. When everything is working fine I am just gonna remove everything not being used.
With some efforts, I could implement PAGE_END event in vb.net. Here is the code for you.
(A) In main module create pdf routine add:
*Dim HandlerRLA = New VariableHeaderEventHandlerRLA
PDFfile.AddEventHandler(PdfDocumentEvent.END_PAGE, HandlerRLA)*
(B) Add anlother class after End Class. You may add text/paragraph as per requirement. I have used image as Header and Footer on specific pages.
Public Class VariableHeaderEventHandlerRLA
Implements IEventHandler
Dim header As String
Dim doc As PdfDocument
Public Sub TextFooterEventHandler(ByRef doc As PdfDocument)
Me.doc = doc
End Sub
Public Sub HandleEvent([event2] As [Event]) Implements IEventHandler.HandleEvent
Dim docEvent1 As PdfDocumentEvent = event2
Dim canvas1 As PdfCanvas = New PdfCanvas(docEvent1.GetPage())
Dim pageSize1 As iText.Kernel.Geom.Rectangle = docEvent1.GetPage().GetPageSize()
'Dim canvas As Canvas = New Canvas(docEvent.GetPage(), New iText.Kernel.Geom.Rectangle(0, 0, pageSize.GetWidth(), pageSize.GetHeight))
Dim PDoc1 As PdfDocument = docEvent1.GetDocument()
Dim Page1 = docEvent1.GetPage()
Dim PageNo1 As Integer = PDoc1.GetPageNumber(Page1)
If PageNo1 > 1 Then
Dim imageFile, BottomImage As String
imageFile = "path to image folder\secondtop.bmp"
Dim data3 = ImageDataFactory.Create(imageFile)
BottomImage = "path to image folder\secondbottom2.bmp"
Dim data4 = ImageDataFactory.Create(BottomImage)
Dim Ratio = data3.GetHeight / data3.GetWidth
Dim rect As iText.Kernel.Geom.Rectangle = New iText.Kernel.Geom.Rectangle(0, 784, 595, 595 * Ratio)
With canvas1
.AddImage(data3, 0, 784, 595, 0)
'.AddImageFittedIntoRectangle(data3, rect, 0)
Ratio = data4.GetHeight / data4.GetWidth
rect = New iText.Kernel.Geom.Rectangle(0, 0, 595, 595 * Ratio)
'.AddImageFittedIntoRectangle(data4, rect, 0)
.AddImage(data4, 0, 0, 595, 0)
End With
End If
'Throw New NotImplementedException()
End Sub
End Class

unable to list Evernote tags in vb.net

I am unable to list the tags associated to a evernote note in vb.net
The note correctly displays its title, but the tagnames are [nothing]...
What am I doing wrong? Here's the code I used:
Imports System
Imports EvernoteSDK
Imports System.IO
Imports System.Collections.Generic
Imports EvernoteSDK.Advanced
Public class main
dim myResultsList As List(Of ENSessionFindNotesResult)
ENSession.SetSharedSessionConsumerKey("KEY", "SECRET")
If ENSession.SharedSession.IsAuthenticated = False Then
ENSession.SharedSession.AuthenticateToEvernote()
myResultsList = ENSession.SharedSession.FindNotes(ENNoteSearch.NoteSearch("text to find"), Nothing, ENSession.SearchScope.All, ENSession.SortOrder.RecentlyUpdated, 500)
' Given a NoteRef instance, download that note.
Dim myDownloadedNote As ENNote = ENSession.SharedSession.DownloadNote(myResultsList(0).NoteRef)
For i As Integer = 0 To myDownloadedNote.TagNames.Count - 1
Note_tags_txt.Text = Note_tags_txt.Text + " " + myDownloadedNote.TagNames.Item(i)
Next
end class
You won't get the note tag names back with the note - you'll get the tag guids. You can either
1. use listTags to cross-reference the tag guids to names, or
2. use getNoteTagNames to get the note tag names directly.
Well... I eventually figured it out myself... I have to remark that the vb.net SDK for Evernote is poorly documented.
First than all I had to have the following Imports
Imports System
Imports EvernoteSDK
Imports System.IO
Imports System.Collections.Generic
Imports EvernoteSDK.Advanced
Imports EvernoteSDK.Advanced.ENNoteStoreClient
Imports Evernote.EDAM.NoteStore
Imports Evernote.EDAM.Type
Imports Evernote.EDAM.UserStore
Then I have to Authorize the application in two steps:
ENSession.SetSharedSessionConsumerKey("KEY", "SECRET")
ENSessionAdvanced.SetSharedSessionConsumerKey("KEY", "SECRET")
If ENSession.SharedSession.IsAuthenticated = False Then
ENSession.SharedSession.AuthenticateToEvernote()
End If
Where "KEY" and "SECRET" is the API Token assigned by Evernote.
Since I did use the wrong code, I had to clear all files in c:\users\%username%\appdata\local\evernote, if I do not do so I get an EDAM error.
Saying that the notes I am interested in getting the tag names comes from a result of a search for the string "textToFind", I can get all the matching notes with:
Dim myResultsList As List(Of ENSessionFindNotesResult) = _
ENSession.SharedSession.FindNotes(ENNoteSearch.NoteSearch(textToFind), Nothing, _
ENSession.SearchScope.All, ENSession.SortOrder.RecentlyUpdated, 500)
The above search can be restricted to a specific notebook by replacing "nothing" with the corresponding notebook.
Say I am interested in the tags of the first note of my zero-based list of results, then:
Dim note_ref As ENNoteRef = myResultsList(0).NoteRef
' Given a NoteRef instance, download that note.
Dim myDownloadedNote As ENNote = ENSession.SharedSession.DownloadNote(note_ref)
Dim s = ENSessionAdvanced.SharedSession.NoteStoreForNoteRef(note_ref)
Dim Tags_List As List(Of String) = s.GetNoteTagNames(note_ref.Guid)
In this way Tags_List will contain a list of tag names as strings. Then the rest of my code:
For i As Integer = 0 To Tags_List.Count - 1
If i = 0 Then
Note_tags_txt.Text = Tags_List.Item(0)
Else
Note_tags_txt.Text = Note_tags_txt.Text + " - " + Tags_List.Item(i)
End If
Next i
Where Note_Tags_Txt is a label I created on my form.
I hope this helps someone.

error with joining two lines in autocad using vb.net

Imports System.Drawing
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Namespace sweeping
Public Class Testing
<CommandMethod("jointwolines")>
Public Shared Sub jointwolines()
Dim line1, line2 As Line
Dim pll As polyline
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim bt As BlockTable
Dim btr As BlockTableRecord
Using tr As Transaction = db.TransactionManager.StartTransaction()
line1 = New line(New point3d(0, 0, 0), New point3d(100, 0, 0))
line2 = New line(New point3d(100, 0, 0), New point3d(100, 100, 0))
bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
btr = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
pll = line1.joinentity(line2)
btr.AppendEntity(pll)
tr.AddNewlyCreatedDBObject(pll, True)
tr.Commit()
End Using
End Sub
End Class
End Namespace
Part of my autocad customization requires me to join two lines into an entity. I have been trying really hard to get it done. But, I m facing a few obstacles.
The first one:
pll = line1.joinentity(line2)
the line above gives me a warning 'expression does not produce a value'.
What I understand is that the joinentity function returns void, so I cant assign it to the pll of polyline type. However, I need to write the polyline formed by joining two lines to the autocad database. How do I go about achieving that?
Second one:
Whenever I build and debug the code to test it with Autocad, the same line
pll = line1.joinentity(line2)
will generate error and break the code. I tried to understand the error message, but to no avail. It reads
An exception of type 'Autodesk.AutoCAD.Runtime.Exception' occurred in AcdbMgd.dll but was not handled in user code
Additional information: eNotApplicable
If there is a handler for this exception, the program may be safely continued.
How to solve this problem? Can someone please explain and help me?
Edited code(but problem still persist):
Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.ApplicationServices.DocumentExtension
Namespace sweeping
Public Class Testing
<CommandMethod("jointwolines")>
Public Shared Sub jointwolines()
Dim line1as polyline
Dim line2 As Line
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Dim ed As Editor = doc.Editor
Dim bt As BlockTable
Dim btr As BlockTableRecord
Using tr As Transaction = db.TransactionManager.StartTransaction()
line1 = New Polyline()
line1.AddVertexAt(0, New Point2d(0, 0), 0, 0, 0)
line1.AddVertexAt(0, New Point2d(100, 0), 0, 0, 0)
line1.Elevation = 0
line2 = New Line(new point3d(0,0,0), new point3d(0,0,100))
bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
btr = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
btr.AppendEntity(line1)
line1.JoinEntity(line2)
tr.AddNewlyCreatedDBObject(line1, True)
tr.Commit()
End Using
End Sub
End Class
End Namespace
Can someone help me? This is getting frustrating :(
JoinEntity does not create a new entity, it modifies the entity on which it is called. It's why you cannot get a return value.
Two lines can be joined if there are collinear, which is not your case. You need to call this method on a polyline, like you do in your second code snippet.
From the Autodesk doc :
Polyline.JoinEntity(ies) requires the given entities to be other,
unclosed Polyline or Polyline2d, Line, and/or Arc entities, which
share common start or end points.
But Polyline is a 2D entity, lying in the XY plane of the WCS by default, and you try to add a line with an end point which is 100 units above this XY plane. You need to use a Polyline3d:
<CommandMethod("JOINTWOLINES")>
Public Shared Sub JoinTwoLines()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim db As Database = doc.Database
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable
bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
Dim btr As BlockTableRecord
btr = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim pl as Polyline3d
pl = New Polyline3d(Poly3dType.SimplePoly, _
new Point3dCollection(), _
False)
btr.AppendEntity(pl)
tr.AddNewlyCreatedDBObject(pl, True)
Dim line1 As Line
line1 = New Line(New Point3d(0, 0, 0), New Point3d(100, 0, 0))
btr.AppendEntity(line1)
tr.AddNewlyCreatedDBObject(line1, True)
Dim line2 As Line
line2 = New Line(new Point3d(0, 0, 0), new Point3d(0, 0, 100))
btr.AppendEntity(line2)
tr.AddNewlyCreatedDBObject(line2, True)
pl.JoinEntities(new Entity(){line1, line2})
tr.Commit()
End Using
End Sub
One more thing: do not put your variable at the top of your sub. You're not writing Pascal but C#. Declare your variables where there are used.