|
Hi Robert.
The indicator is a XK3101(N). I have found this code to guide me in the right direction but can't get it to work the way I want it.
Public Class Form1
Dim myport As Array
Dim strWeight As String
Public Delegate Sub myDel(ByVal txtBox As TextBox)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
myport = SerialPort.GetPortNames
AddHandler SerialPort1.DataReceived, AddressOf SerialPort1_DataReceived
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
txtBox.Invoke(New myDel(AddressOf UpdateTextBox), New Object() {txtBox})
End Sub
Public Sub UpdateTextBox(ByVal UpDateTextBox As TextBox)
Dim bytes As Integer = SerialPort1.BytesToRead
Dim Buffer(bytes) As Byte
SerialPort1.Read(Buffer, 0, bytes)
strWeight = System.Text.Encoding.Default.GetString(Buffer)
txtBox.AppendText(strWeight)
GetTareandWeight(strWeight)
End Sub
Private Sub GetTareandWeight(ByVal weight As String)
Dim strWeights() As String
Dim newWeight As String = Replace(weight, " ", " ")
strWeights = Split(weight, ",")
txtBox2.Text &= newWeight & vbCrLf
txtBox2.Text &= strWeights.Length.ToString & vbCrLf
txtBox2.Text &= "Tare: " & strWeights(1).ToString
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
SerialPort1.PortName = "COM5"
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 8
SerialPort1.Parity = Parity.None
SerialPort1.StopBits = StopBits.One
SerialPort1.Handshake = Handshake.None
SerialPort1.Open()
SerialPort1.Write(vbCr)
End Sub
If I can get it to work, I will have to incorporate it into my main program. I get the weight readings but gives an error when I press the Tare button on the indicator. Hope you can help. I got the manual but can't put a picture here. Hope you can help.
|
|
|
|
|
Gus:
Some comments on that code:
(a) It looks like it is working. You have defined an event handler for receiving data from the serial port. You "get the weight readings", so we know that event handler works.
(b) The "GetTareAndWeight" code tells me that the scale sends both Weight and Tare in the same string.
Something like "10.3, 2.0".
This must be working when you "get weight readings" - otherwise it would crash with an array error.
(c) After receiving a weight txtBox2 (a multiline textbox) should look something like this:
"10.3, 2.0"
"2"
"Tare: 2.0"
(d) If your code received a string containing Tare only, ie, "2.0", then it will crash in "GetTareAndWeight" on the line 'txtBox2.Text &= "Tare: " & strWeights(1).ToString'
Question for you Gus:
"gives an error when I press the Tare button on the indicator". What is the error?
|
|
|
|
|
Hi Robert.
The error occurs at the line: txtBox2.Text &= "Tare: " & strWeight(1).ToString with error message; IndexOutOfRangeException was unhandled by user code. Index was outside the bounds of the array. How would I go about to fix the code?
|
|
|
|
|
I have changed the code a bit but now there is no output in txtBox2 but the the error message when I open the port.
|
|
|
|
|
Gus:
I think you can see that you have a simple array error. The compiler seems to have been quite clear about that.
I suggest that you resolve that array error.
The code will then work fine.
I cannot help you any further with this issue Gus.
|
|
|
|
|
Hello,
I am automating the outlook using vb.net using
Microsoft.Office.Interop.Outlook
I want to add a unsubscribe link to the mail header.
I have done mail automation using asp.net which has option to add unsubscribe link in header
Dim Mail As New System.Net.Mail.MailMessage()
.Headers.Add("List-Unsubscribe", oModPass.OurunsubscribeMailId)
But this is not working in outlook.
Is there any alternatives for '.header.add' in 'Microsoft.Office.Interop.Outlook'
In simple I want to add a link as shown in this link
Google Images[^]
Please help.
|
|
|
|
|
According to this StackOverflow thread[^], something like this should work:
Public Sub AddCustomHeader(ByVal mail As MailItem, ByVal headerName As String, ByVal headerValue As String)
Dim prop As String = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/" + headerName
mail.PropertyAccessor.SetProperty(prop, headerValue)
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, When users click on 'unsubscribe' what will happen ? To whom the unsubscribe notification goes ?
|
|
|
|
|
It goes to whatever address or URL you've specified in the header:
List-Unsubscribe: <mailto:unsubscribe-espc-tech-12345N@domain.com>, <http:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
It worked for me.
Thank you so much.. You made my work easier.
|
|
|
|
|
Hello everybody!
I M facing a brain busting issue for the last 3 days and desperately seeking help.
As a most trivial example, I M using the NorhtwindDataSet and has dropped only 3 Fields - ProductID, ProductName, and the UnitPrice from the Products table (in details view) on to the form. The Navigator displays all the records without any problem.
When I modify any value from any of the 3 fields, it accepts obediently. But, when I run the form again, No modification is there - the same old values are making faces at me. The auto-generated code behind is as below:
Private Sub ProductsBindingNavigatorSaveItem_Click_3(sender As Object, e As EventArgs) _
Handles ProductsBindingNavigatorSaveItem.Click
Me.Validate()
Me.ProductsBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)
End Sub
I tried my own Save button, and copied the above code in its Procedure, with no luck.
I have tried this with plenty of databases, including my own database tables as well, with exactly the same problem.
Please help me, taking me as a novice.
Regards
|
|
|
|
|
Are you using the Access database version of Northwind, and all your other databases for that matter?
|
|
|
|
|
Thanks for a response, at least. I am using MS SQL Server 2015 Express edition and working in VisualBasic.NET.
Not a single project is functioning to Insert or Update any record, whether in DataGridView or in detailed format.
I M suffering and seek help desperately.
Regards
|
|
|
|
|
I hate to ask this question, but this is my first time using SQLite from the nuGet package.
System.Data.SQLite (x86/x64) and it installed EF6, SQLite Core, SQLite EF6, SQLite LINQ
I wrote a DLL for the DAL, and a DLL for the SQL Linq Call. Then I wrote a function to just get a count from the table to trigger creating the database. I tested it using SQL Server and it worked fine. Created the database and tables, then seeded the tables.
So then I switch over to SQLite. Adjusted the App.Config file - see below
This App.Config is from the main program project. I have App.Configs in the DLL's as well, not sure If I need them or not.
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http:
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=WSACORE2-VM1\SQLServer; Initial Catalog=AccountMateExtras2016; User ID=mvc.connector; Password=9Moret9z" providerName="System.Data.SqlClient" />
<add name="SQLiteConnection" connectionString="data source=d:\Amp\SIS\AMExtras.sqlite" providerName="System.Data.SqlLite.EF6"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<!--<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.101.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />-->
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
</configuration>
Then I ran this in the EF DLL and got that error in the subject line.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Data.SQLite
Imports System.Data.SQLite.EF6
Imports System.Data.SQLite.Linq
Imports AccountMate_DAL.DAL
Imports AccountMate_DAL.Models
Imports AccountMate_EF6
Public Class ef_seed
Public Shared Function Create_Database() As Integer
Dim pValue As Integer = 0
Using context As New ameContext()
pValue = context.SMTP_SEND.Count()
End Using
Return pValue
End Function
End Class
I have no clue on this, and I did search for 2 hours on the subject. Any help appreciated!
Maybe the Linq I use above is not valid with SQLite.
|
|
|
|
|
Well first off, SQLite doesn't support automatic database creation, you have to manually create the database. So I added that add-in to my Firefox and created the database.
I'm wondering if this is worth the time. This program uses old Dbase IV or Foxpro database files, and I wanted to use something faster and more modern for a new program feature that stores all the emails sent in the database, so if one fails it can be resent.
This kicked my butt, but I don't get an error anymore. I couldn't figure out the App.Config part the way the bulk of examples showed, but I did figure out how to point the database to a network drive via code in the Application, and pass it to EF6 DAL.
So in case your looking for an example of how to point SQLite to a network drive without hard coding the path, this is it, well I think it is, until something better comes along.
I apologize in advance for this being in VB. All the examples where in C#
My project has 3 modules, because it's getting too large in size.
Main Project EXE
Data Access Layer DLL
Entity DLL
I went back and stripped out the SQLite from the main project and Entity DLL and just installed it in the DAL DLL. Then just made references for SQLite back to the DAL. Then stripped out the SQLite and EF stuff in the App.Configs of DLL's
So in the DBContext class in my DAL, I added the conn string to use in New()
Public Class ameContext
Inherits DbContext
<ObsoleteAttribute("The default connection factory should be set in the config file or using the DbConfiguration class. (See <a href="http:
Public Shared Property DefaultConnectionFactory As IDbConnectionFactory
Public Sub New(ByVal conString As String) '<< I added the conn string to use
MyBase.New(conString)
'SQLite doesn't support auto database creation
Entity.Database.SetInitializer(Of ameContext)(Nothing)
End Sub
End NameSpace
Then I added a SQLiteConfiguration File to my DAL Class, which gets called from the DBContext above.
Imports System.Data.SQLite
Imports System.Data.SQLite.EF6
Imports System.Linq
Imports System.Text
Imports System.Data.Entity.Core.Common
Imports AccountMate_DAL
Namespace System.Data.SQLite.Entity
Public Class SQLiteConfiguration
Inherits DbConfiguration
Public Sub New()
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance)
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance)
SetProviderServices("System.Data.SQLite", CType(SQLiteProviderFactory.Instance.GetService(GetType(DbProviderServices)), DbProviderServices))
End Sub
End Class
End NameSpace
And added a SQLiteConnectionFactory Class to my DAL Class, which gets called from the DBConfiguration above.
Imports System.Data.Common
Imports System.Data.Entity.Infrastructure
Imports System.Data.SQLite
Public Class SQLiteConnectionFactory
Implements IDbConnectionFactory
Public Function CreateConnection(ByVal connectionString As String) As DbConnection Implements IDbConnectionFactory.CreateConnection
Return New SQLiteConnection(connectionString)
End Function
End Class
The App.Config for the VB App, All I did was declare the DefaultConnectionfactory, which is the name of my DAL.
<entityFramework>
<defaultConnectionFactory type="AccountMate_DAL.SQLiteConnectionFactory, AccountMate_DAL" />
</entityFramework>
Finally in the program, when initializing the context, I added the connstring, connstring is that string that was in the App.Config of the vb.net app shown below, higlighted in blue. Get the string and then delete it.
<add name="SQLiteConnection" connectionString="data source=d:\Amp\SIS\AMExtras.sqlite" providerName="System.Data.SqlLite.EF6" />
Dim context = new ameContext(connstring)
Hope that helps, like I said it was pretty confusing to figure out. And the examples were so basic and assumed it works.
[edit] 05//11/2013
Had no modify the DBContext to stop Database Creation
But I wrote a record to it, and updated the record 5 times now.
Be cool if I can figure out a way to detect the whether its using SQL Server or SQLite in the DBContext.
modified 13-May-16 11:08am.
|
|
|
|
|
How we can get last 12 months using current month with we select departmentTitle and ReadingDate(Apr 2016) from table
and also add sum of meterreading using departmentTitle and ReadingDate.
My Query is:
SELECT CONVERT(varchar(3), ReadingDate, 100) AS XText,SUM(MeterReading) AS DataText,MonthlyTarget AS YText FROM tblReadings WHERE ReadingDate =apr 2016 AND DepartmentTitle=ADS GROUP BY CONVERT(varchar(3), ReadingDate, 100), MONTH(ReadingDate),MonthlyTarget ORDER BY MONTH(ReadingDate)
Required output is:
[Month from date] [Sum of meterreading]
[Apr] [12000]
[Mar] [16000]
[Feb] [20000]
[Jan] [18000]
|
|
|
|
|
Assuming you are storing your date as a date or datetime you use
where Readingdate >= dateadd(year,-1,ReadingDate)
Typed from memory so you need to check the syntax
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanx...
But I want selected month and previous 12 months..
and my where condition is
Where ReadingDate <= 'Nov 2016' AND DepartmentTitle='ABC'
Required OUTPUT:
Nov 2016
Oct 2016
Sept 2016
Aug 2016
Jul 2016
Jun 2016
May 2016
Apr 2016
Mar 2016
Feb 2016
Jan 2016
Dec 2015
|
|
|
|
|
Do some research into the datetime object in sql server, by using that you can get exactly what you want.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
To only include the last 12 months of data use this in your WHERE clause
WHERE ReadingDate BETWEEN DATEADD(YY, -1, GETDATE()) AND GETDATE()
As aside, instead of using
CONVERT(varchar(3), ReadingDate, 100) AS XText try (SQL 2008 and later)
DATENAME(mm, ReadingDate) AS XText
|
|
|
|
|
CHill60 wrote: SQL 2008 and later
In this case, MSDN is wrong, or at least misleading. The DATENAME function was available at least as far back as SQL 2000:
DATENAME : SQL Server 2000 Books Online[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for info.
I always check when a function I'm suggesting was introduced - you're right, MSDN is misleading on this one. I'll do more robust checking next time
|
|
|
|
|
You, like me, assumed SQL server, if the OP does not even deign to inform us as to the database he is using then I don't think the onus is on you to be specific as to the when the function became available!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks ....
We want only required Month and Year from date instead of date in where condition.
This is my Query:
SELECT TOP 12 CONVERT(varchar(3), ReadingDate, 100)+CONVERT(varchar(4), ReadingDate,102) AS XText,SUM(MeterReading) AS DataText,(MonthlyTarget) AS YText
FROM tblReadings
WHERE DepartmentTitle='abc'AND ReadingDate BETWEEN DATEADD(mm,-12,ReadingDate) AND '31 may 2016'
GROUP BY CONVERT(varchar(3), ReadingDate, 100)+CONVERT(varchar(4), ReadingDate,102), MONTH(ReadingDate),YEAR(ReadingDate),MonthlyTarget
ORDER BY YEAR(ReadingDate) DESC, MONTH(ReadingDate) DESC
I Want this output -
'may 2016'
|
|
|
|
|
Is there any way to find out the status of opening a recordset in VBA? I thought it was the SQL that was slow but it is instantaneous. It is the open of the recordset that is slow and I would like to be able to monitor its progress.
ORIGINAL QUESTION SHOWN BELOW FOR HISTORY
I'm running an SQL query in VBA in Excel to return a record set. Is there any way to know the progress of the query so I can show it on the status bar (or elsewhere)? If there are millions of records that would be better than "please be patient" or "processing 15,000,000 records".
modified 5-May-16 19:04pm.
|
|
|
|
|