|
Well, you're going to have to start looking for a PDF library that you can access through COM support.
|
|
|
|
|
|
|
Story:
I have a ListBox where I add custom objects, when the user clicks these custom objects in that ListBox some WPF Controls are generated in a stackpanel, these WPF Controls are properties of the custom objects. Below you may see the class.
<pre> Public Class VariableClass
Public Property Content As String
Public Property myNameLabel As New Label
Public Property myNameTextBox As New ComboBox
Public Property myTypeLabel As New Label
Public Property myTypeTextBox As New ComboBox
Public Overrides Function ToString() As String
Return Content.ToString()
End Function
End Class
I want to know what PropertyName the control the user types into has.
<pre> Private Sub ValuePanel_PreviewKeyDown(sender As Object, e As KeyEventArgs) Handles ValuePanel.PreviewKeyDown
Dim myElement As ComboBox = e.OriginalSource.TemplatedParent
Dim myVar = GetValue(myElement).GetType().GetProperty("PropertyName")
End Sub
However myElement is not a DependencyObject and cannot be cast to one, I don't know how else to get the PropertyName or the VariableName.
|
|
|
|
|
|
Hello and thanks in advance.
I have created a form1 which is asking for a password to get to form2. After you put in your code and click on the submit button it looks at an access database table for that code, if code exists it then returns by closing form1 and shows form2.
In the access database there are 2 fields, username and password. how can I show on form2 in a text box the username which was approved to sign on in a textbox?
|
|
|
|
|
|
Thank you for the quick reply. I am trying to understand this, sorry. So I have in my button the following. So when I get to form2 (Form2.Show) how would I pull out the username from the MDB file.
Dim connab As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\test\1274-Users.accdb")
REM Dim cmd As New OleDbCommand("select* from login1 where user1=@userl and pass1=@pass1", connab)
Dim cmd As New OleDbCommand("select* from login1 where pass1=@pass1", connab)
REM cmd.Parameters.Add("@userl", OleDbType.VarChar).Value = TextBox1.Text
cmd.Parameters.Add("@pass1", OleDbType.VarChar).Value = TextBox2.Text
Dim adapter1 As New OleDbDataAdapter(cmd)
Dim table As New DataTable
adapter1.Fill(table)
If table.Rows.Count <= 0 Then
MsgBox("ERROR: NO PASSWORD OR INCORRECT PASSWORD")
TextBox2.Text = ""
Else
TextBox2.Text = ""
Form2.Show()
Me.Visible = False
|
|
|
|
|
The data from the database record should be in the DataTable. Use your debugger to examine the results after the Fill operation.
|
|
|
|
|
Jeremy Haley 2022 wrote: In the access database there are 2 fields, username and password.
Sounds like you're storing the passwords insecurely.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
NB: If you trust everyone who can access the database file not to look at the table to see the passwords, then why bother with a password in the first place? Just let them pick from a drop-down list of usernames.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i have code to combine two datatable.
the code works fine in my test program, but when i copy it to my production program it gives me this error?
"{"Specified cast is not valid."}"
here is the code and the error is in the for each loop.
<pre> Private Sub CompareDataTables(ByVal dt1 As DataTable, ByVal dt2 As DataTable)
Try
Dim Results =
(
From table1 In dt1
Join table2 In dt2 On table1.Field(Of Integer)(0) Equals table2.Field(Of Integer)(0)
Where table1.Field(Of String)(1) <> table2.Field(Of String)(1) OrElse
table1.Field(Of String)(2) <> table2.Field(Of String)(2)
Select table2)
For Each row As DataRow In Results
DataGridView3.Rows.Add(row.ItemArray)
Next
dtNew = Results
Catch ex As Exception
ErrorHandler.ErrHandler("CompareDataTables- Import_Customer")
End Try
End Sub
i have search the net for two days and can't fine the solution. can some one help me please!!!
|
|
|
|
|
Either the first column of both tables is not an Integer , or the second or third columns of both tables is not a String .
We have no access to your data, so we can't tell you where the problem is. You need to debug your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you i think i know what i did wrong.
need to check a few things to make Sher.
|
|
|
|
|
Hi my guy.
Whichever language you are using in Visual Studio, this will work as long as the two datatables have the same schema/structure.
//=====================See Code Below =================================
DataTable DT1 = TicketDatatable();
DataTable DT2 = TicketDatatable();
DT2.Merge(DT1); //This combines the two datatables provided they have the same attributes (Schema)
//======================================Code Above =======================
DT2 is now the combined datatables, using the merge method of datatable.
|
|
|
|
|
I have written a Check Book application and the code that calculates the 4th Tue of the Month is failing when we enter a new Year. I have added an additional Function that works but the code seems less tan elegant. I have tested a few changes with no results.
Without posting a lot of unnecessary code here is the process and the relevant code that works now.
I am storing he 4th Tue of the month in a SQLite DB and when the user writes a check I am testing if the date today is greater than the stored DB date. If this test is true than I update the stored date to the 4th Tue for next Month. I would like to know if there is a better way to design this process ?
Perhaps only using one Function.
Public Sub GetDateInfo()
Using conn As New SQLiteConnection($"Data Source = '{gv_dbName}';Version=3;")
conn.Open()
Using cmd As SQLiteCommand = New SQLiteCommand($"SELECT * FROM DateInfoTable WHERE DID = '1'", conn)
Using rdr As SQLite.SQLiteDataReader = cmd.ExecuteReader
While rdr.Read()
varSearchDate = CDate(rdr("diTESTdate"))
End While
End Using
End Using
End Using
End Sub
This is the code that executes when user writes a check
Public Sub testDates()
GetDateInfo()
'Other Option
'ElseIf dateToday > varSearchDate And CInt(varSearchDate.ToString.Substring(0, 2)) = 12 Then
'============================================================================================
Dim dateToday = Date.Today
Dim mo As String
mo = dateToday.ToString("MM")
'mo = varSearchDate.ToString("MM")
'line above for testing for NOV
If dateToday > varSearchDate And CInt(mo) <> 12 Then
varFTue = CDate(FourthTueOfNextMonth(Date.Today).ToString("yyyy-M-d"))
WriteNewFourthTue()
gvTxType = "SS Deposit"
ElseIf dateToday > varSearchDate And CInt(mo) = 12 Then
varFTue = CDate(FourthTueOfNewYear(Date.Today).ToString("yyyy-M-d"))
MsgBox("varFTue " & varFTue)
WriteNewFourthTue()
gvTxType = "SS Deposit"
End If
End Sub
These are the two Functions that are in a Data Module
Function FourthTueOfNextMonth(dt As Date) As Date
Dim currDate = New Date(dt.Year, dt.Month, 1)
Dim nTuesday As Integer
While nTuesday < 4
If currDate.DayOfWeek = DayOfWeek.Tuesday Then
nTuesday += 1
End If
currDate = currDate.AddDays(1)
End While
Return New Date(dt.Year, dt.Month, currDate.Day - 1)
End Function
Function FourthTueOfNewYear(dt As Date) As Date
Dim currDate = New Date(dt.Year + 1, dt.Month - 11, 1)
Dim nTuesday As Integer
While nTuesday < 4
If currDate.DayOfWeek = DayOfWeek.Tuesday Then
nTuesday += 1
End If
currDate = currDate.AddDays(1)
End While
Return New Date(dt.Year + 1, dt.Month - 11, currDate.Day - 1)
End Function
|
|
|
|
|
If the "day" of the "Tuesday date" is >= 22 and <= 28, it's the 4th Tuesday.
How to: Extract the Day of the Week from a Specific Date | Microsoft Docs
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Gerry I like the idea. Guess I was being exact with the date for each month in case the user does not write a check between the date range. With the exact date from the database if the user writes a check after the 28 of last month the the event will trigger in the next month. I was trying to avoid having two Function and find a better way to write a test that would capture the 4th Tue when the YEAR changes.
I appreciate the link to working with Date's Date's are like a moving target that always needs to go back to the starting point January
|
|
|
|
|
Use date add with 3 weeks and add weekday difference with it you will get the fourth Tuesday
Every thing is possible
|
|
|
|
|
After consideration I have rewritten the Functions with just this one.
Still testing but I believe it will correct the issue when the year changes.
Function FourthTueOfNextMonth(dt As Date) As Date
' Start with the First Day of the Month, from the date passed in.
' Add one Month to that to get the first Day of the NEXT month.
Dim currDate As Date = (New Date(dt.Year, dt.Month, 1)).AddMonths(1)
'Dim currDate As Date = (New Date(2022, 1, 1)).AddMonths(1)
'LINE ABOVE for testing set it to todays DATE
' Find the First Tuesday of the Month
While currDate.DayOfWeek <> DayOfWeek.Tuesday
currDate = currDate.AddDays(1)
End While
' Add three more Weeks to jump to Fourth Tuesday
Return currDate.AddDays(21)
End Function
|
|
|
|
|
hi i'm VB.net Newbi in south korea. it's difficult to me ;( .
I am creating a UDP chat by looking at the data. The server cannot send a message to the client. I need help. how do i code it??
-Send-
Shrink ▲ Copy Code
Imports System.IO
Imports System.Net.Sockets.Socket
Imports System
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Dim GLOIP As IPAddress
Dim GLOINTPORT As Integer
Dim bytCommand As Byte() = New Byte() {}
Dim udpClient As New UdpClient
Public receivingUdpClient As UdpClient
Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
Public ThreadReceive As System.Threading.Thread
Dim SocketNO As Integer
Private Sub cmdSend_Click(sender As Object, e As EventArgs) Handles cmdSend.Click
Dim pRet As Integer
Try
'Get IP address
GLOIP = IPAddress.Parse(txtIP.Text)
'Get Port
GLOINTPORT = txtPort.Text
'Connect
udpClient.Connect(GLOIP, GLOINTPORT)
'Get Message from text box, encode it
bytCommand = Encoding.Unicode.GetBytes(txtMessage.Text)
'Send
pRet = udpClient.Send(bytCommand, bytCommand.Length)
txtInfo.Text = txtInfo.Text + vbCrLf + "The messege send is """
txtInfo.Text = txtInfo.Text & Encoding.Unicode.GetString(bytCommand) & """"
Catch ex As Exception
txtInfo.Text = txtInfo.Text & vbCrLf & ex.Message
End Try
End Sub
'txtMessage창에서 Enter키를 누르면 메시지를 전송하는 기능
Private Sub txtMessage_KeyDown(sender As Object, e As KeyEventArgs) Handles txtMessage.KeyDown
If e.KeyCode = Keys.Enter Then
cmdSend.PerformClick()
txtMessage.Clear()
End If
End Sub
End Class
--Receive--
Shrink ▲ Copy Code
Imports System.IO
Imports System
Imports System.Text
Imports System.Net
Imports System.Net.Sockets
Imports Microsoft.VisualBasic
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Public receivingUdpClient As UdpClient
Public RemoteIpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, 0)
Public ThreadReceive As System.Threading.Thread
Dim SocketNO As Integer
Public Delegate Sub SettheText(ByVal TextObject As TextBox, ByVal text As String)
Public Sub setText(ByVal textobject As TextBox, ByVal text As String)
Try
If textobject.InvokeRequired Then
Dim d As New SettheText(AddressOf setText)
textobject.Invoke(d, New Object() {textobject, text})
Else
textobject.Text = text
End If
Catch ex As Exception
End Try
End Sub
Public Sub ReceiveMessages()
Try
Dim receiveBytes As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
'txtIP.Text = RemoteIpEndPoint.Address.ToString
setText(txtIP, RemoteIpEndPoint.Address.ToString)
txtInformation.Text = txtInformation.Text & vbCrLf & "A message is received and being processed"
txtInformation.Text = txtInformation.Text + vbCrLf + "The message received is """
txtInformation.Text = txtInformation.Text & Encoding.Unicode.GetString(receiveBytes) + """"
txtInformation.Text = txtInformation.Text & vbCrLf
NewInitialize()
Catch e As Exception
End Try
End Sub
Public Sub NewInitialize()
ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages)
ThreadReceive.Start()
End Sub
' Clear 버튼을 누르면 TextBox 초기화
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click
txtInformation.Text = "Information"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Try
SocketNO = txtSocket.Text
receivingUdpClient = New System.Net.Sockets.UdpClient(SocketNO)
ThreadReceive = New System.Threading.Thread(AddressOf ReceiveMessages)
ThreadReceive.Start()
txtInformation.Text = "Connect Complete"
txtInformation.Enabled = True
btnStop.Enabled = True
btnStart.Enabled = False
txtSocket.ReadOnly = True
Catch x As Exception
txtInformation.Text = txtInformation.Text & vbCrLf & x.Message
End Try
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Try
receivingUdpClient.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Try
ThreadReceive.Abort()
receivingUdpClient.Close()
txtInformation.Text = "INFORMATION"
txtInformation.Enabled = False
btnStop.Enabled = False
btnStart.Enabled = True
txtIP.Text = ""
txtSocket.ReadOnly = False
Catch ex As Exception
txtInformation.Text = txtInformation.Text & vbCrLf & ex.Message
End Try
End Sub
End Class
|
|
|
|
|
You already posted this question in the .NET forum. Please do not cross post.
|
|
|
|
|
Below is sample code, with sample values. Uses a Form with a Chart object ("Chart1") X-Axis is the date and there are 2 Y values. If the mouse passes over the line(s) I want to display which series, the value and the date, several show as "Unknown" because the value passed to the Function is slightly off the actual value. I'd rather NOT use the function I created anyway, I would rather get it direct from the HitTest results or some other method if that is possible.
<pre> Option Strict On
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Private TheDate As New List(Of Date)
Private Series1 As New List(Of Integer)
Private Series2 As New List(Of Integer)
Private Function DateFromOtherData(SName As String, Data As Integer) As String
Dim DataIndex As Integer = -1
If SName = "Series1" Then
DataIndex = Series1.IndexOf(Data)
Else
DataIndex = Series2.IndexOf(Data)
End If
If DataIndex > -1 Then
Return TheDate(DataIndex).ToShortDateString
Else
Return "Unknown"
End If
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Temp As New List(Of String)
Temp.Add("2020-03-07")
Series1.Add(428)
Series2.Add(19)
Temp.Add("2020-03-31")
Series1.Add(188461)
Series2.Add(4304)
Temp.Add("2020-04-24")
Series1.Add(909853)
Series2.Add(51360)
Temp.Add("2020-05-18")
Series1.Add(1515593)
Series2.Add(90414)
Temp.Add("2020-06-11")
Series1.Add(2036500)
Series2.Add(113980)
Temp.Add("2020-07-05")
Series1.Add(2910782)
Series2.Add(129941)
Temp.Add("2020-07-29")
Series1.Add(4433633)
Series2.Add(151172)
Temp.Add("2020-09-15")
Series1.Add(6614318)
Series2.Add(195689)
Temp.Add("2020-10-09")
Series1.Add(7719211)
Series2.Add(213595)
Temp.Add("2020-11-02")
Series1.Add(9377208)
Series2.Add(231480)
Temp.Add("2020-11-26")
Series1.Add(12954294)
Series2.Add(263339)
Temp.Add("2020-12-20")
Series1.Add(17880478)
Series2.Add(317810)
Temp.Add("2021-01-13")
Series1.Add(23135194)
Series2.Add(384824)
Temp.Add("2021-02-06")
Series1.Add(26958807)
Series2.Add(462052)
Temp.Add("2021-03-02")
Series1.Add(28738501)
Series2.Add(515710)
Temp.Add("2021-03-26")
Series1.Add(30172762)
Series2.Add(547621)
Temp.Add("2021-04-19")
Series1.Add(31754642)
Series2.Add(567314)
Temp.Add("2021-05-13")
Series1.Add(32868084)
Series2.Add(583991)
Temp.Add("2021-06-06")
Series1.Add(33329413)
Series2.Add(596803)
Temp.Add("2021-06-30")
Series1.Add(33639764)
Series2.Add(604446)
Temp.Add("2021-07-24")
Series1.Add(34469200)
Series2.Add(610400)
Temp.Add("2021-08-17")
Series1.Add(37133674)
Series2.Add(623237)
Temp.Add("2021-09-10")
Series1.Add(40914456)
Series2.Add(658865)
Temp.Add("2021-10-04")
Series1.Add(43826566)
Series2.Add(703362)
Temp.Add("2021-10-28")
Series1.Add(45797078)
Series2.Add(743050)
Temp.Add("2021-11-21")
Series1.Add(47692614)
Series2.Add(771871)
Temp.Add("2021-12-15")
Series1.Add(50346987)
Series2.Add(801037)
For Each S As String In Temp
TheDate.Add(CDate(S))
Next
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Chart1.Series.Clear()
Chart1.Series.Add("Series1")
Chart1.Series.Add("Series2")
Chart1.Series(0).YAxisType = AxisType.Primary
Chart1.Series(1).YAxisType = AxisType.Secondary
Chart1.ChartAreas(0).AxisY.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisY2.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX2.MajorGrid.LineWidth = 0
Chart1.ChartAreas(0).AxisX.Interval = 21
Chart1.ChartAreas(0).AxisX2.Interval = 21
Chart1.ChartAreas(0).AxisY.LabelStyle.ForeColor = Color.Blue
Chart1.ChartAreas(0).AxisY.LabelStyle.Font = New Font("Arial", 12, FontStyle.Bold)
Chart1.ChartAreas(0).AxisY2.LabelStyle.ForeColor = Color.Red
Chart1.ChartAreas(0).AxisY2.LabelStyle.Font = New Font("Arial", 12, FontStyle.Bold)
Chart1.Series(0).Name = "Series1"
Chart1.Series(0).Points.DataBindXY(TheDate.ToArray, Series1.ToArray)
Chart1.Titles.Clear()
Chart1.Series(1).Name = "Series2"
Chart1.Series(1).Points.DataBindXY(TheDate.ToArray, Series2.ToArray)
Chart1.Series(0).ChartType = SeriesChartType.Line
Chart1.Series(0).BorderWidth = 5
Chart1.Series(1).ChartType = SeriesChartType.Line
Chart1.Series(1).BorderWidth = 2
Chart1.Series(0).Color = Color.Blue
Chart1.Series(1).Color = Color.Red
Chart1.Visible = True
End Sub
Private Sub Chart1_MouseMove(sender As Object, e As MouseEventArgs) Handles Chart1.MouseMove
Dim result As HitTestResult = Chart1.HitTest(e.X, e.Y)
Dim Ndx As Integer
Dim thisPt As New PointF
Dim ta As New CalloutAnnotation
Dim TheText As String = ""
Chart1.Annotations.Clear()
If result.ChartElementType = ChartElementType.DataPoint Then
Dim SName As String = result.Series.Name
If SName = "Series1" Then
Ndx = 0
Else
Ndx = 1
End If
thisPt = New PointF(CSng(Chart1.Series(Ndx).Points(result.PointIndex).XValue),
CSng(Chart1.Series(Ndx).Points(result.PointIndex).YValues(0)))
ta.CalloutStyle = CalloutStyle.Rectangle
ta.AnchorDataPoint = Chart1.Series(Ndx).Points(result.PointIndex)
ta.Alignment = ContentAlignment.MiddleLeft
ta.TextStyle = TextStyle.Default
ta.Font = New Font("Arial", 10, FontStyle.Bold)
TheText &= SName & ": " & vbLf &
"Value: " & thisPt.Y.ToString("F0") & vbLf &
"Date: " & DateFromOtherData(SName, CInt(thisPt.Y))
ta.Text = TheText
Chart1.Annotations.Add(ta)
Chart1.Invalidate()
Me.Text = "ThisPt.X = " & thisPt.X.ToString
End If
End Sub
End Class
|
|
|
|
|
Hello every one
simple code as follow
Dim MyInt As Int16 = 12
Dim result As Byte() =BitConverter.GetBytes(MyInt)
Console.WriteLine(BitConverter.ToString(result).Length)
Console.WriteLine(BitConverter.ToString(result))
this will return as follow
5
0C-00
Just I want to get
2
0C
(length 2 only) and return (0C) only
I try to change "MyInt" Declare type from Int16 to all available types but did not work,
also i dont need to subtract result as string, i need result as byte() type
any advise please ?
I am using VS2019
thanks in advance
|
|
|
|
|
It really depends on what you are trying to do, and why you need to convert a number to a hexadecimal string. You could just use the 'X' format string to print the value, which would give you the correct answer.
|
|
|
|
|
I solved like follows:-
Dim MyInt As Int16 = 12
Dim result (0) As Byte
result (0) = Convert.ToByte(MyInt)
Console.WriteLine(BitConverter.ToString(result))
thanks everyone again
|
|
|
|